繁体   English   中英

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

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

我正在使用jslint来验证我的代码。
我的所有页面都有“严格使用”。
如何禁用消息“使用'use strict'的函数形式”但保留“Missing'use strict'statement”警告,所以我不会忘记把它放在新文件上?

谢谢

根据Crockford的帖子 ,你会想要将所有内容都包含在一个函数中......

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

您也可以使用jshint代替,它具有“ globalstrict ”选项,可以完全满足您的要求而无需将所有内容都包装在函数中

如果不更改驱动jslint的javascript文件就无法完成。

对我来说,功能形式是一种胡思乱想的工作实践,因此不能强迫别人。

不是每个人都需要结合和缩小,但即使我这样做,我也会组合应用相同规则的代码,因此文件声明就足够了。

虽然jshint具有您需要的功能。 最新的jslint现在比jshint更先进,发现更多的弱点并应对更复杂的代码。 我喜欢jshint,但它跟不上jslint。

我找到的解决方案是用“use strict”创建一个单行文件; 没有别的

将它作为连接包中的第一个文件,将其添加到jslint的排除列表中,切换sloppy = true pragma

可能会有一些副作用,但没有采取草率的代码,但我对文档的理解是,它只是检查“使用严格”; 线

这是一个黑客压制“使用'use strict'的函数形式。”

    $ uname -a
    Darwin 13.0.0 Darwin Kernel Version 13.0.0
  1. 找出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. 注释掉警告。

     $ 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. 如果它不起作用,您可能安装了多个版本的jslint,并且没有编辑正确的版本。

     sudo find / -name jslint.js 

暂无
暂无

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

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