我应该担心HTML5Shiv.min.js版本3.7.2上的这些JSLint警告吗?

时间:2015-03-21 00:48:53

标签: javascript jslint adobe-brackets html5shiv

我从此Cloudflare链接复制了HTML5Shiv.min.js版本,当我将文件导入Adobe Brackets时,JSLint编译器告诉我该脚本包含以下错误:

4   Missing 'use strict' statement.
    !function (a, b) {function c(a, b) {var c = a.createElement("p"), d = a.getElementsByTagName("head")[0] || a.documentElement; return c.innerHTML="x<style>"+b+"</style>",d.ins

4   'c' is already defined.
    !function (a, b) {function c(a, b) {var c = a.createElement("p"), d = a.getElementsByTagName("head")[0] || a.documentElement; return c.innerHTML="x<style>"+b+"</style>",d.ins

4   Expected ';' and instead saw '='.
    !function (a, b) {function c(a, b) {var c = a.createElement("p"), d = a.getElementsByTagName("head")[0] || a.documentElement; return c.innerHTML="x<style>"+b+"</style>",d.ins

4   Unreachable '=' after 'return'.
    !function (a, b) {function c(a, b) {var c = a.createElement("p"), d = a.getElementsByTagName("head")[0] || a.documentElement; return c.innerHTML="x<style>"+b+"</style>",d.ins

4   Expected an identifier and instead saw '='.
    !function (a, b) {function c(a, b) {var c = a.createElement("p"), d = a.getElementsByTagName("head")[0] || a.documentElement; return c.innerHTML="x<style>"+b+"</style>",d.ins

4   Stopping. (100% scanned).
    !function (a, b) {function c(a, b) {var c = a.createElement("p"), d = a.getElementsByTagName("head")[0] || a.documentElement; return c.innerHTML="x<style>"+b+"</style>",d.ins

如果我决定使用它,这真的会起作用吗?缺少语句和无法访问的运算符的代码。也许JSLint不是最新的或者有些东西是关闭的,但如果可能的话,我想就此发表第二意见。

谢谢。

1 个答案:

答案 0 :(得分:4)

不要出汗。您可以使用该库。唯一的&#34;失踪&#34; line是"use strict";,这是JSLint喜欢的,但您不需要使用它。 (Here's a decent discussion of use strict。)

JSLint和其他短信寻找两种类型的&#34;错误&#34;:功能风格。 JSLint发现的许多样式错误实际上都会转换为您想要避免的逻辑错误。这是一个很棒的工具。

同时,您可以在不破坏代码功能的情况下制作JSLint不喜欢的样式错误,尤其是在缩小代码中。当您看到JSLint在第三方代码中识别样式错误 - 或任何人的缩小代码时,请不要担心。他们不一定是功能问题。

作为一项规则,您应该免除第三方图书馆的损失。关于外部库你什么也做不了,除非你想把它们分叉并自己去掉它们,这是疯狂的。 ; ^)而且,缩小的代码通常采用不易于使用的快捷方式。在你最小化以保持其质量之前,请你的代码,但不要担心QAing库你无论如何都不应该触摸。假设他们有另一种确保高质量的方法,可能包括使用不同的linter,或者使用不同规则的linter。

这是一个&#34;脏&#34;秘密...

jQuery也是JSLint ...

例如,

jQuery, even unminified,也没有lint。即使我添加一行来告诉JSLint裁掉空白&#34;错误&#34;,丢失&#34;使用strict&#34;,让它知道它应该假定一个浏览器,我得到......

'module' was used before it was defined.
    if ( typeof module === "object" && typeof module.exports === "object" ) {
line 18 character 44'module' was used before it was defined.
    if ( typeof module === "object" && typeof module.exports === "object" ) {
line 26 character 3'module' was used before it was defined.
        module.exports = global.document ?
line 39 character 3Unexpected 'typeof'. Use '===' to compare directly with undefined.
}(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
line 49 character 5 Combine this with the previous 'var' statement.
    var slice = deletedIds.slice;
line 51 character 5 Combine this with the previous 'var' statement.
    var concat = deletedIds.concat;
line 53 character 5 Combine this with the previous 'var' statement.
    var push = deletedIds.push;
line 55 character 5 Combine this with the previous 'var' statement.
等等没有人会认为jQuery是假的,你知道吗?所以不要担心Cloudfire或任何其他文件会给你带来同样的错误。< / p>

结论:对于图书馆,尤其是缩小图书馆,不要对你大吼大叫。 Linters是 代码的代码质量工具。如果其他人有其他方法来保持他们的代码正常工作并且它可以很好地测试您的用途,那么请单独使用lib。 ; ^)