Fork me on GitHub

JSLint Error Explanations

JSLint will hurt your feelings. It's time to make them better!


Unclosed comment

什么时候会产生这个错误?

JSLint和JSHint在遇到多行注释没有用*/结尾,会抛出"Unclosed comment"的错误。以下是一个例子:

为什么会产生这个错误?

这个错误是为了强调一个JavaScript语法错误。ECMAScript5规范列出了以下关于多行注释的语法 (section §7.4):

MultiLineComment ::
    /* MultiLineCommentCharsopt */

我们可以从上述引用内容中中了解到多行注释必须以*/字符结尾。如果你有一个没有闭合的多行注释,那么解释器在到文件末端时就会抛出一个语法错误。以下仍是上述代码片段,但是这次我们将多行注释闭合了:

JSHint bug alert!

As you may have noticed if you have switched one of the example above to use JSHint instead of JSLint, a large number of the same error appear to get generated for the first unclosed comment, to the point where the parser gives up and tells you that there are too many errors. Fixed as of JSHint 1.0.0.

在JSHint1.0.0及以上版本中你可以通过特殊的语法来忽略任意警告。但是这个消息和严重的语法错误有关,所以你无法忽略之。


comments powered by Disqus