eslint-plugin-eslint-comments will be broken in 4.6.0
See original GitHub issueeslint-plugin-eslint-comments
is a plugin created by @mysticatea to solve the issue in https://github.com/eslint/eslint/issues/6190 of linting for unused /* eslint-disable */
comments. Since ESLint rules aren’t supposed to be aware of other rules, a plugin like this technically isn’t supposed to be possible. However it was successfully implemented by monkeypatching a private API context.eslint.report
), and has been useful to a lot of people for avoiding unused disable comments.
I just realized that eslint-plugin-eslint-comments
will be broken in v4.6.0 as a result of d672aef42b2950c710d598cb970d630f49b2be4b, which refactors ESLint’s internal reporting logic and removes the private API that was being monkeypatched. With the current version of ESLint on master
, it is no longer possible to implement something like eslint-plugin-eslint-comments
, because context
objects in rules don’t have a reference to the underlying Linter
instance anymore. We explicitly don’t make any guarantees about the stability of undocumented APIs, but it would still be nice to avoid breaking peoples’ linting builds if possible.
So we have a few things to consider:
- Should we revert d672aef42b2950c710d598cb970d630f49b2be4b for now?
- Should we reconsider adding a core feature to warn on unused disable comments? Personally, I don’t think using a plugin for this is a good solution in the long-term, because it breaks the boundaries between rules and prevents us from refactoring internal APIs.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
I agree. For now, I think maybe it would be best to revert https://github.com/eslint/eslint/commit/d672aef42b2950c710d598cb970d630f49b2be4b until we have a better way to lint for unused directive comments.
I tried to update
eslint-plugin-eslint-comments
to use the public API by loading rules and running them within the plugin, but I don’t think it’s possible to make it fully work right now without accessingcontext.eslint
/context._linter
. It can check comments like// eslint-disable-line no-undef
by running theno-undef
rule separately, but it can’t check comments like// eslint-disable-line
that apply to all rules, because it doesn’t know which rules are enabled.In the long term, I think the best solution would be to check for unused directive comments in core, using something similar to what was discussed in https://github.com/eslint/eslint/issues/6190.
For
node/this-in-event-handlers
, I think it would be best to use rule composition. For example:Then users could easily use
node/no-invalid-this
as a replacement forno-invalid-this
andeslint-plugin-node
wouldn’t need to copy the logic fromno-invalid-this
.To avoid needing to do another traversal, maybe it would be possible to extract the listeners manually and call them as part of the
node/no-invalid-this
listeners, then filter out reports in theProgram:exit
listener.