Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grunt-contrib-jshint doesn't complain about console.log

Tags:

gruntjs

jshint

With the following setting the jsHint doesn't complain about console.log statements while it still reports debugger statements:

jshint: {
      files: [
        'Gruntfile.js',
        'js/**/*.js',
        'tests/*.js',
      ],
      options: {
        curly: true,
        immed: true,
        noarg: true,
        expr: true,
        quotmark: 'single',
        maxdepth: 3,
        browser: true,
        eqnull: true
      }
    },
like image 739
Andreas Köberle Avatar asked May 02 '13 11:05

Andreas Köberle


2 Answers

As far as I can tell, JSHint has never warned about references to console. There is no code in there to specifically handle such references.

console is simply treated as an identifier that should be defined and accessible from whatever context it is referred to from (which is correct, since that is really all it is).

Therefore, you can get JSHint to warn about usage of console by getting it to warn about all undefined variables. Just set the undef option to true.

Then, if you want to allow the usage of console, you can add it to your globals directive or set the devel option to true (which implicitly adds it to your globals directive).

like image 84
James Allardice Avatar answered Sep 28 '22 05:09

James Allardice


I also had this problem.

I had "undef" set to true and still it didn't work.

I tried "devel" to no avail.

Finally - I simply use the "globals" variable like so:

"globals" : { 
         "console": true
}

and that did the trick.

like image 39
guy mograbi Avatar answered Sep 28 '22 04:09

guy mograbi