Skip to content

Commit

Permalink
Update: no-unused-vars false negative about destructuring (fixes #8442)…
Browse files Browse the repository at this point in the history
… (#8459)

The rule should warn the variables which are in destructuring even if those exist in non-last parameters because those can always be removed.
  • Loading branch information
mysticatea authored and gyandeeps committed Apr 15, 2017
1 parent 741ed39 commit 9f540fd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-unused-vars.js
Expand Up @@ -513,7 +513,7 @@ module.exports = {
}

// if "args" option is "after-used", skip all but the last parameter
if (config.args === "after-used" && !isLastInNonIgnoredParameters(variable)) {
if (config.args === "after-used" && astUtils.isFunction(def.name.parent) && !isLastInNonIgnoredParameters(variable)) {
continue;
}
} else {
Expand Down
48 changes: 48 additions & 0 deletions tests/lib/rules/no-unused-vars.js
Expand Up @@ -609,6 +609,54 @@ ruleTester.run("no-unused-vars", rule, {
{
code: "/*global\rfoo*/",
errors: [{ message: "'foo' is defined but never used.", line: 2, column: 1 }]
},

// https://github.com/eslint/eslint/issues/8442
{
code: "(function ({ a }, b ) { return b; })();",
parserOptions: { ecmaVersion: 2015 },
errors: [
"'a' is defined but never used."
]
},
{
code: "(function ({ a }, { b, c } ) { return b; })();",
parserOptions: { ecmaVersion: 2015 },
errors: [
"'a' is defined but never used.",
"'c' is defined but never used."
]
},
{
code: "(function ({ a, b }, { c } ) { return b; })();",
parserOptions: { ecmaVersion: 2015 },
errors: [
"'a' is defined but never used.",
"'c' is defined but never used."
]
},
{
code: "(function ([ a ], b ) { return b; })();",
parserOptions: { ecmaVersion: 2015 },
errors: [
"'a' is defined but never used."
]
},
{
code: "(function ([ a ], [ b, c ] ) { return b; })();",
parserOptions: { ecmaVersion: 2015 },
errors: [
"'a' is defined but never used.",
"'c' is defined but never used."
]
},
{
code: "(function ([ a, b ], [ c ] ) { return b; })();",
parserOptions: { ecmaVersion: 2015 },
errors: [
"'a' is defined but never used.",
"'c' is defined but never used."
]
}
]
});

0 comments on commit 9f540fd

Please sign in to comment.