Skip to content

Getting Started

npm versionDownloads/monthBuild Statuscodecov

Additional ESLint rules for ESLint directive comments (e.g. //eslint-disable-line).

🏁 Goal

The purpose of this plugin is to apply best practices on directive comments such as /* eslint-disable */.

For example,

  • to disallow unused disabling.
  • to disallow non-effect enabling.
  • to require rule IDs for disabling and enabling.

💿 Installation

Use npm or a compatible tool.

console
npm install --save-dev eslint @eslint-community/eslint-plugin-eslint-comments

Requirements

  • Node.js ^12.22.0 || ^14.17.0 || >=16.0.0
  • ESLint ^6.0.0 || ^7.0.0 || ^8.0.0

📖 Usage

Configure your eslint.config.* file.

For example:

js
import js from "@eslint/js"
import comments from "@eslint-community/eslint-plugin-eslint-comments/configs"

export default [
    js.configs.recommended,
    comments.recommended,
]

If your project's ESLint config runs in CommonJS instead of ESM, use require():

js
const comments = require("@eslint-community/eslint-plugin-eslint-comments/configs")

Either way, you can optionally configure individual rules:

js
// ...
[
    // ...
    comments.recommended,
    {
        "@eslint-community/eslint-comments/no-unused-disable": "error"
    },
]

TIP

The @eslint-community/eslint-comments/no-unused-disable rule has the same effect as --report-unused-disable-directives option. However, the @eslint-community/eslint-comments/no-unused-disable rule is relatively useful since it can be configured in shareable configs.

📜 Legacy ESLint Configs

Configure your .eslintrc.* file.

For example:

jsonc
{
    "extends": [
        "eslint:recommended",
        "plugin:@eslint-community/eslint-comments/recommended"
    ],
    "rules": {
        // Optional.
        "@eslint-community/eslint-comments/no-unused-disable": "error"
    }
}