Skip to content

Commit

Permalink
Fix: no-unused-vars crash with spread operator (fixes #48)
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Jul 9, 2019
1 parent f6daa04 commit df7892e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rules/no-unused-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ module.exports = ruleComposer.mapReports(
return fixer.remove(parent);
case "RestElement":
case "Property":
if (!grand) {

// https://github.com/aladdin-add/eslint-plugin-autofix/issues/48
if (!(grand && grand.type === "ObjectPattern")) {
return null;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/no-unused-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ ruleTester.run("no-unused-vars", rule, {
parserOptions: { ecmaVersion: 2018 },
errors: [{ type: "Identifier" }]
},
{
code: "function foo(...args){}",
output: null,
parserOptions: { ecmaVersion: 2018 },
errors: [{ type: "Identifier" }, { type: "Identifier" }]
},
{
code: "let {a} = b",
output: "let {} = b",
Expand Down

0 comments on commit df7892e

Please sign in to comment.