Skip to content
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

Merged
merged 5 commits into from Sep 18, 2017
Merged

Conversation

gyandeeps
Copy link
Member

@gyandeeps gyandeeps commented Sep 17, 2017

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?

  • Not very clean (I kinda think - not sure why) but it looks to solve the problem.
  • Column calculation threw a 馃敡 . 馃槃

@mention-bot
Copy link

@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.

@gyandeeps gyandeeps added bug ESLint is working incorrectly core Relates to ESLint's core APIs and features patch candidate This issue may necessitate a patch release in the next few days labels Sep 17, 2017
@eslint eslint deleted a comment from eslintbot Sep 17, 2017
Copy link
Member

@not-an-aardvark not-an-aardvark left a 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.


switch (directive.type) {
case "disable-line":
tempDisabledByLine.add(directive.ruleId === null ? "all" : directive.ruleId);
Copy link
Member

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".

) {
problems.push(problem);
}

lineDisabledRules.set(problem.line, {
column: directive.column || 0,
Copy link
Member

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.


for (const problem of options.problems) {
let tempDisabledByLine = new Set();
Copy link
Member

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?


for (const problem of options.problems) {
let tempDisabledByLine = new Set();
let directive = {};
const lineDisabledRule = lineDisabledRules.get(problem.line);
Copy link
Member

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?

Copy link
Member Author

@gyandeeps gyandeeps Sep 17, 2017

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

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" }]
);
});

@eslintbot
Copy link

LGTM

@not-an-aardvark
Copy link
Member

not-an-aardvark commented Sep 17, 2017

@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 issue9318 branch, which is on this PR).

@eslintbot
Copy link

LGTM

@gyandeeps gyandeeps closed this Sep 17, 2017
@gyandeeps gyandeeps reopened this Sep 17, 2017
@not-an-aardvark not-an-aardvark changed the title Fix: Handle nested disable directive correctly (fixes 9318) Fix: Handle nested disable directive correctly (fixes #9318) Sep 17, 2017
Copy link
Member

@not-an-aardvark not-an-aardvark left a 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.

@not-an-aardvark
Copy link
Member

@gyandeeps I made another PR onto this branch: #9324

@eslintbot
Copy link

LGTM

@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion regression Something broke labels Sep 17, 2017
@@ -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", () => {
Copy link
Member Author

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....

Copy link
Member

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.

Copy link
Member

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.

@btmills btmills merged commit 08656db into master Sep 18, 2017
@gyandeeps gyandeeps deleted the issue9318 branch September 18, 2017 21:00
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Mar 18, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Mar 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features patch candidate This issue may necessitate a patch release in the next few days regression Something broke
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants