Skip to content

Commit dffb4fa

Browse files
mysticateanzakas
authored andcommitted
Fix: no-unused-vars false positive (fixes #7250) (#7258)
1 parent 4448cec commit dffb4fa

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

lib/rules/no-unused-vars.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,12 @@ module.exports = {
428428
return true;
429429
}
430430

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

436-
if (posteriorParams.every(v => config.argsIgnorePattern.test(v.name))) {
436+
if (posteriorParams.every(v => v.references.length === 0 && config.argsIgnorePattern.test(v.name))) {
437437
return true;
438438
}
439439
}

tests/lib/rules/no-unused-vars.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,17 @@ ruleTester.run("no-unused-vars", rule, {
225225
options: [{argsIgnorePattern: "d"}],
226226
parserOptions: {ecmaVersion: 6}
227227
},
228+
229+
// https://github.com/eslint/eslint/issues/7250
230+
{
231+
code: "(function(a, b, c) { c })",
232+
options: [{argsIgnorePattern: "c"}],
233+
},
234+
{
235+
code: "(function(a, b, {c, d}) { c })",
236+
options: [{argsIgnorePattern: "[cd]"}],
237+
parserOptions: {ecmaVersion: 6},
238+
},
228239
],
229240
invalid: [
230241
{ code: "function foox() { return foox(); }", errors: [{ message: "'foox' is defined but never used.", type: "Identifier"}] },

0 commit comments

Comments
 (0)