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's directive-comments (e.g. //eslint-disable-line
).
:cd: Installation
npm install --save-dev eslint eslint-plugin-eslint-comments
Requirements
- Node.js
^4.0.0
, ^6.0.0
, or newer. - ESLint
^3.1.0
, or newer.
:book: Usage
Write in your ESLint configurations: http://eslint.org/docs/user-guide/configuring#using-the-configuration-from-a-plugin
Example
.eslintrc.json
{
"plugins": [
"eslint-comments"
],
"rules": {
"eslint-comments/disable-enable-pair": "error",
"eslint-comments/no-duplicate-disable": "error",
"eslint-comments/no-unlimited-disable": "error",
"eslint-comments/no-unused-disable": "error",
"eslint-comments/no-unused-enable": "error",
"eslint-comments/no-use": "error",
}
}
Rules
:anchor: Semantic Versioning Policy
eslint-plugin-eslint-comments
follows semantic versioning and ESLint's Semantic Versioning Policy.
- Patch release (intended to not break your lint build)
- A bug fix in a rule that results in
eslint-plugin-eslint-comments
reporting fewer errors. - Improvements to documentation.
- Non-user-facing changes such as refactoring code, adding, deleting, or modifying tests, and increasing test coverage.
- Re-releasing after a failed release (i.e., publishing a release that doesn't work for anyone).
- Minor release (might break your lint build)
- A bug fix in a rule that results in
eslint-plugin-eslint-comments
reporting more errors. - A new rule is created.
- A new option to an existing rule is created.
- An existing rule is deprecated.
- Major release (likely to break your lint build)
- A support for old Node version is dropped.
- A support for old ESLint version is dropped.
- An existing rule is removed.
- An existing option of a rule is removed.
- An existing config is updated.
:newspaper: Changelog
:muscle: Contributing
Welcome contributing!
Please use GitHub's Issues/PRs.
Development Tools
npm test
runs tests and measures coverage.npm run watch
runs tests and measures coverage when source code are changed.npm run coverage
shows the coverage result of npm test
command.npm run clean
removes the coverage result of npm test
command.