Skip to content

Commit 7f4ffbb

Browse files
committed
Docs: update no-unused-disable doc
1 parent 90e3da8 commit 7f4ffbb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/rules/no-unused-disable.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,29 @@ var foo = bar() //eslint-disable-line no-undef
3838

3939
doSomething()
4040
```
41+
42+
## Known limitations
43+
44+
This rule might not work fine if the rule wasn't loaded from [CLIEngine](https://eslint.org/docs/developer-guide/nodejs-api#cliengine) class because this rule is hacky a bit.
45+
46+
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](https://github.com/eslint/eslint/issues/10140) for details).
47+
So this rule is now using two public APIs as an alternative hack.
48+
49+
- [require.cache](https://nodejs.org/api/modules.html#modules_require_cache)
50+
- [Linter.prototype.verify](https://eslint.org/docs/developer-guide/nodejs-api#linterverify)
51+
52+
And it needs an assumption:
53+
54+
- The rule was loaded from `CLIEngine` API.<br>
55+
(I.e., the `eslint` module was loaded already, but the `Linter.prototype.verify` method hasn't been called yet.)
56+
57+
### How it works
58+
59+
When the rule is loaded, it searches `eslint` module from `require.cache` API and it overrides `Linter.prototype.verify` method.
60+
61+
The overridden `Linter.prototype.verify` method does the following steps:
62+
63+
1. If `config.rules["eslint-comments/no-unused-disable"]` is not enabled, it calls `super.verify` and returns the result as is.
64+
2. Otherwise, it calls `super.verify` with `reportUnusedDisableDirectives` option.
65+
3. It converts the result of `super.verify` as from `reportUnusedDisableDirectives` errors to `eslint-comments/no-unused-disable` errors.
66+
4. It returns the converted result.

0 commit comments

Comments
 (0)