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: camelcase duplicate warning bug (fixes #10801) #10802

Merged
merged 1 commit into from Sep 1, 2018

Conversation

helixbass
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:

See #10801 for description of behavior

What changes did you make? (Give an overview)
Fixed the logic in lib/rules/camelcase.js, and added a test that would've been broken before the fix

Basically, there appears to have been faulty logic introduced by #10373:

This guard (pre-#10373) was preventing reporting the key of a Property:

node.parent.key === node && node.parent.value !== node

Then #10373 replaced that guard with this:

!assignmentKeyEqualsValue && node.parent.key === node

The hole introduced in the logic is if assignmentKeyEqualsValue but node.parent.key !== node.parent.value, the value gets reported twice (once while visiting the key and once while visiting the value)

I believe that the only reason existing invalid tests like var { category_id } = query; weren't failing on duplicate warnings is that the default parser (espree?) must reuse the same Identifier node for the key and value of a shorthand Property (as opposed to the Coffeescript custom parser I'm working on, which doesn't reuse the same node, thus how I found this bug)

But then by adding an invalid test for var { category_id: category_id } = query;, you get a duplicate warning (it exposes the hole in the logic, since assignmentKeyEqualsValue but the Property's key and value are two different Identifier objects)

So the fix is basically to restore the pre-#10373 guard logic so that you effectively never visit the Property key

Is there anything you'd like reviewers to focus on?

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Aug 26, 2018
Copy link
Member

@platinumazure platinumazure 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!

Copy link
Member

@platinumazure platinumazure 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!

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

Thanks for contributing to ESLint!

@kaicataldo kaicataldo merged commit 6e110e6 into eslint:master Sep 1, 2018
@helixbass helixbass deleted the camelcase-duplicate-report-bug branch September 11, 2018 18:33
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Mar 2, 2019
@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 2, 2019
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