Repository: jshint/jshint
Pull request #3153 (2017-07-01 18:34:42)

[[FIX]] Correct location reported for W043
In addition, do not emit the E029 error. Maintain the error code itself
to replace with W043 in a future release.

This is intended to resolve gh-3152.

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

Coverage remained the same at 97.763% when pulling **7dbae3d4b185fab059ea2f8fc5b9a5a4fef0f55a on jugglinmike:3152-w043-location** into **d3d84ae1695359aef077ddb143f4be98001343b4 on jshint:master**.


Patch:
diff --git a/src/lex.js b/src/lex.js
index 573092b5..c9c6052c 100644
--- a/src/lex.js
+++ b/src/lex.js
@@ -1203,7 +1203,7 @@ Lexer.prototype = {
 
         if (!allowNewLine) {
           // This condition unequivocally describes a syntax error.
-          // TODO: Re-factor as an "error" (not a "warning").
+          // TODO: Emit error E029 and remove W112.
           this.trigger("warning", {
             code: "W112",
             line: this.line,
@@ -1232,12 +1232,6 @@ Lexer.prototype = {
         // error and implicitly close it at the EOF point.
 
         if (!this.nextLine(checks)) {
-          this.trigger("error", {
-            code: "E029",
-            line: startLine,
-            character: startChar
-          });
-
           return {
             type: Token.StringLiteral,
             value: value,
@@ -1278,8 +1272,14 @@ Lexer.prototype = {
           allowNewLine = parsed.allowNewLine;
         }
 
-        value += char;
-        this.skip(jump);
+        // If char is the empty string, end of the line has been reached. In
+        // this case, `this.char` should not be incremented so that warnings
+        // and errors reported in the subsequent loop iteration have the
+        // correct character column offset.
+        if (char !== "") {
+          value += char;
+          this.skip(jump);
+        }
       }
     }
 


Test patch:
diff --git a/tests/unit/options.js b/tests/unit/options.js
index 129460af..08df11a8 100644
--- a/tests/unit/options.js
+++ b/tests/unit/options.js
@@ -2066,21 +2066,21 @@ exports.strings = function (test) {
   var src = fs.readFileSync(__dirname + '/fixtures/strings.js', 'utf8');
 
   TestRun(test)
-    .addError(9, "Unclosed string.")
-    .addError(10, "Unclosed string.")
-    .addError(15, "Unclosed string.")
+    .addError(9, "Unclosed string.", {character: 20})
+    .addError(10, "Unclosed string.", {character: 1})
+    .addError(15, "Unclosed string.", {character: 1})
     .addError(25, "Octal literals are not allowed in strict mode.")
     .test(src, { es3: true, multistr: true });
 
   TestRun(test)
-    .addError(3, "Bad escaping of EOL. Use option multistr if needed.")
-    .addError(4, "Bad escaping of EOL. Use option multistr if needed.")
-    .addError(9, "Unclosed string.")
-    .addError(10, "Unclosed string.")
-    .addError(14, "Bad escaping of EOL. Use option multistr if needed.")
-    .addError(15, "Unclosed string.")
+    .addError(3, "Bad escaping of EOL. Use option multistr if needed.", {character: 21})
+    .addError(4, "Bad escaping of EOL. Use option multistr if needed.", {character: 2})
+    .addError(9, "Unclosed string.", {character: 20})
+    .addError(10, "Unclosed string.", {character: 1})
+    .addError(14, "Bad escaping of EOL. Use option multistr if needed.", {character: 21})
+    .addError(15, "Unclosed string.", {character: 1})
     .addError(25, "Octal literals are not allowed in strict mode.")
-    .addError(29, "Bad escaping of EOL. Use option multistr if needed.")
+    .addError(29, "Bad escaping of EOL. Use option multistr if needed.", {character: 36})
     .test(src, { es3: true });
 
   test.done();
diff --git a/tests/unit/parser.js b/tests/unit/parser.js
index 3b3a7a9b..84ad4d79 100644
--- a/tests/unit/parser.js
+++ b/tests/unit/parser.js
@@ -697,7 +697,7 @@ exports.strings = function (test) {
   var run = TestRun(test)
     .addError(1, "Control character in string: <non-printable>.", {character: 10})
     .addError(1, "This character may get silently deleted by one or more browsers.")
-    .addError(7, "Unclosed string.")
+    .addError(7, "Unclosed string.", {character: 12})
     .addError(7, "Missing semicolon.");
   run.test(code, {es3: true});
   run.test(code, {}); // es5