# eslint-comments/no-unused-disable
disallow unused
eslint-disable
comments
Since refactoring or a bug fix of upstream, an eslint-disable
directive-comment may become unnecessary.
In that case, you should remove the garbage as soon as possible since the garbage may cause to overlook ESLint warnings in future.
This rule warns unnecessary eslint-disable
directive-comments.
# Rule Details
Examples of 👎 incorrect code for this rule:
/*eslint eslint-comments/no-unused-disable: error, eqeqeq: error, no-undef: error */
var foo = bar() //eslint-disable-line no-undef,eqeqeq
/*eslint eslint-comments/no-unused-disable: error, eqeqeq: error, no-undef: error */
/*globals doSomething */
doSomething() //eslint-disable-line
Examples of 👍 correct code for this rule:
/*eslint eslint-comments/no-unused-disable: error, eqeqeq: error, no-undef: error */
var foo = bar() //eslint-disable-line no-undef
/*eslint eslint-comments/no-unused-disable: error, eqeqeq: error, no-undef: error */
/*globals doSomething */
doSomething()
# Known limitations
This rule might not work fine if the rule wasn't loaded from CLIEngine class because this rule is hacky a bit.
Previously, this rule had depended on a private API of ESLint, but the private API was removed at ESLint 5.0.0 (see eslint/eslint#10140 for details). So this rule is now using two public APIs as an alternative hack.
And it needs an assumption:
- The rule was loaded from
CLIEngine
API.
(I.e., theeslint
module was loaded already, but theLinter.prototype.verify
method hasn't been called yet.)
# How it works
When the rule is loaded, it searches eslint
module from require.cache
API and it overrides Linter.prototype.verify
method.
The overridden Linter.prototype.verify
method does the following steps:
- If
config.rules["eslint-comments/no-unused-disable"]
is not enabled, it callssuper.verify
and returns the result as is. - Otherwise, it calls
super.verify
withreportUnusedDisableDirectives
option. - It converts the result of
super.verify
as fromreportUnusedDisableDirectives
errors toeslint-comments/no-unused-disable
errors. - It returns the converted result.