diff --git a/src/lex.js b/src/lex.js index 886e6f2f0c..af3e87cd69 100644 --- a/src/lex.js +++ b/src/lex.js @@ -435,6 +435,17 @@ Lexer.prototype = { body = body.substr(str.length + 1); } + // To handle rarer case when special word is separated from label by + // multiple spaces or tabs + var strIndex = body.indexOf(str); + if (!isSpecial && strIndex >= 0 && body.charAt(strIndex + str.length) === " ") { + var isAllWhitespace = body.substr(0, strIndex).trim().length === 0; + if (isAllWhitespace) { + isSpecial = true; + body = body.substr(str.length + strIndex); + } + } + if (!isSpecial) { return; } diff --git a/tests/unit/fixtures/inline-tabs-spaces.js b/tests/unit/fixtures/inline-tabs-spaces.js new file mode 100644 index 0000000000..c2f2f5dbb3 --- /dev/null +++ b/tests/unit/fixtures/inline-tabs-spaces.js @@ -0,0 +1,18 @@ +function a() { + // jshint unused: true + var x; +} + +function b() { + /* jshint + unused: true + */ + var y; +} + +function c() { + /* jshint + unused: true + */ + var z; +} diff --git a/tests/unit/parser.js b/tests/unit/parser.js index e4ee8832e1..8ff6b284ca 100644 --- a/tests/unit/parser.js +++ b/tests/unit/parser.js @@ -377,6 +377,18 @@ exports["jshint option comments multi line/option, leading and trailing space"] test.done(); }; +exports["jshint option inline comments, leading and trailing tabs and spaces"] = function (test) { + var src = fs.readFileSync(__dirname + "/fixtures/inline-tabs-spaces.js", "utf8"); + + TestRun(test) + .addError(3, 9, "'x' is defined but never used.") + .addError(10, 9, "'y' is defined but never used.") + .addError(17, 9, "'z' is defined but never used.") + .test(src); + + test.done(); +}; + exports.shebang = function (test) { var code = [ "#!test",