New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reportUnusedDisableDirectives
should distinguish between globally disable rules and no violation of globally enabled rule
#18218
Comments
Sorry, it's not quite clear what scenario you're describing here. Can you please provide some code as an example, preferably a StackBlitz that shows the behavior you're describing? |
@nzakas , a very simplified example would be https://stackblitz.com/edit/stackblitz-starters-omyohp?file=index.js
Now imagine that Of course, lint with "fast" config has no way of distinguishing between cases of line 3 and line 10; the rule is disabled, so it has no way of knowing whether the directive is needed or not. Currently, they only way to prevent lint with "fast" config from producing warnings for line 3 / from removing directive on line 3 in fix mode is to add |
Thanks, that's very helpful. Just to make sure I understand what you're requesting, let me try to summarize: Current BehaviorA disable directive (
In both cases Desired BehaviorWhen Do I have that correct? |
This is not quite my original idea, because I think that in some cases it would be useful to remove disable directives for rules disabled in the config file, too. So in my original idea, the desired behavior would be to introduce two separate controls for these two cases (e.g. But lacking that, changing the current behavior from "warns in both cases, removes directives in both cases" to "warns in both cases, removes only in case 2" would also solve the immediate issue. |
Got it. Splitting the behavior into two properties would be a breaking change, which we'd need to wait until v10 to do (if the team agreed to that proposal). First, we'd need to see how the team feels about making any change to this behavior. I'm slightly in favor of the change I proposed, so interested to hear what the rest of @eslint/eslint-team thinks. |
This makes sense. I'm in favor of making the option more granular and/or splitting into multiple options. In typescript-eslint we commonly tell folks that if they want fast linting, they can use strategies like the one mentioned here with configs like Tangentially related: I also filed #18230 to track also reporting on unused/redundant inline config comments. I imagine if that is accepted, we'd want to apply a similar strategy from this issue. |
Oops! It looks like we lost track of this issue. What do we want to do here? This issue will auto-close in 7 days without an update. |
ping @eslint/eslint-team |
If |
ESLint version
v8.56.0
What problem do you want to solve?
ESLint currently does not distinguish between disable directives that are unused because the rule they're disabling is already disabled in eslint config, and disable directives that are unused because the code they're disabling it for does not actually violate the rule.
In scenarios when multiple eslint configs are used, running
eslint --fix
on smaller config withreportUnusedDisableDirectives
enabled will currently remove both kinds of unused disabled directives, causingeslint
on larger config to fail.One example would be this:
@typescript-eslint
has a "type-checked" ruleset which requires it to basically compile the entire project, which can take a lot of time on larger projects, regardless of the number of files checked (because it needs the type information from the entire project to check these files). So it is natural to not use this ruleset in fast checks (e.g. on precommit) when we're only interested in knowing if some specific files have any obvious errors, but not interested in spending a minute to get an answer for just one file.Running
eslint --fix my-single-file.ts
with the main eslint config will take minutes on large codebases. Running it with the supplementary eslint config that disables type-checked rules and TS project loading will only take fractions of a second, but (ifreportUnusedDisableDirectives
is enabled) will also cause it to remove all directives disabling specific type-checked rules on specific lines.There is way to work around: it's to disable
reportUnusedDisableDirectives
in the smaller config. But this has a drawback that runningeslint --fix
with the smaller config will not remove directives that are actually unused.What do you think is the correct solution?
I think it would be nice if eslint distinguished between "this directive is unused because I know that the next line does not violate this rule" and "this directive is unused because the rule is globally disabled, but I don't know if the next line violates this rule", and allowed enabling autofixing for the former but not for the latter.
Participation
Additional comments
No response
The text was updated successfully, but these errors were encountered: