项目原始demo,不改动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

пре 4 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # eslint-plugin-promise
  2. Enforce best practices for JavaScript promises.
  3. [![travis-ci](https://travis-ci.org/xjamundx/eslint-plugin-promise.svg)](https://travis-ci.org/xjamundx/eslint-plugin-promise)
  4. [![npm version](https://badge.fury.io/js/eslint-plugin-promise.svg)](https://www.npmjs.com/package/eslint-plugin-promise)
  5. [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
  6. [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
  7. <!-- START doctoc generated TOC please keep comment here to allow auto update -->
  8. <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
  9. * [Installation](#installation)
  10. * [Usage](#usage)
  11. * [Rules](#rules)
  12. * [Maintainers](#maintainers)
  13. * [License](#license)
  14. <!-- END doctoc generated TOC please keep comment here to allow auto update -->
  15. ## Installation
  16. You'll first need to install [ESLint](http://eslint.org):
  17. ```
  18. $ npm install eslint --save-dev
  19. ```
  20. Next, install `eslint-plugin-promise`:
  21. ```
  22. $ npm install eslint-plugin-promise --save-dev
  23. ```
  24. **Note:** If you installed ESLint globally (using the `-g` flag) then you must
  25. also install `eslint-plugin-promise` globally.
  26. ## Usage
  27. Add `promise` to the plugins section of your `.eslintrc` configuration file. You
  28. can omit the `eslint-plugin-` prefix:
  29. ```json
  30. {
  31. "plugins": ["promise"]
  32. }
  33. ```
  34. Then configure the rules you want to use under the rules section.
  35. ```json
  36. {
  37. "rules": {
  38. "promise/always-return": "error",
  39. "promise/no-return-wrap": "error",
  40. "promise/param-names": "error",
  41. "promise/catch-or-return": "error",
  42. "promise/no-native": "off",
  43. "promise/no-nesting": "warn",
  44. "promise/no-promise-in-callback": "warn",
  45. "promise/no-callback-in-promise": "warn",
  46. "promise/avoid-new": "warn",
  47. "promise/no-new-statics": "error",
  48. "promise/no-return-in-finally": "warn",
  49. "promise/valid-params": "warn"
  50. }
  51. }
  52. ```
  53. or start with the recommended rule set
  54. ```json
  55. {
  56. "extends": ["plugin:promise/recommended"]
  57. }
  58. ```
  59. ## Rules
  60. | rule | description | recommended | fixable |
  61. | -------------------------------------------------------- | -------------------------------------------------------------------------------- | ----------- | -------- |
  62. | [`catch-or-return`][catch-or-return] | Enforces the use of `catch()` on un-returned promises. | :bangbang: | |
  63. | [`no-return-wrap`][no-return-wrap] | Avoid wrapping values in `Promise.resolve` or `Promise.reject` when not needed. | :bangbang: | |
  64. | [`param-names`][param-names] | Enforce consistent param names when creating new promises. | :bangbang: | :wrench: |
  65. | [`always-return`][always-return] | Return inside each `then()` to create readable and reusable Promise chains. | :bangbang: | |
  66. | [`no-native`][no-native] | In an ES5 environment, make sure to create a `Promise` constructor before using. | | |
  67. | [`no-nesting`][no-nesting] | Avoid nested `then()` or `catch()` statements | :warning: | |
  68. | [`no-promise-in-callback`][no-promise-in-callback] | Avoid using promises inside of callbacks | :warning: | |
  69. | [`no-callback-in-promise`][no-callback-in-promise] | Avoid calling `cb()` inside of a `then()` (use [nodeify][] instead) | :warning: | |
  70. | [`avoid-new`][avoid-new] | Avoid creating `new` promises outside of utility libs (use [pify][] instead) | | |
  71. | [`no-new-statics`][no-new-statics] | Avoid calling `new` on a Promise static method | :bangbang: | |
  72. | [`no-return-in-finally`][no-return-in-finally] | Disallow return statements in `finally()` | :warning: | |
  73. | [`valid-params`][valid-params] | Ensures the proper number of arguments are passed to Promise functions | :warning: | |
  74. | [`prefer-await-to-then`][prefer-await-to-then] | Prefer `await` to `then()` for reading Promise values | :seven: | |
  75. | [`prefer-await-to-callbacks`][prefer-await-to-callbacks] | Prefer async/await to the callback pattern | :seven: | |
  76. **Key**
  77. | icon | description |
  78. | ---------- | ----------------------------------------------- |
  79. | :bangbang: | Reports as error in recommended configuration |
  80. | :warning: | Reports as warning in recommended configuration |
  81. | :seven: | ES2017 Async Await rules |
  82. | :wrench: | Rule is fixable with `eslint --fix` |
  83. ## Maintainers
  84. * Jamund Ferguson - [@xjamundx][]
  85. * Macklin Underdown - [@macklinu][]
  86. ## License
  87. * (c) MMXV jden <mailto:jason@denizac.org> - ISC license.
  88. * (c) 2016 Jamund Ferguson <mailto:jamund@gmail.com> - ISC license.
  89. [catch-or-return]: docs/rules/catch-or-return.md
  90. [no-return-wrap]: docs/rules/no-return-wrap.md
  91. [param-names]: docs/rules/param-names.md
  92. [always-return]: docs/rules/always-return.md
  93. [no-native]: docs/rules/no-native.md
  94. [no-nesting]: docs/rules/no-nesting.md
  95. [no-promise-in-callback]: docs/rules/no-promise-in-callback.md
  96. [no-callback-in-promise]: docs/rules/no-callback-in-promise.md
  97. [avoid-new]: docs/rules/avoid-new.md
  98. [no-new-statics]: docs/rules/no-new-statics.md
  99. [no-return-in-finally]: docs/rules/no-return-in-finally.md
  100. [valid-params]: docs/rules/valid-params.md
  101. [prefer-await-to-then]: docs/rules/prefer-await-to-then.md
  102. [prefer-await-to-callbacks]: docs/rules/prefer-await-to-callbacks.md
  103. [nodeify]: https://www.npmjs.com/package/nodeify
  104. [pify]: https://www.npmjs.com/package/pify
  105. [@macklinu]: https://github.com/macklinu
  106. [@xjamundx]: https://github.com/xjamundx