Repository: jshint/jshint (js)

Issue:
Unused arrow-function parameters not ignored by "unused": "vars"
Setting `"unused": "vars"` disables all warnings concerning unused normal function parameters. However the new arrow functions don't seem to be supported by this option:

    on().then( thing => console.log( 'done' ) );

    'thing' is defined but never used.

I feel these should behave the same as normal function parameters when it comes to raising warnings.

Pull request:
[[FIX]] Ignore unused arrow-function parameters if unused: vars
Fixes #2345

Patch:
diff --git a/src/jshint.js b/src/jshint.js
index a40e8a4a..30057a94 100644
--- a/src/jshint.js
+++ b/src/jshint.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;


Test patch:
diff --git a/tests/unit/fixtures/unused.js b/tests/unit/fixtures/unused.js
index 3bf8f80e..d83a71cb 100644
--- a/tests/unit/fixtures/unused.js
+++ b/tests/unit/fixtures/unused.js
@@ -61,4 +61,11 @@ let letUsed = "this is used";
 if (letUsed) {
     let letUsed = "unused",
         anotherUnused;
-}
\ No newline at end of file
+}
+
+// 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;
\ No newline at end of file
diff --git a/tests/unit/options.js b/tests/unit/options.js
index a7960d2e..1def7df1 100644
--- a/tests/unit/options.js
+++ b/tests/unit/options.js
@@ -652,7 +652,10 @@ 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 = [
@@ -660,7 +663,8 @@ 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."],
+    [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();
 };