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

戏子无情 提交于 2019-12-23 07:15:38

问题


I am using jslint to validate my code.
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?

Thanks


回答1:


According to Crockford's post, you'll want to wrap everything in a function...

(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




回答2:


Cannot be done without changing the javascript file which drives jslint.

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. The latest jslint is now more advanced than jshint, spotting more weaknesses and copes with more complicated code. I like jshint but it isn't keeping up with jslint.




回答3:


The solution I found for this was to create a single line file with "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

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




回答4:


Here is a hack to suppress "Use the function form of 'use strict'."

    $ uname -a
    Darwin 13.0.0 Darwin Kernel Version 13.0.0
  1. Figure out where your jslint distribution is.

    $ 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.

    sudo find / -name jslint.js
    


来源:https://stackoverflow.com/questions/8953654/disable-use-the-function-form-of-use-strict-but-keep-the-missing-use-strict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!