7.1.0 • Published 4 months ago

eslint-plugin-promise v7.1.0

Weekly downloads
2,406,559
License
ISC
Repository
github
Last release
4 months ago

eslint-plugin-promise

Enforce best practices for JavaScript promises.

CI npm version code style: prettier

Installation

You'll first need to install ESLint:

npm install eslint --save-dev

Next, install eslint-plugin-promise:

npm install eslint-plugin-promise --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-promise globally.

Usage

Add promise to the plugins section of your .eslintrc.json configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": ["promise"]
}

Then configure the rules you want to use under the rules section.

{
  "rules": {
    "promise/always-return": "error",
    "promise/no-return-wrap": "error",
    "promise/param-names": "error",
    "promise/catch-or-return": "error",
    "promise/no-native": "off",
    "promise/no-nesting": "warn",
    "promise/no-promise-in-callback": "warn",
    "promise/no-callback-in-promise": "warn",
    "promise/avoid-new": "warn",
    "promise/no-new-statics": "error",
    "promise/no-return-in-finally": "warn",
    "promise/valid-params": "warn",
    "promise/no-multiple-resolved": "error"
  }
}

or start with the recommended rule set:

  • eslint.config.js:

    import pluginPromise from 'eslint-plugin-promise'
    export default [
      // ...
      pluginPromise.configs['flat/recommended'],
    ]
  • .eslintrc.*:

    {
      "extends": ["plugin:promise/recommended"]
    }

Rules

💼 Configurations enabled in.\ ⚠️ Configurations set to warn in.\ 🚫 Configurations disabled in.\ ✅ Set in the flat/recommended configuration.\ ✅ Set in the recommended configuration.\ 🔧 Automatically fixable by the --fix CLI option.

Name                     Description💼⚠️🚫🔧
always-returnRequire returning inside each then() to create readable and reusable Promise chains.
avoid-newDisallow creating new promises outside of utility libs (use util.promisify instead).
catch-or-returnEnforce the use of catch() on un-returned promises.
no-callback-in-promiseDisallow calling cb() inside of a then() (use util.callbackify instead).
no-multiple-resolvedDisallow creating new promises with paths that resolve multiple times.
no-nativeRequire creating a Promise constructor before using it in an ES5 environment.
no-nestingDisallow nested then() or catch() statements.
no-new-staticsDisallow calling new on a Promise static method.🔧
no-promise-in-callbackDisallow using promises inside of callbacks.
no-return-in-finallyDisallow return statements in finally().
no-return-wrapDisallow wrapping values in Promise.resolve or Promise.reject when not needed.
param-namesEnforce consistent param names and ordering when creating new promises.
prefer-await-to-callbacksPrefer async/await to the callback pattern.
prefer-await-to-thenPrefer await to then()/catch()/finally() for reading Promise values.
spec-onlyDisallow use of non-standard Promise static methods.
valid-paramsEnforces the proper number of arguments are passed to Promise functions.

Maintainers

License

@yysmx/eslint-config@yysmx/eslint-config-basic@anjun-brasil/eslint-configwhzbcx_web_comswhzbcx_web_cxwhzbcx_web_cx3whzbcx_web_cxewhzbcx_web_cxgiswhzbcx_web_gwwhzbcx_web_sjzxwhzbcx_web_swdzwhzbcx_web_xjwhzbcx_web_yzwmc-eslintxcc-standard-eslint@bridge-tools/config@yoyuo/eslint-config@azul-tecnologia/eslint-config@lvyunlong/eslint-config@lvyunlong/eslint-config-basic@jcamp/eslint-config-basic@jiqi/eslint-config@jiqi/eslint-config-basic@jiralite/eslint-config-neon@kaivanwong/eslint-config-base@qualopreco/eslint-config@rjqh/eslint-config-basic@rain-star/eslint-config-basic@cyenoch/eslint-config@fiuzagr/boot@asasinmode/eslint-config@knapsack-cloud/msk-design-system@obvcloud/eslint-config-preset-basic@denverzh/eslint-config@denverzh/eslint-config-baseeslint-config-bambieslint-config-metamoeslint-config-nectis@wongbejoonline/eslint-plugin-wbo@maiscrm/eslint-config-frontendnoodles-normes6-flowyreact-antd-scripts-newreact-native-brave@wheresalice/standard-adfreeeslint-config-contra@oka_technology/eslint-config@suozhao/eslint-vue-168ch168vueeslinteslint-vue-168@analogyxbi-ui/build-configvideocapturinghaodfplusnode-next-servermagnoabsass-sdfddabc-jdjdjjdmo-foundation-base@ffbutton/eslint-config-baseeslint-config-standard-vincent@outcome-co/eslint-config@mole/eslint-config-vueflowycharteslint-config-slickidvcyp-mdlinksyp-.mdlinksswiss-tourneysprobica15probica16eslint-config-quartztogether-lib@martyncherry/eslint-configmetamo-eslint-configmetamo-lint-config@mark42/deploy@straal/eslint-config-fp-startereslint-config-smarchetti@scalara/eslintconfigeslint-config-prettystandard-vueeslint-config-clicktimegusgard-eslint-configzjlab-clieslint-config-demingdemingeslint-config-kelexkelex-clislm_cdkkelex-plugin-lintkelex-plugin-apptemp2-test-scriptseslint-config-mti@iftek/standardcq-batch-templatedeming-linterbb-chateslint-plugin-matt@sno2wman/eslint-config@usehatchapp/eslint-config-hatchcontentcluster
7.1.0

4 months ago

6.5.0

4 months ago

7.0.0

4 months ago

6.6.0

4 months ago

6.5.1

4 months ago

6.3.0

5 months ago

6.4.0

5 months ago

6.2.0

6 months ago

6.1.0

2 years ago

6.1.1

2 years ago

6.0.1

2 years ago

5.2.0

3 years ago

6.0.0

3 years ago

5.1.1

3 years ago

5.1.0

4 years ago

5.0.0

4 years ago

4.3.1

4 years ago

4.3.0

4 years ago

4.2.1

5 years ago

4.1.1

6 years ago

4.1.0

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.8.0

7 years ago

3.7.0

7 years ago

3.6.0

7 years ago

3.5.0

8 years ago

3.4.2

8 years ago

3.4.1

8 years ago

3.4.0

8 years ago

3.4.0-0

8 years ago

3.3.2

8 years ago

3.3.1

8 years ago

3.3.0

8 years ago

3.2.1

8 years ago

3.2.0

8 years ago

3.1.0

8 years ago

3.0.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.3.2

8 years ago

1.3.1

8 years ago

1.3.0

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.8

9 years ago

1.0.0

9 years ago