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

Randall Flagg
  • 4,834
  • 9
  • 33
  • 45

4 Answers4

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

Paul Armstrong
  • 7,008
  • 1
  • 22
  • 36
  • 2
    "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. – Randall Flagg Jan 28 '12 at 16:12
  • Have you checked out jshint as I recommended instead? – Paul Armstrong Jan 28 '12 at 17:50
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.

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

The Trav
  • 1,955
  • 3
  • 22
  • 30
-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
    
user847319
  • 23
  • 1
  • 2