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
Conversation
LGTM |
@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. |
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.
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).
Actually, ESTree ended up switching to |
That's a good point. This issue leads me to believe babel-eslint indeed is still using |
I reached out to @hzoo and it looks like babel-eslint still uses As far as I understand, the |
@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. |
@platinumazure Hmm that's a very good point, thanks for pointing it out! |
lib/rules/prefer-const.js
Outdated
@@ -9,7 +9,7 @@ | |||
// Helpers | |||
//------------------------------------------------------------------------------ | |||
|
|||
const PATTERN_TYPE = /^(?:.+?Pattern|RestElement|Property)$/; | |||
const PATTERN_TYPE = /^(?:.+?Pattern|RestElement|ExperimentalRestProperty|Property)$/; |
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.
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.
LGTM |
Ok so I did a bit more investigating and I found out that babel-eslint already outputs On previous versions of babel-eslint, the node type was being set to I added |
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. |
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.
My concerns are addressed, thanks!
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 thedestructuring: "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?