2.0.1 • Published 1 year ago

eslint-plugin-no-await-in-promise v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

eslint-plugin-no-await-in-promise

npm

ESLint Plugin to error when using await inside promise statements. Using await inside a Promise.all or Promise.race will make the awaited Promise resolve first, and only after that the Promise.all or Promise.race will be called. For .all, this means the promises are run serially, for .race, the awaited promise will now always win. This is rarely what you want. This plugin will warn you against such usages and suggest an auto-fix.

Rule Details

Examples of incorrect code for this rule:

await Promise.all([await foo(), bar()]);
await Promise.race([foo(), await bar()]);

Examples of correct code for this rule:

await Promise.all([foo(), bar()]);
await Promise.race([foo(), bar()]);

Installation

You'll first need to install ESLint:

npm i eslint --save-dev
# Or
yarn add -D eslint
# Or
pnpm add -D eslint

Next, install eslint-plugin-no-await-in-promise:

npm install eslint-plugin-no-await-in-promise --save-dev
# Or
yarn add -D eslint-plugin-no-await-in-promise
# Or
pnpm add -D eslint-plugin-no-await-in-promise

Usage (flat config)

Configure the plugin in your eslint.config.js:

import noAwaitInPromise from 'eslint-plugin-no-await-in-promise';

export default [
  noAwaitInPromise.configs.recommended,
  // Other plugins here
];

Usage (legacy config)

Note: from version 2.0.0 recommended was renamed to recommended-legacy to avoid conflict with the new recommended flat config.

Configure the plugin in your .eslintrc:

{
  "extends": ["plugin:no-await-in-promise/recommended-legacy"]
}

This essentially expands to:

{
  "plugins": ["no-await-in-promise"],
  "rules": {
    "no-await-in-promise/no-await-in-promise": "error"
  }
}
2.0.1

1 year ago

2.0.0

1 year ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago