Navigation Menu

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: id-blacklist should ignore ObjectPatterns (fixes #12787) #12792

Merged
merged 6 commits into from Jan 17, 2020

Conversation

jpramassini
Copy link
Contributor

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:

#12787

What changes did you make? (Give an overview)
I modified the should report logic to check that the effectiveParent's parent is a block statement and added tests for the case.

Is there anything you'd like reviewers to focus on?
Thoughts on any potentially cleaner ways to accomplish this? This is my first PR to ESLint so I want to make sure it's up to snuff.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Jan 15, 2020
@yeonjuan
Copy link
Member

yeonjuan commented Jan 15, 2020

@jpramassini
Hello.
I'm not an eslint member but leave a comment.
Issue #12787 is related to the Destructuring assignment, while the codes in your test cases are Labeled statement.

code: "{foo: bar}",

Your changes should pass these test cases.

// valid
{
  code: “const { foo: bar } = baz”,
  options: [“foo”],
  parserOptions: { ecmaVersion: 6 }
}

// invalid
{
  code: “const { foo: bar } = baz”,
  options: [“bar”],
  parserOptions: { ecmaVersion: 6 },
  errors: [
     // ...
  ]
}

@jpramassini
Copy link
Contributor Author

jpramassini commented Jan 15, 2020

@yeonjuan This is a very good point, dumb mistake on my part. I'll update my test cases later today. Update: My code doesn't work with accurate test cases, so I'll revisit my approach here.

@kaicataldo kaicataldo added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Jan 15, 2020
Copy link
Member

@kaicataldo kaicataldo 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 contributing! I don't think this current iteration is going to work since BlockStatement nodes aren't related to the bug in question. Here's what the AST looks like for a destructured assignment.

@kaicataldo
Copy link
Member

kaicataldo commented Jan 15, 2020

I also want to note that the fix should be to not warn on destructured assignments at all. From the rule docs (emphasis my own):

It will not catch blacklisted identifiers that are:

  • function calls (so you can still use functions you do not have control over)
  • object properties (so you can still use objects you do not have control over)

Ideally, I do think the rule should warn when a property is renamed to a blacklisted identifier name in a destructuring assignment, but I also think that can (and probably should) be done in a separate PR as a separate bug fix.

@jpramassini
Copy link
Contributor Author

@kaicataldo Thanks for the help on the AST! I'll take another crack at this.

@jpramassini
Copy link
Contributor Author

@kaicataldo Updated to ignore in Object Pattern nodes, and removed the error test case as we want to ignore it for this PR.

@kaicataldo
Copy link
Member

You got it! Feel free to reach out with any questions you have :)

lib/rules/id-blacklist.js Outdated Show resolved Hide resolved
tests/lib/rules/id-blacklist.js Show resolved Hide resolved
@kaicataldo
Copy link
Member

We're getting closer! Thanks for working on this.

@jpramassini
Copy link
Contributor Author

jpramassini commented Jan 16, 2020

Do we want an error test case for function foo({ bar: baz }) {}? I.e. testing to make sure we're still getting the function name if foo is illegal?

@kaicataldo
Copy link
Member

Sorry, that wasn't a great example. I think a test for the destructured parameters is sufficient. In the example above, that would be having bar blacklisted and not warning.

@kaicataldo
Copy link
Member

That being said, additional tests are always welcome :)

@jpramassini
Copy link
Contributor Author

I think between the existing function name tests and the added nested and destructured arguments we should be covered, so I left it out.

@kaicataldo
Copy link
Member

One last thing from me: do you mind updating the PR title to more accurately reflect the current iteration of this PR?

@jpramassini jpramassini changed the title Fix: Ignore destructured object property reassignments. (fixes #12787) Fix: Ignore destructured object property reassignments and destructured object function arguments. (fixes #12787) Jan 16, 2020
} else if (node.parent.type === "Property") {

if (shouldReport(effectiveParent, name)) {
report(node);
}

// Report anything that is a match and not a CallExpression
// Report anything that is a match and not a CallExpression
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind undoing this? This is referring to the following block and I think it's clearer to have it indented as it was.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pushed a commit that should fix this, the commit has these lined up properly but for some reason the diff doesn't seem to have updated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I see that. Strange :/ Seems like something on GitHub's end?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it. This is the first time I've had this happen. 🤷‍♂

@kaicataldo
Copy link
Member

Re the commit message check that's failing now: How about changing it to Fix: id-blacklist should ignore ObjectPatterns (fixes #12787)?

@jpramassini jpramassini changed the title Fix: Ignore destructured object property reassignments and destructured object function arguments. (fixes #12787) Fix: id-blacklist should ignore ObjectPatterns (fixes #12787) Jan 16, 2020
@jpramassini
Copy link
Contributor Author

Thanks for your patience and help, sorry for all the small gotchas here.

@kaicataldo
Copy link
Member

You're doing great. We really appreciate the contribution!

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM. Thank you for contributing to ESLint!

@jpramassini
Copy link
Contributor Author

Awesome, thanks again for all of your help!

@@ -65,6 +65,26 @@ ruleTester.run("id-blacklist", rule, {
code: "var obj = { key: foo.bar };",
options: ["f", "fo", "fooo", "b", "ba", "barr", "bazz", "bingg"]
},
{
code: "const {foo: bar} = baz",
options: ["foo", "bar"],
Copy link
Member

@yeonjuan yeonjuan Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpramassini
Hi, In my opinion, this case should be included in invalid because it makes a new identifier bar, which is in the id-blacklist.

Ideally, I do think the rule should warn when a property is renamed to a blacklisted identifier name in a destructuring assignment, but I also think that can (and probably should) be done in a separate PR as a separate bug fix.

I got it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this should definitely be invalid at some point due to the spirit of the rule. I added that to try and illustrate for now that that's intended behavior for now. Should I make a separate issue to make sure that gets tracked?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I make a separate issue to make sure that gets tracked?

Maybe it would be welcomed, but it is up to you. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An issue would be great!

Copy link
Member

@btmills btmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for fixing this!

@btmills btmills merged commit 756b95d into eslint:master Jan 17, 2020
@jpramassini
Copy link
Contributor Author

@kaicataldo Unsure of where to put this, this seems like the best place to follow up. For the issue to track the reassignment identifier warning for this rule, should that issue be categorized as a bug fix, or is it a rule change proposal?

@kaicataldo
Copy link
Member

I think it should be categorized as a semver-minor bug fix (reported as a bug fix).

@jpramassini
Copy link
Contributor Author

@kaicataldo New issue here: #12807

montmanu pushed a commit to montmanu/eslint that referenced this pull request Mar 4, 2020
…slint#12792)

* Fix: Ignore destructured object property reassignments. (fixes eslint#12787)

* Updated to ignore blacklisted id's in ObjectPattern nodes.

* Remove console.log.

* Added tests for nested destructuring and destructuring function parameters.

* Fix typo.

* Undo accidentally auto-fixed comment indent.
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jul 17, 2020
@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 Jul 17, 2020
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 rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants