Permalink
Browse files

Don't generate false positives on /* inside comments.

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 GH-540
Closes GH-599
  • Loading branch information...
1 parent 9ec3e3a commit 892cfdde9b4102bdedc81a75fc5f40fe0b5d79c8 @valueof valueof committed Aug 19, 2012
Showing with 26 additions and 7 deletions.
  1. +1 −5 jshint.js
  2. +20 −0 tests/unit/fixtures/gruntComment.js
  3. +5 −2 tests/unit/parser.js
View
@@ -788,7 +788,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_$]*)$/;
@@ -1429,10 +1429,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;
@@ -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}
+ * }
+ * }
+ *
+ */
View
@@ -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 () {

0 comments on commit 892cfdd

Please sign in to comment.