简体   繁体   English

禁用“使用use strict的函数形式”但保留“Missing'use strict'statement”警告

[英]Disable “use the function form of use strict” but keep the “Missing 'use strict' statement” warning

I am using jslint to validate my code. 我正在使用jslint来验证我的代码。
I have "use strict" on all my pages. 我的所有页面都有“严格使用”。
How can I disable the message "use the function form of 'use strict'" but keep the "Missing 'use strict' statement" warning, so I won't forget to put it on new files? 如何禁用消息“使用'use strict'的函数形式”但保留“Missing'use strict'statement”警告,所以我不会忘记把它放在新文件上?

Thanks 谢谢

According to Crockford's post , you'll want to wrap everything in a function... 根据Crockford的帖子 ,你会想要将所有内容都包含在一个函数中......

(function () {
    "use strict";
    // the rest of your file goes here...
}());

You could also use jshint instead, which has a " globalstrict " option that can do exactly what you're asking for without having to wrap everything in a function 您也可以使用jshint代替,它具有“ globalstrict ”选项,可以完全满足您的要求而无需将所有内容都包装在函数中

Cannot be done without changing the javascript file which drives jslint. 如果不更改驱动jslint的javascript文件就无法完成。

To me function form is a cranky working practice, therefore cannot force on others. 对我来说,功能形式是一种胡思乱想的工作实践,因此不能强迫别人。

Not everybody needs to combine and minify, but even if I did I'd combine code that applied the same rules, thus a file statement would be sufficient. 不是每个人都需要结合和缩小,但即使我这样做,我也会组合应用相同规则的代码,因此文件声明就足够了。

Although jshint has exactly the feature you require. 虽然jshint具有您需要的功能。 The latest jslint is now more advanced than jshint, spotting more weaknesses and copes with more complicated code. 最新的jslint现在比jshint更先进,发现更多的弱点并应对更复杂的代码。 I like jshint but it isn't keeping up with jslint. 我喜欢jshint,但它跟不上jslint。

The solution I found for this was to create a single line file with "use strict"; 我找到的解决方案是用“use strict”创建一个单行文件; and nothing else 没有别的

Make that the first file in your concatenation package, add it to jslint's exclude list, switch the sloppy=true pragma 将它作为连接包中的第一个文件,将其添加到jslint的排除列表中,切换sloppy = true pragma

There may be some side effects around not picking up sloppy code, but my understanding of the docs is that it just checks for the "use strict"; 可能会有一些副作用,但没有采取草率的代码,但我对文档的理解是,它只是检查“使用严格”; line 线

Here is a hack to suppress "Use the function form of 'use strict'." 这是一个黑客压制“使用'use strict'的函数形式。”

    $ uname -a
    Darwin 13.0.0 Darwin Kernel Version 13.0.0
  1. Figure out where your jslint distribution is. 找出jslint分布的位置。

     $ which jslint /usr/local/bin/jslint $ ls -l /usr/local/bin/jslint lrwxr-xr-x 1 root admin 40 11 Feb 2013 /usr/local/bin/jslint -> ../lib/node_modules/jslint/bin/jslint.js $ cd /usr/local/lib/node_modules/jslint/ $ ls LICENSE README.md lib package.json Makefile bin node_modules 
  2. Comment out the warning. 注释掉警告。

     $ sudo vim lib/jslint.js search for 'function_strict' comment out the line 'warn('function_strict');' note: the exact line might vary on some versions but just comment it out. 
  3. If it does not work you probably have multiple versions of jslint installed and have not edited the right one. 如果它不起作用,您可能安装了多个版本的jslint,并且没有编辑正确的版本。

     sudo find / -name jslint.js 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM