Skip to content

Commit

Permalink
Don't generate false positives on /* inside comments.
Browse files Browse the repository at this point in the history
JSHint used to attempt to detect nested multiline comments but
that generated too many false positives:

    /**
     * To use bla.js provide path: bla("./*");
     */

In addition to that, nested multiline comments will error early
no matter what so there is no need for JSHint to warn about them:

    /*
     * /* Nested comment */
     */

So I just removed that check.

References:

Closes jshintGH-540
Closes jshintGH-599
  • Loading branch information
valueof authored and jugglinmike committed Oct 21, 2014
1 parent 54f17e9 commit 49d3089
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
6 changes: 1 addition & 5 deletions jshint.js
Expand Up @@ -785,7 +785,7 @@ var JSHINT = (function () {
nxg = /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;

// star slash
lx = /\*\/|\/\*/;
lx = /\*\//;

// identifier
ix = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/;
Expand Down Expand Up @@ -1426,10 +1426,6 @@ unclosedString: for (;;) {
errorAt("Unclosed comment.", line, character);
}
}
character += i + 2;
if (s.substr(i, 1) === "/") {
errorAt("Nested comment.", line, character);
}
s = s.substr(i + 2);
token.comment = true;
break;
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/fixtures/gruntComment.js
@@ -0,0 +1,20 @@
/**
* Grunt Task File
* ---------------
*
* Task: logless
* Description: Parses JavaScript files and removes logging statements
*
* Usage:
*
* logless: {
* task: {
* src: ['file1.js', 'file2.js', 'other/stuff/*.js'],
* dest: 'path/to/destination',
* names: ['console', 'alert'],
* strip: 'path/to/remove',
* options: {beautify: true}
* }
* }
*
*/
7 changes: 5 additions & 2 deletions tests/unit/parser.js
Expand Up @@ -192,10 +192,13 @@ exports.comments = function () {
];

TestRun()
.addError(2, "Nested comment.")
.addError(2, "Unbegun comment.")
.addError(3, "Unbegun comment.")
.addError(4, "Unclosed comment.")
.test(code);

var src = "/* this is a comment /* with nested slash-start */";
TestRun().test(src);
TestRun().test(fs.readFileSync(__dirname + "/fixtures/gruntComment.js", "utf8"));
};

exports.regexp = function () {
Expand Down

0 comments on commit 49d3089

Please sign in to comment.