Permalink
Browse files

[[FIX]] Ignore unused arrow-function parameters if unused: vars

Fixes #2345
  • Loading branch information...
nicolo-ribaudo committed May 12, 2015
1 parent a093f78 commit 2ea9cb0f636cf005d48e53cc69b29175818f4ddf
Showing with 17 additions and 5 deletions.
  1. +1 −1 src/jshint.js
  2. +8 −1 tests/unit/fixtures/unused.js
  3. +8 −3 tests/unit/options.js
@@ -2880,7 +2880,7 @@ var JSHINT = (function() {

if (loneArg && loneArg.identifier === true) {
addlabel(loneArg.value, { type: "unused", token: loneArg });
return [loneArg];
return [loneArg.value];
}

next = state.tokens.next;
@@ -61,4 +61,11 @@ let letUsed = "this is used";
if (letUsed) {
let letUsed = "unused",
anotherUnused;
}
}

// GH-2345 - Unused arrow-function parameters should be ignored if "unused" is set to "vars"
let x = y => y;
x = y => {};
x = (y) => {};
x = (y, z) => y;
x = (y, z) => z;
@@ -652,15 +652,19 @@ exports.unused = function (test) {
[22, "'i' is defined but never used."],
[28, "'a' is defined but never used."],
[28, "'b' is defined but never used."],
[28, "'c' is defined but never used."]
[28, "'c' is defined but never used."],
[68, "'y' is defined but never used."],
[69, "'y' is defined but never used."],
[70, "'z' is defined but never used."]
];

var all_param_errors = [
[15, "'err' is defined but never used."],
[22, "'i' is defined but never used."],
[28, "'a' is defined but never used."],
[28, "'b' is defined but never used."],
[28, "'c' is defined but never used."]
[28, "'c' is defined but never used."],
[71, "'y' is defined but never used."]
];

var true_run = TestRun(test, {esnext: true});
@@ -686,11 +690,12 @@ exports.unused = function (test) {
vars_run.test(src, { esnext: true, unused: "vars"});

var unused = JSHINT.data().unused;
test.equal(15, unused.length);
test.equal(19, unused.length);
test.ok(unused.some(function (err) { return err.line === 1 && err.character == 5 && err.name === "a"; }));
test.ok(unused.some(function (err) { return err.line === 6 && err.character == 18 && err.name === "f"; }));
test.ok(unused.some(function (err) { return err.line === 7 && err.character == 9 && err.name === "c"; }));
test.ok(unused.some(function (err) { return err.line === 15 && err.character == 10 && err.name === "foo"; }));
test.ok(unused.some(function (err) { return err.line === 68 && err.character == 5 && err.name === "y"; }));

test.done();
};

0 comments on commit 2ea9cb0

Please sign in to comment.