Skip to content

Commit

Permalink
Update: Omit setter param from no-unused-vars (fixes #2133)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Mar 24, 2015
1 parent 0653cf7 commit 5749bfe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/rules/no-unused-vars.js
Expand Up @@ -108,12 +108,20 @@ module.exports = function(context) {
if (scope.type === "function" && variables[i].name === "arguments" && variables[i].identifiers.length === 0) {
continue;
}
var type = variables[i].defs[0].type;

var def = variables[i].defs[0],
type = def.type;

// skip catch variables
if (type === "CatchClause") {
continue;
}

// skip any setter argument
if (type === "Parameter" && def.node.parent.type === "Property" && def.node.parent.kind === "set") {
continue;
}

// if "args" option is "none", skip any parameter
if (config.args === "none" && type === "Parameter") {
continue;
Expand Down
1 change: 1 addition & 0 deletions tests/lib/rules/no-unused-vars.js
Expand Up @@ -32,6 +32,7 @@ eslintTester.addRuleTest("lib/rules/no-unused-vars", {
"var foo = 5;\n\nwhile (true) {\n console.log(foo);\n break;\n}",
{ code: "for (let prop in box) {\n box[prop] = parseInt(box[prop]);\n}", ecmaFeatures: { blockBindings: true }},
"var box = {a: 2};\n for (var prop in box) {\n box[prop] = parseInt(box[prop]);\n}",
"f({ set foo(a) { return; } });",
{ code: "a; var a;", args: [1, "all"] },
{ code: "var a=10; alert(a);", args: [1, "all"] },
{ code: "var a=10; (function() { alert(a); })();", args: [1, "all"] },
Expand Down

0 comments on commit 5749bfe

Please sign in to comment.