11

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

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

2 Comments

"If a file with a "use strict"; preamble has sloppy code appended to it, the sloppy code will be processed as strict and will probably fail." This is when you will want to put it in a function. Not all the time. All my code is strict, so no use for me.
Have you checked out jshint as I recommended instead?
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.

Comments

0

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

Comments

-2

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.