# eslint-comments/no-unused-disable
disallow unused
eslint-disablecomments
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
CLIEngineAPI.
(I.e., theeslintmodule was loaded already, but theLinter.prototype.verifymethod 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.verifyand returns the result as is. - Otherwise, it calls
super.verifywithreportUnusedDisableDirectivesoption. - It converts the result of
super.verifyas fromreportUnusedDisableDirectiveserrors toeslint-comments/no-unused-disableerrors. - It returns the converted result.