Update: no-useless-rename also reports default values (fixes #12301)#12322
Update: no-useless-rename also reports default values (fixes #12301)#12322platinumazure merged 2 commits intomasterfrom
Conversation
3a00488 to
18b41ed
Compare
18b41ed to
9905f36
Compare
platinumazure
left a comment
There was a problem hiding this comment.
LGTM, thanks!
I agree this should be semver-minor.
| @@ -85,7 +90,9 @@ module.exports = { | |||
| const properties = node.properties; | |||
|
|
|||
| for (let i = 0; i < properties.length; i++) { | |||
There was a problem hiding this comment.
Do we use the index anymore, outside of the next line? If not, should this be turned into a for-of loop?
There was a problem hiding this comment.
Updated! Did some further refactoring while I was at it. The code looks a bit simpler now!
9905f36 to
c6da1e4
Compare
| * If the property is computed, we have no idea if a rename is useless or not. | ||
| */ | ||
| if (properties[i].computed || !properties[i].key) { | ||
| if (property.shorthand || property.type === "RestElement" || property.computed) { |
There was a problem hiding this comment.
Looks like there are already tests covering the property.type === "RestElement" change on this line.
| if (properties[i].key.type === "Identifier" && properties[i].key.name === properties[i].value.name || | ||
| properties[i].key.type === "Literal" && properties[i].key.value === properties[i].value.name) { | ||
| reportError(properties[i], properties[i].key, properties[i].value, "Destructuring assignment"); | ||
| const key = (property.key.type === "Identifier" && property.key.name) || (property.key.type === "Literal" && property.key.value); |
There was a problem hiding this comment.
Some change here seems to break!
Failing line: https://github.com/nuxt/nuxt.js/blob/13331a02b4d5ef37932f42a845ca1754fb834243/packages/webpack/src/builder.js#L169
(just informational! I'll try to reproduce it better and make PR or Issue)
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[x] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
fixes #12301
What changes did you make? (Give an overview)
This updates
no-useless-renameto check destructured assignments with default values. I think this should be considered a semver-minor bug fix, since it feels like an oversight that this rule doesn't already check this case.Is there anything you'd like reviewers to focus on?
Are reviewers in agreement that this should be default behavior and not behind an option?