Skip to content

Commit

Permalink
Fix: no-unused-vars false positive (fixes #7250) (#7258)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea authored and nzakas committed Sep 30, 2016
1 parent 4448cec commit dffb4fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rules/no-unused-vars.js
Expand Up @@ -428,12 +428,12 @@ module.exports = {
return true;
}

// if all parameters preceded by this variable are ignored, this is the last.
// if all parameters preceded by this variable are ignored and unused, this is the last.
if (config.argsIgnorePattern) {
const params = context.getDeclaredVariables(def.node);
const posteriorParams = params.slice(params.indexOf(variable) + 1);

if (posteriorParams.every(v => config.argsIgnorePattern.test(v.name))) {
if (posteriorParams.every(v => v.references.length === 0 && config.argsIgnorePattern.test(v.name))) {
return true;
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/no-unused-vars.js
Expand Up @@ -225,6 +225,17 @@ ruleTester.run("no-unused-vars", rule, {
options: [{argsIgnorePattern: "d"}],
parserOptions: {ecmaVersion: 6}
},

// https://github.com/eslint/eslint/issues/7250
{
code: "(function(a, b, c) { c })",
options: [{argsIgnorePattern: "c"}],
},
{
code: "(function(a, b, {c, d}) { c })",
options: [{argsIgnorePattern: "[cd]"}],
parserOptions: {ecmaVersion: 6},
},
],
invalid: [
{ code: "function foox() { return foox(); }", errors: [{ message: "'foox' is defined but never used.", type: "Identifier"}] },
Expand Down

0 comments on commit dffb4fa

Please sign in to comment.