簡體   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