Repository: jshint/jshint
Pull request #3341 (2019-01-06 01:53:36)

Remove unused warnings
This should resolve gh-3340

coveralls: 
[![Coverage Status](https://coveralls.io/builds/20923715/badge)](https://coveralls.io/builds/20923715)

Coverage remained the same at 98.621% when pulling **2d66874277d2ec2d78f34a710ff8ea3a3fbb7248 on jugglinmike:remove-unused-warnings** into **26b9e530ecde736454f6401b109a6df6feaa5ec4 on jshint:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/20923715/badge)](https://coveralls.io/builds/20923715)

Coverage remained the same at 98.621% when pulling **2d66874277d2ec2d78f34a710ff8ea3a3fbb7248 on jugglinmike:remove-unused-warnings** into **26b9e530ecde736454f6401b109a6df6feaa5ec4 on jshint:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/20923715/badge)](https://coveralls.io/builds/20923715)

Coverage remained the same at 98.621% when pulling **2d66874277d2ec2d78f34a710ff8ea3a3fbb7248 on jugglinmike:remove-unused-warnings** into **26b9e530ecde736454f6401b109a6df6feaa5ec4 on jshint:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/20923715/badge)](https://coveralls.io/builds/20923715)

Coverage remained the same at 98.621% when pulling **2d66874277d2ec2d78f34a710ff8ea3a3fbb7248 on jugglinmike:remove-unused-warnings** into **26b9e530ecde736454f6401b109a6df6feaa5ec4 on jshint:master**.


Patch:
diff --git a/src/jshint.js b/src/jshint.js
index efd27671..1aff3aef 100644
--- a/src/jshint.js
+++ b/src/jshint.js
@@ -5331,8 +5331,6 @@ var JSHINT = (function() {
     combine(predefined, vars.ecmaIdentifiers[3]);
     combine(predefined, vars.reservedVars);
 
-    combine(predefined, g || {});
-
     declared = Object.create(null);
     var exported = Object.create(null); // Variables that live outside the current file
 
@@ -5347,18 +5345,21 @@ var JSHINT = (function() {
     }
 
     if (o) {
-      each(o.predef || null, function(item) {
-        var slice, prop;
-
-        if (item[0] === "-") {
-          slice = item.slice(1);
-          JSHINT.blacklist[slice] = slice;
-          // remove from predefined if there
-          delete predefined[slice];
-        } else {
-          prop = Object.getOwnPropertyDescriptor(o.predef, item);
-          predefined[item] = prop ? prop.value : false;
-        }
+
+      each([o.predef, o.globals], function(dict) {
+        each(dict, function(item) {
+          var slice, prop;
+
+          if (item[0] === "-") {
+            slice = item.slice(1);
+            JSHINT.blacklist[slice] = slice;
+            // remove from predefined if there
+            delete predefined[slice];
+          } else {
+            prop = Object.getOwnPropertyDescriptor(dict, item);
+            predefined[item] = prop ? prop.value : false;
+          }
+        });
       });
 
       each(o.exported || null, function(item) {
diff --git a/src/messages.js b/src/messages.js
index ba6dd6ff..c60db567 100644
--- a/src/messages.js
+++ b/src/messages.js
@@ -121,7 +121,7 @@ var warnings = {
   W036: "Unexpected /*member '{a}'.",
   W037: "'{a}' is a statement label.",
   W038: "'{a}' used out of scope.",
-  W039: "'{a}' is not allowed.",
+  W039: null,
   W040: "If a strict mode function is executed using function invocation, " +
     "its 'this' value will be undefined.",
   W041: null,
@@ -193,7 +193,7 @@ var warnings = {
   W102: null,
   W103: "The '{a}' property is deprecated.",
   W104: "'{a}' is available in ES{b} (use 'esversion: {b}') or Mozilla JS extensions (use moz).",
-  W105: "Unexpected {a} in '{b}'.",
+  W105: null,
   W106: "Identifier '{a}' is not in camel case.",
   W107: "Script URL.",
   W108: "Strings must use doublequote.",


Test patch:
diff --git a/tests/unit/core.js b/tests/unit/core.js
index 3effcb29..b6492c71 100644
--- a/tests/unit/core.js
+++ b/tests/unit/core.js
@@ -38,6 +38,33 @@ exports.testCustomGlobals = function (test) {
     .addError(3, 1, "Read only.")
     .test(code, { es3: true, unused: true, predef: { foo: false }});
 
+  JSHINT("x = null;", { undef: true, globals: { x: true } });
+
+  test.ok(!JSHINT.data().errors);
+
+  JSHINT("x = null;", { undef: true, globals: { x: false } });
+
+  test.equal(JSHINT.data().errors.length, 1);
+
+  JSHINT("parseInt('');", { undef: true, globals: { "-parseInt": true } });
+
+  test.equal(JSHINT.data().errors.length, 1);
+
+  JSHINT('x = null;', { undef: true, globals: { x: false } }, { x: true });
+
+  test.ok(
+    !JSHINT.data().errors,
+    "`predef` parameter takes precedence over `globals` option"
+  );
+
+  JSHINT("x = null;", { undef: true, globals: { x: true } }, { x: false });
+
+  test.equal(
+    JSHINT.data().errors.length,
+    1,
+    "`predef` parameter takes precedence over `globals` option"
+  );
+
   test.done();
 };