最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Disable "use the function form of use strict" but keep the "Missing 'use strict&

programmeradmin1浏览0评论

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

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

Share Improve this question asked Jan 21, 2012 at 14:17 Randall FlaggRandall Flagg 5,1089 gold badges36 silver badges46 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 14

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

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.

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

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
    

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论