eslint-plugin-promise is an ESLint plugin designed to enforce best practices and prevent common pitfalls when working with JavaScript Promises. It ensures proper promise chain construction, error handling, and discourages anti-patterns like callbacks inside `then()` blocks. The current stable version is `7.2.1`, released in November 2024, indicating an active development and maintenance cadence with several releases throughout the year addressing bugs and adding features. Key differentiators include its comprehensive set of rules covering various promise use cases, from enforcing `catch()` or `return` to disallowing multiple resolutions and improper nesting, thereby enhancing code readability and reliability in asynchronous operations. It supports both legacy `.eslintrc.*` configurations and modern ESLint flat configurations.
npm install eslint-plugin-promiseVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up `eslint-plugin-promise` in an `eslint.config.js` (flat config) file, including importing the plugin, applying its recommended rules, and illustrating some problematic promise patterns the plugin targets.
Upgrade Node.js to `^18.18.0 || ^20.9.0 || >=21.1.0` and ESLint to `^7.0.0 || ^8.0.0 || ^9.0.0`. For ESLint v9, use the flat configuration (`eslint.config.js`).
If enabling `strict` mode for `prefer-await-to-then`, refactor code to use `try/catch` blocks for error handling with `await` instead of `.catch()`. Otherwise, disable the `strict` option if mixed `async/await` and promise chaining is acceptable.
Review affected code; if the rule is incorrectly flagging legitimate code, consider using the `timeoutsErr` option (`no-callback-in-promise": ["error", { "timeoutsErr": true }]`) or disable the rule for specific lines/files with ESLint comments if a false positive cannot be re-architected.For ESLint v9 and `eslint.config.js`, explicitly import the plugin (`import pluginPromise from 'eslint-plugin-promise'`) and use `pluginPromise.configs['flat/recommended']` within your configuration array. Ensure you also map the plugin in the `plugins` object for rule definitions.
Run `npm install eslint-plugin-promise --save-dev` or `yarn add eslint-plugin-promise --dev`.
Ensure `import pluginPromise from 'eslint-plugin-promise';` is at the top of `eslint.config.js`, and the plugin is mapped in `plugins: { promise: pluginPromise }`.Verify that `plugins: { promise: pluginPromise }` is correctly defined in your flat config, or that `"plugins": ["promise"]` is in your `.eslintrc.*` and that the rule name is correctly prefixed (`promise/`).