我应该担心HTML5Shiv.min.js版本3.7.2上的这些JSLint警告吗? [英] Should I worry about these JSLint warnings on HTML5Shiv.min.js version 3.7.2?

查看:131
本文介绍了我应该担心HTML5Shiv.min.js版本3.7.2上的这些JSLint警告吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从

I copied a version of HTML5Shiv.min.js from this Cloudflare link, and when I import the file into Adobe Brackets, the JSLint compiler tells me that the script contains the following errors:

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不是最新的,或者有什么问题,但是如果可能的话,我想对此发表第二意见.

Is this really going to work if I decide to use it? Code with missing statements and unreachable operators. Maybe JSLint is not up to date or something is off, but I would like to get a second opinion on this if possible.

谢谢.

推荐答案

别出汗.您可以使用该库.唯一的缺失"是指行是"use strict";,这是JSLint喜欢的,但是您不需要使用它. (这是对use strict 的恰当讨论.)

Don't sweat it. You're fine to use the library. The only "missing" line is "use strict";, which is something JSLint likes, but you're not required to use it. (Here's a decent discussion of use strict.)

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

JSLint and other linters look for two types of "errors": functional and style. Many of the style errors that JSLint finds will actually translate to logical errors you want to avoid. It's a great tool.

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

At the same time, you can make style errors that JSLint doesn't like without breaking your code's function, especially in minified code. Don't worry when you see JSLint identifying style errors in third-party code -- or anyone's minified code. They're not necessarily functional issues.

通常,您应免除第三者图书馆的棉绒.除非您想分叉它们并自己对它们进行皮棉编织,否则您对外部库无能为力,这真是太疯狂了. ; ^)而且,缩小代码经常采用不易掉毛的快捷方式.在精简代码以保持高质量之前,请先清除您的代码,但不要担心无论如何都不应该接触QAing库.假设他们还有另一种确保高质量的方法,其中可能包括使用不同的短绒,或使用具有不同规则集的短绒.

As a rule, you should exempt 3rd party libraries from your linting. There's nothing you can do about external libraries unless you want to fork them and lint them yourself, which is, well, insane. ;^) And, again, minified code often takes shortcuts that aren't lint-friendly. Lint your code before you minify to keep its quality high, but don't worry about QAing libraries you shouldn't be touching anyhow. Assume they have another method for ensuring high quality, which might include using a different linter, or a linter with a different set of rules.

这是一个脏"的东西.秘密...

And here's a "dirty" secret...

jQuery,甚至是 un 最小化的,例如,也不会掉毛.即使我添加一行命令告诉JSLint放弃空白错误",缺少使用严格",并让它知道它应该使用浏览器,我也会...

jQuery, even unminified, doesn't lint either, for instance. Even if I add a line to tell JSLint to lay off of the whitespace "error", missing "use strict", and let it know it should assume a browser, I get...

'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或任何其他文件是否会给您带来相同的错误.

etc etc etc. And nobody is going to argue that jQuery is bogus, you know? So don't worry if Cloudfire or any other file gives you the same set of errors.

最重要的是:不要因皮绒而对你大吼大叫,尤其是对小型图书馆.短绒是用于您的代码的代码质量工具.如果其他人还有其他方法可以保持其代码正常运行,并且可以很好地测试您的使用情况,请不要使用lib. ; ^)

Bottom line: Don't sweat lint yelling at you about libraries, especially minified ones. Linters are code quality tools for your code. If others have other means of keeping their code working and it tests well for your uses, leave the lib alone. ;^)

这篇关于我应该担心HTML5Shiv.min.js版本3.7.2上的这些JSLint警告吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆