Skip to content

Commit

Permalink
support array destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed Jun 9, 2019
1 parent 262016a commit 69beb3e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/rules/no-unused-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ module.exports = ruleComposer.mapReports(
fixer.remove(parent),
fixer.remove(sourceCode.getTokenAfter(parent, commaFilter))
];
case "ArrayPattern":
return fixer.remove(node);
default:
return null;
}
Expand Down
20 changes: 19 additions & 1 deletion tests/lib/rules/no-unused-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,30 @@ ruleTester.run("no-unused-vars", rule, {
output: null,
errors: [{ type: "Identifier" }]
},
{
code: "var [a] = c",
output: "var [] = c",
parserOptions: { ecmaVersion: 6 },
errors: [{ type: "Identifier" }]
},
{
code: "var [a, b] = c",
output: null,
output: "var [, ] = c",
parserOptions: { ecmaVersion: 6 },
errors: [{ type: "Identifier" }, { type: "Identifier" }]
},
{
code: "var [a, b] = c; a;",
output: "var [a, ] = c; a;",
parserOptions: { ecmaVersion: 6 },
errors: [{ type: "Identifier" }]
},
{
code: "var [a, b] = c; b;",
output: "var [, b] = c; b;",
parserOptions: { ecmaVersion: 6 },
errors: [{ type: "Identifier" }]
},
{
code: "var a = b, c = d; c;",
output: "var c = d; c;",
Expand Down

0 comments on commit 69beb3e

Please sign in to comment.