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: no-useless-rename handles ExperimentalRestProperty (fixes #6284) #6288

Merged
merged 4 commits into from
Jun 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/rules/no-useless-rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ module.exports = {
return;
}

if (properties[i].computed) {
/**
* If an ObjectPattern property is computed, we have no idea
* if a rename is useless or not. If an ObjectPattern property
* lacks a key, it is likely an ExperimentalRestProperty and
* so there is no "renaming" occurring here.
*/
if (properties[i].computed || !properties[i].key) {
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocker: I think a comment here about why this guard is needed could be helpful for future contributors

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add that tomorrow. Thanks! Apologies for missing that.

return;
}

Expand Down
48 changes: 48 additions & 0 deletions tests/lib/rules/no-useless-rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ ruleTester.run("no-useless-rename", rule, {
{ code: "export {foo as bar, baz as qux};", parserOptions: { ecmaVersion: 6, sourceType: "module" } },
{ code: "export {foo as bar} from 'foo';", parserOptions: { ecmaVersion: 6, sourceType: "module" } },
{ code: "export {foo as bar, baz as qux} from 'foo';", parserOptions: { ecmaVersion: 6, sourceType: "module" } },
{
code: "const {...stuff} = myObject;",
parserOptions: {
ecmaFeatures: { experimentalObjectRestSpread: true },
ecmaVersion: 6
}
},
{
code: "const {foo, ...stuff} = myObject;",
parserOptions: {
ecmaFeatures: { experimentalObjectRestSpread: true },
ecmaVersion: 6
}
},
{
code: "const {foo: bar, ...stuff} = myObject;",
parserOptions: {
ecmaFeatures: { experimentalObjectRestSpread: true },
ecmaVersion: 6
}
},

// { ignoreDestructuring: true }
{
Expand Down Expand Up @@ -238,6 +259,33 @@ ruleTester.run("no-useless-rename", rule, {
parserOptions: { ecmaVersion: 6 },
errors: ["Destructuring assignment foo unnecessarily renamed.", "Destructuring assignment bar unnecessarily renamed."]
},
{
code: "const {foo: foo, ...stuff} = myObject;",
output: "const {foo, ...stuff} = myObject;",
parserOptions: {
Copy link
Member

Choose a reason for hiding this comment

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

We should check the fixed output here as well - check the other invalid tests for the output key to see what this looks like

Copy link
Member Author

Choose a reason for hiding this comment

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

My bad, I didn't realize the rule was fixable. I will add that in a few
hours, when I get back home. Thanks!
On May 30, 2016 3:34 PM, "Kai Cataldo" notifications@github.com wrote:

In tests/lib/rules/no-useless-rename.js
#6288 (comment):

@@ -239,6 +260,30 @@ ruleTester.run("no-useless-rename", rule, {
errors: ["Destructuring assignment foo unnecessarily renamed.", "Destructuring assignment bar unnecessarily renamed."]
},
{

  •        code: "const {foo: foo, ...stuff} = myObject;",
    
  •        parserOptions: {
    

We should check the fixed output here as well - check the other invalid
tests for the output key to see what this looks like


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/eslint/eslint/pull/6288/files/80d4c3c664cd314b393a4b31e2878a704683645a#r65104582,
or mute the thread
https://github.com/notifications/unsubscribe/AARWeoNObAlcbU4o3J-4iSuxw4-CESFLks5qG0m3gaJpZM4Ip_rq
.

ecmaFeatures: { experimentalObjectRestSpread: true },
ecmaVersion: 6
},
errors: ["Destructuring assignment foo unnecessarily renamed."]
},
{
code: "const {foo: foo, bar: baz, ...stuff} = myObject;",
output: "const {foo, bar: baz, ...stuff} = myObject;",
parserOptions: {
ecmaFeatures: { experimentalObjectRestSpread: true },
ecmaVersion: 6
},
errors: ["Destructuring assignment foo unnecessarily renamed."]
},
{
code: "const {foo: foo, bar: bar, ...stuff} = myObject;",
output: "const {foo, bar, ...stuff} = myObject;",
parserOptions: {
ecmaFeatures: { experimentalObjectRestSpread: true },
ecmaVersion: 6
},
errors: ["Destructuring assignment foo unnecessarily renamed.", "Destructuring assignment bar unnecessarily renamed."]
},
{
code: "import {foo as foo} from 'foo';",
output: "import {foo} from 'foo';",
Expand Down