What is eslint-plugin-eslint-comments?
The eslint-plugin-eslint-comments npm package provides a set of linting rules for ESLint directive comments (e.g., /* eslint-disable */, /* eslint-enable */, etc.). It helps in managing and enforcing best practices for the use of ESLint directive comments within your codebase. This includes rules for preventing unused or unnecessary disabling of rules, ensuring proper enable/disable pairs, and more.
What are eslint-plugin-eslint-comments's main functionalities?
Disallow Unused ESLint Disable Comments
This rule helps in identifying ESLint disable comments that are unnecessary because the rules they are disabling are not actually reported. It helps in keeping the codebase clean and avoiding confusion about why a rule was disabled.
"eslint-comments/no-unused-disable": "error"
Require Description in ESLint Directive Comments
Enforces that all ESLint directive comments include a description, making it clearer why a rule was disabled or enabled at a specific point in the code. This is useful for maintaining code quality and understanding the context behind disabling a rule.
"eslint-comments/require-description": ["error", { "ignore": [] }]
Disallow Duplicate Disable Comments
Prevents multiple ESLint disable comments for the same rule on consecutive lines. This rule ensures that disable comments are used efficiently and are not repeated unnecessarily.
"eslint-comments/no-duplicate-disable": "error"
Other packages similar to eslint-plugin-eslint-comments
eslint-plugin-import
This package provides linting rules related to ES6+ import/export syntax, ensuring proper paths, naming, and more. While it focuses on module syntax, eslint-plugin-eslint-comments focuses on managing ESLint directive comments. Both contribute to maintaining code quality but in different areas.
eslint-plugin-promise
Offers a set of rules for working with promises, ensuring best practices and avoiding common pitfalls in asynchronous code. Unlike eslint-plugin-eslint-comments, which is focused on ESLint directives, eslint-plugin-promise focuses on the specific area of promise usage.
eslint-plugin-jsx-a11y
This package includes ESLint rules for accessibility in JSX elements, helping developers write accessible code. It's different from eslint-plugin-eslint-comments as it focuses on accessibility concerns rather than the management of ESLint directive comments.
Additional ESLint rules for ESLint directive comments (e.g. //eslint-disable-line
).
💿 Installation
npm install --save-dev eslint eslint-plugin-eslint-comments
Requirements
- Node.js
^6.5.0
, or newer versions. - ESLint
^4.19.1
, or newer versions.
📖 Usage
Write in your ESLint configurations: http://eslint.org/docs/user-guide/configuring#using-the-configuration-from-a-plugin
Example
.eslintrc.json
{
"extends": [
"eslint:recommended",
"plugin:eslint-comments/recommended"
],
}
Or you can specify for each rule:
{
"plugins": [
"eslint-comments"
],
"rules": {
"eslint-comments/no-unused-disable": "error",
"eslint-comments/no-unused-enable": "error",
}
}
Rules
- 🌟 mark: the rule is enabled by
eslint-comments/recommended
preset. - ✒️ mark: the rule is fixable by
eslint --fix
command.
Best Practices
Stylistic Issues
🚥 Semantic Versioning Policy
eslint-plugin-eslint-comments
follows semantic versioning and ESLint's Semantic Versioning Policy.
📰 Changelog
🍻 Contributing
Welcome contributing!
Please use GitHub's Issues/PRs.
Development Tools
npm test
runs tests and measures coverage.npm run build
updates README.md
, index.js
, and the header of all rule's documents.npm run clean
removes the coverage of the last npm test
command.npm run coverage
shows the coverage of the last npm test
command.npm run lint
runs ESLint for this codebase.npm run watch
runs tests and measures coverage when source code are changed.