eslint-config-drupal

raw JSON →
5.0.2 verified Sat Apr 25 auth: no javascript maintenance

ESLint shareable config for Drupal JavaScript. Stable v5.0.2 (2021) targets Drupal 9 standards; infrequent releases. Provides a single `drupal` config that enforces Drupal's coding style and best practices. Unlike generic ESLint configs, it is tailored for Drupal's contributed module and theme development, including proper handling of Drupal's global variables and jQuery patterns. Requires ESLint as a peer dependency.

error Error: Cannot find module 'eslint-config-drupal'
cause Package not installed or ESLint cannot resolve it.
fix
Run npm install --save-dev eslint-config-drupal eslint and ensure node_modules is present.
error ESLint configuration in .eslintrc.json is invalid: "extends": "drupal"
cause Valued string instead of array.
fix
Use ["drupal"] instead of "drupal".
gotcha Package only works with ESLint 5.x; newer ESLint versions may cause incompatibilities.
fix Pin ESLint to 5.x or use eslint-config-drupal v6+
gotcha Requires manual installation of Drupal-specific globals (e.g., Drupal, jQuery) via environment or additional config.
fix Add `"env": { "browser": true, "jquery": true }` or define globals.
deprecated Deprecated default rule `prefer-destructuring` warns for array destructuring, which conflicts with Drupal's coding style.
fix Set `'prefer-destructuring': ['warn', { array: false }]`
npm install eslint-config-drupal
yarn add eslint-config-drupal
pnpm add eslint-config-drupal

Setup ESLint with Drupal config using .eslintrc.json extends field and run linting.

// .eslintrc.json
{
  "extends": [
    "drupal"
  ],
  "rules": {
    "no-console": "warn"
  }
}

// In terminal:
npx eslint yourfile.js