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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Handle nested disable directive correctly (fixes #9318) #9322
Conversation
@gyandeeps, thanks for your PR! By analyzing the history of the files in this pull request, we identified @not-an-aardvark, @aladdin-add and @i-ron-y to be potential reviewers. |
c145215
to
6648bb0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this.
To me, it seems like this solution is more complex than necessary. I'll take a look at it to see if I can make it simpler.
lib/util/apply-disable-directives.js
Outdated
|
||
switch (directive.type) { | ||
case "disable-line": | ||
tempDisabledByLine.add(directive.ruleId === null ? "all" : directive.ruleId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail if someone creates a rule with the id "all"
.
lib/util/apply-disable-directives.js
Outdated
) { | ||
problems.push(problem); | ||
} | ||
|
||
lineDisabledRules.set(problem.line, { | ||
column: directive.column || 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the column matter here? eslint-disable-line
comments should apply to the entire line, regardless of where they're placed on the line.
lib/util/apply-disable-directives.js
Outdated
|
||
for (const problem of options.problems) { | ||
let tempDisabledByLine = new Set(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the name of this comment -- why is it temp
?
lib/util/apply-disable-directives.js
Outdated
|
||
for (const problem of options.problems) { | ||
let tempDisabledByLine = new Set(); | ||
let directive = {}; | ||
const lineDisabledRule = lineDisabledRules.get(problem.line); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are enable-line
directives needed if we are filtering by line here anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because sometimes there would be no code on a disabled line and then next line would have code with violations. That would only for some unique scenarios like this one
eslint/tests/lib/util/apply-disable-directives.js
Lines 352 to 360 in 22bf943
it("keeps problems after the next line", () => { | |
assert.deepEqual( | |
applyDisableDirectives({ | |
directives: [{ type: "disable-next-line", line: 1, column: 1, ruleId: null }], | |
problems: [{ line: 3, column: 3, ruleId: "foo" }] | |
}), | |
[{ line: 3, column: 3, ruleId: "foo" }] | |
); | |
}); |
001ac4f
to
22bf943
Compare
LGTM |
@gyandeeps I made a few modifications to your implementation in #9323, which makes the implementation a bit simpler. Feel free to merge that if you're okay with those changes (the base branch of #9323 is your |
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I might have made a mistake -- I'm still getting an error when linting the code from #9318 (comment) on this branch. Requesting changes while I figure out what's going on.
@gyandeeps I made another PR onto this branch: #9324 |
LGTM |
@@ -343,19 +388,6 @@ describe("apply-disable-directives", () => { | |||
[] | |||
); | |||
}); | |||
|
|||
it("keeps problems on the next line if there is an eslint-enable comment before the problem on the next line", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the confusion... I dont think we should remove this test...
This behavior in this test does make sense....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really? I think the behavior is sort of strange -- this is the only place where the "block" directives and the "line" directives interact with each other. I think it makes more sense for them to be separate, and people can just use /* eslint-disable */
rather than // eslint-disable-line
if they only want to disable part of a line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably decide about the correct behavior here. I think the version that's currently on this PR is the most reasonable choice (and at very least it's better than the version on master). If there is going to be a patch release tomorrow, then I think we should either decide this quickly or merge the PR as-is and decide it later.
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[ x ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Fixed a bug where nested eslint disable directive created some issues. Please refer to the linked issue for examples.
Is there anything you'd like reviewers to focus on?