问题
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
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
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.
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