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

Should I worry about these JSLint warnings on HTML5Shiv.min.js version 3.7.2?

本文关键字:JSLint 警告 版本 min HTML5Shiv 担心 js 我应该      更新时间:2023-09-26

我从这个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 不是最新的或有些东西不对劲,但如果可能的话,我想得到第二意见。

谢谢。

不要出汗。您可以使用该库。唯一"缺失"的行是 "use strict"; ,这是 JSLint 喜欢的,但你不需要使用它。(这是对use strict的体面讨论。

JSLint 和其他 linter 寻找两种类型的"错误":功能和样式。JSLint 发现的许多样式错误实际上会转化为您想要避免的逻辑错误。这是一个很棒的工具。

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

通常,您应该从 linting 中免除第三方库。对于外部库,你无能为力,除非你想自己分叉它们并检查它们,这太疯狂了。;^)而且,同样,缩小的代码通常采用对 lint 不友好的快捷方式。在缩小之前检查您的代码以保持其高质量,但不要担心您无论如何都不应该接触的 QAing 库。假设他们有另一种确保高质量的方法,其中可能包括使用不同的 linter 或具有不同规则集的 linter。

这是一个"肮脏"的秘密...

jQuery borks JSLint too...

例如,jQuery,即使是缩小的,也不会lint。即使我添加一行来告诉 JSLint 删除空格"错误",缺少"使用严格",并让它知道它应该假设浏览器,我得到......

'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或任何其他文件给您相同的错误集,请不要担心。

一句话:不要对图书馆大喊大叫,尤其是缩小的图书馆。棉绒是代码的代码质量工具。如果其他人有其他方法来保持他们的代码工作,并且它测试得很好,适合您的使用,请不要理会 lib。;^)