jslint Unsafe character


用jslint进行语法检查,遇见如下错误:

../javascript/abcms/office/PackageWindow.js
    Line #: 1
    Char #: 0
    Reason: Unsafe character.


查找jslint源码:

function next_line() {
    ...
    at = source_row.search(cx); // source_row 为读取的一行文件代码,正则匹配
    if (at >= 0) {
        warn('unsafe', line, at);
    }
    ...
}


cx的定义:

// unsafe characters that are silently deleted by one or more browsers
        cx = /[\u0000-\u0008\u000a-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/,


这些转义字符,就不列举了,也就是说源文件包含了转义字符。

转义字符是怎么来的,就是文件格式原因。

What steps will reproduce the problem?
1. Add a UTF BOM character to the very start of a .js file that is going to be linted
2. Run the plugin

参考:http://code.google.com/p/jslint4java/issues/detail?id=85


查看文件的格式,果然是UTF BOM,查找资料feff正是BOM的编码。

Q: What is a BOM?
A: A byte order mark (BOM) consists of the character code U+FEFF at the beginning of a data stream, where it can be used as a signature defining the byte order and encoding form, primarily of unmarked plaintext files. Under some higher level protocols, use of a BOM may be mandatory (or prohibited) in the Unicode data stream defined in that protocol.

参考:http://unicode.org/faq/utf_bom.html


解决办法:把文件的格式批量设置为UTF WITHOUT BOM格式。






你可能感兴趣的:(JavaScript,jslint)