ESLint Plugin for Promises

7.2.1 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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();

view raw JSON →