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: prefer-const false positive with object spread (fixes #8187) #8297

Merged
merged 2 commits into from Mar 30, 2017

Conversation

vitorbal
Copy link
Member

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:

This fixes a false-positive with prefer-const and the destructuring: "all" option. Essentially, the option was not taking into account destructurings that contained a rest operator.
The original bug-report is here: #8187 (comment)

What changes did you make? (Give an overview)
I've added a couple of test cases that reproduce the bug, then modified the prefer-const rule accordingly to fix the bug.

Is there anything you'd like reviewers to focus on?
I'm not sure, but I think not. Maybe suggestions for more test cases?

@vitorbal vitorbal 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 labels Mar 20, 2017
@eslintbot
Copy link

LGTM

@mention-bot
Copy link

@vitorbal, thanks for your PR! By analyzing the history of the files in this pull request, we identified @mysticatea, @not-an-aardvark and @NickHeiner to be potential reviewers.

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.

Might be worth writing a test based on babel-eslint's parse output if you can-- I don't know if they use ExperimentalRestProperty or just RestProperty (and I think eventually the Stage 3 proposal will use the latter).

@not-an-aardvark
Copy link
Member

Actually, ESTree ended up switching to RestElement. I think babel-eslint might still use RestProperty though.

@vitorbal
Copy link
Member Author

vitorbal commented Mar 20, 2017

Actually, ESTree ended up switching to RestElement. I think babel-eslint might still use RestProperty though.

That's a good point. This issue leads me to believe babel-eslint indeed is still using RestProperty. ping @hzoo can you confirm?

@vitorbal
Copy link
Member Author

I reached out to @hzoo and it looks like babel-eslint still uses RestProperty, so I'm gonna update the PR to add a check for it as well.

As far as I understand, the RestProperty usage will be cleaned up after babel/babel-eslint#440, so we could do a sweeping change and clean up the occurences in eslint too once that's done.

@platinumazure
Copy link
Member

@vitorbal Thanks for checking! I think removing RestProperty from every rule should probably be considered a semver-major change since we don't know what other parsers might use it and rely on ESLint supporting that node type.

@vitorbal
Copy link
Member Author

@platinumazure Hmm that's a very good point, thanks for pointing it out!

@@ -9,7 +9,7 @@
// Helpers
//------------------------------------------------------------------------------

const PATTERN_TYPE = /^(?:.+?Pattern|RestElement|Property)$/;
const PATTERN_TYPE = /^(?:.+?Pattern|RestElement|ExperimentalRestProperty|Property)$/;
Copy link
Member

Choose a reason for hiding this comment

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

Given what we've uncovered in the discussion, this should probably include RestProperty as well.

If at all possible, a test which simulates the babel-eslint parser's output would also be awesome, but don't put too much effort into that.

@eslintbot
Copy link

LGTM

@vitorbal
Copy link
Member Author

Ok so I did a bit more investigating and I found out that babel-eslint already outputs ExperimentalRestProperty since v6.x (babel/babel-eslint@31dd811).

On previous versions of babel-eslint, the node type was being set to SpreadProperty (instead of RestProperty, like we previously believed).

I added SpreadProperty to the regexp pattern, since I assume babel-eslint 5.x still sees some usage (it only supports ESLint 1.x, though...).
I also wrote a stub parser fixture for the ast output from babel-eslint 5.x, and a couple of tests.
If folks think the tests are not necessary I can remove them, but I figured it wouldn't hurt.

@vitorbal vitorbal self-assigned this Mar 28, 2017
@vitorbal
Copy link
Member Author

ping @not-an-aardvark @platinumazure. Any chance you guys could take another look at this? Would like to get it merged before the release this Friday, if possible.

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.

My concerns are addressed, thanks!

@vitorbal vitorbal merged commit 27616a8 into master Mar 30, 2017
@vitorbal vitorbal deleted the issue8187 branch March 30, 2017 10:15
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 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 Feb 6, 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 rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants