Skip to content

Commit

Permalink
Fix: no-useless-rename handles ExperimentalRestProperty (fixes #6284) (
Browse files Browse the repository at this point in the history
…#6288)

* Fix: no-useless-rename handles ExperimentalRestProperty (fixes #6284)

* Adding output to tests and changing approach

* Adding comment explaining the approach

* Removing unnecessary TODO.
  • Loading branch information
platinumazure authored and ilyavolodin committed Jun 1, 2016
1 parent fca0679 commit bb69380
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/rules/no-useless-rename.js
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) {
return;
}

Expand Down
48 changes: 48 additions & 0 deletions tests/lib/rules/no-useless-rename.js
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: {
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

0 comments on commit bb69380

Please sign in to comment.