Change Request: Enable `reportUnusedDisableDirectives` config option by default
See original GitHub issue2022-12 UPDATE
I have opened an RFC for this:
ESLint version
8.5.0
What problem do you want to solve?
Outdated/unused ESLint disable directive comments (e.g. notConsole(); // eslint-disable-line no-console
) are currently a blind spot for most apps/repositories. These leftover comments cause clutter and confusion, and detecting them requires going out of one’s way by using one of the following existing solutions:
- Run linting with
eslint --report-unused-disable-directives
(errors, but only applies during CLI) - Add
reportUnusedDisableDirectives: true
to .eslintrc.js config file (warns) - Enabling third-party rule eslint-comments/no-unused-disable (errors, but requires third-party plugin)
These existing solutions are fine but they lack discoverability and require manual work to adopt in every single repository so are thus not commonly used.
What do you think is the correct solution?
As a breaking change, I propose changing the default value for the config option reportUnusedDisableDirectives
from false to true. This will cause users to see additional warnings if they have unused disable directives.
Displaying these warnings should help raise awareness about the problem of unused disable directives, and encourage many users to remove unused disable directives caused by their changes.
Note that since these are just warnings, users could also choose to ignore them and let them pile up, as a potential downside. But luckily, the new functionality from running eslint --fix --report-unused-disable-directives
could be used to fix/remove all of them at any time.
Another note is that we need to limit any default behavior to warnings and not errors for this due to our semver policy. More context in:
- https://github.com/eslint/eslint/pull/14699#discussion_r650863268
…because of our semver policy, which says that bug fixes that produce fewer errors should not break builds.
- https://github.com/eslint/eslint/issues/12703#issuecomment-568582014
If we allowed for errors to be reported with reportUnusedDisableDirectives, we would limit what kind of changes we could publish in a semver-patch release (since fixing a bug that would result in fewer errors could create additional unused disable directives).
Participation
- I am willing to submit a pull request for this change.
Additional comments
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:20 (18 by maintainers)
Top GitHub Comments
@nzakas your questions have got me thinking that the current boolean design of these options is particularly confusing and unintuitive, making it hard to predict the interplay.
What if I described a new “explicit severity” design:
off
,warn
,error
Benefits of this design:
off
/warn
/error
), regardless of where they set the option fromreportUnusedDisableDirectives: 'error'
can now be part of a shareable configOn top of this design, we can still debate what the default value should be:
off
warn
error
(potential semver implication, but this is my preference if acceptable)I have opened an RFC for this: