Registry / testing / eslint-plugin-promise

eslint-plugin-promise

JSON →
library7.2.1jsnpmunverified

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.

testing
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

For use in `eslint.config.js` with ESLint's new flat configuration system (ESLint v9+).

import pluginPromise from 'eslint-plugin-promise';

In legacy `.eslintrc.*` files, plugins are referenced by their short name in the `plugins` array. The plugin is loaded by ESLint itself; direct JavaScript imports are not used for configuration.

{ "plugins": ["promise"] }

Applies the plugin's recommended set of rules for common best practices in `.eslintrc.*`.

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

Utilizes the plugin's recommended flat configuration object, typically spread into the `export default []` array in `eslint.config.js`.

pluginPromise.configs['flat/recommended']

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.

import pluginPromise from 'eslint-plugin-promise'; import globals from 'globals'; export default [ { files: ['**/*.js'], languageOptions: { ecmaVersion: 'latest', sourceType: 'module', globals: { ...globals.node, ...globals.browser } }, plugins: { promise: pluginPromise }, rules: { ...pluginPromise.configs['flat/recommended'].rules, // Override or add specific rules 'promise/always-return': 'error', 'promise/no-nesting': 'warn', 'promise/prefer-await-to-then': 'error' } } ]; // Example file: src/async.js // async function fetchData() { // return fetch('/api/data') // .then(response => response.json()) // .catch(error => console.error('Fetch error:', error)); // } // // const badPromise = new Promise(resolve => { // resolve('first'); // resolve('second'); // Will be flagged by no-multiple-resolved // }); // // function processData(data, cb) { // Promise.resolve(data).then(() => { // cb(null, data); // Will be flagged by no-callback-in-promise // }); // } // // fetchData();
Debug
Known footguns
breakingVersion 7.0.0 updated Node.js and ESLint peer dependency versions to align with ESLint v9, which means Node.js versions prior to 18.18.0 and ESLint versions older than 7.0.0 are no longer officially supported.
gotchaThe `prefer-await-to-then` rule, when used with the `strict` option, will disallow `.then()` or `.catch()` following `await` expressions, which can be useful for enforcing full `async/await` syntax but might break existing codebases using mixed patterns.
gotchaThe `no-callback-in-promise` rule can sometimes trigger false positives, especially in complex scenarios or when using specific patterns that mimic callbacks but are not true anti-patterns for promises.
breakingWith the introduction of ESLint's flat configuration system (ESLint v9+), the way plugins are configured has changed. The `extends` property with `plugin:promise/recommended` in `.eslintrc.*` is for legacy configurations.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
16 hits · last 30 days
gptbot
4
ahrefsbot
4
chatgpt-user
4
script
1
googlebot
1
Resources