grunt-contrib-jshint icon indicating copy to clipboard operation
grunt-contrib-jshint copied to clipboard

"Ignore Warnings" not working

Open raijinsetsu opened this issue 9 years ago • 10 comments

I am attempting to get the plugin to report success even when JSHint reports particular warnings. For example: I want to warn the developer when they have defined a variable which is never used but I do not want that warning to prevent subsequent tasks from being run. I still want other warnings, such as "variable is undefined" to be treated as an error.

The documentation indicates that I can ignore a particular warning by specifying it in the options prefixed with a '-' and this seems to match what I want the plugin to do. However, this functionality does not appear to work. Here is the relevant part of my grunt config:

dev : {
    options : {
        jshintrc : '.jshintrc',
        '-W098':true
    },
    src : '<%= jshint.prod.src %>'
}

Note: W098 is the "is defined but never used" warning. The plugin reports the following:

Running "jshint:dev" (jshint) task

   public\js\classes\fileUpload.js
     15 |        minimizedStack = [],
                 ^ 'minimizedStack' is defined but never used.

>> 1 error in 1 file
Warning: Task "jshint:dev" failed. Use --force to continue.

Aborted due to warnings.

The default reporter does not seem to conditionalize incrementing the error count. In looking at the code, it would appear that these options would be passed to JSHint but only in the absence of the jshintrc option.

At the very least, the documentation is misleading and should indicate that you can only do this in the absence of the jshintrc option. The same should go for the "Specifying JSHint options and globals" section as none of the options would be passed to JSHint.

raijinsetsu avatar Sep 25 '14 17:09 raijinsetsu

I am seeing the same issue with the following config.

jshint: {
      options: {
        jshintrc: '<%= yeoman.client %>/.jshintrc',
        verbose: true
      },
      server: {
        options: {
          jshintrc: 'server/.jshintrc'
        },
        src: [ 'server/{,*/}*.js']
      },
      all: {
        options: {
          '-W106': true
        },
        src: [
          '<%= yeoman.client %>/{app,components}/**/*.js',
          '!<%= yeoman.client %>/{app,components}/**/*.spec.js',
          '!<%= yeoman.client %>/{app,components}/**/*.mock.js'
        ]
      },
      test: {
        src: [
          '<%= yeoman.client %>/{app,components}/**/*.spec.js',
          '<%= yeoman.client %>/{app,components}/**/*.mock.js'
        ]
      }
    }

whyvez avatar Oct 08 '14 21:10 whyvez

I created my own output formatter, which is actually what is detecting errors. It's based on the default one - it just does not count the errors I want it to treat as warnings. On Oct 27, 2014 4:22 PM, "Justin Schrader" [email protected] wrote:

Same problem - although there is an example in the docs: https://github.com/gruntjs/grunt-contrib-jshint#ignoring-specific-warnings I have mine setup the exact same way:

jshint: { ignore_warning: { options: { '-W116': true, '-W109': true, '-E007': true } } }

but I still see W116, W109, and E007 in the output. Any ideas?

— Reply to this email directly or view it on GitHub https://github.com/gruntjs/grunt-contrib-jshint/issues/177#issuecomment-60662427 .

raijinsetsu avatar Oct 27 '14 21:10 raijinsetsu

Attached is what I came up with. It's not extensible, but it gets the point across. When I have time, I plan on going back and making it extensible.

Here is what the relevant part of my config looks like:

    grunt.config.set('jshint', {
        options : {
            jshintrc : '.jshintrc',
            reporter : 'grunt/jshint-reporter.js'
        }        ,
        build : {
            // uses default JSHint options
            src : [
                '**/.jshintrc',
                'Gruntfile.js',
                'grunt/**/*.js'
            ]
        },

-Luke

On Mon, Oct 27, 2014 at 5:04 PM, Lucas Lacroix [email protected] wrote:

I created my own output formatter, which is actually what is detecting errors. It's based on the default one - it just does not count the errors I want it to treat as warnings. On Oct 27, 2014 4:22 PM, "Justin Schrader" [email protected] wrote:

Same problem - although there is an example in the docs: https://github.com/gruntjs/grunt-contrib-jshint#ignoring-specific-warnings I have mine setup the exact same way:

jshint: { ignore_warning: { options: { '-W116': true, '-W109': true, '-E007': true } } }

but I still see W116, W109, and E007 in the output. Any ideas?

— Reply to this email directly or view it on GitHub https://github.com/gruntjs/grunt-contrib-jshint/issues/177#issuecomment-60662427 .

raijinsetsu avatar Oct 27 '14 21:10 raijinsetsu

jshint: {
            options: {
                    '-W079': true,
            },
            all: ['Gruntfile.js', 'client/src/*.js'],
            dev: ['client/src/*.js']
        }

should fix it.

bhonnegowda avatar Jan 03 '15 12:01 bhonnegowda

Any updates on this?

marian-r avatar Sep 22 '15 16:09 marian-r

Just adding "'-W098':true" without changing anything else from the default Yeoman build worked great to get mine to ignore declared but never used errors. Thanks!

jaydge avatar Nov 23 '15 19:11 jaydge

The problem is when you combine the jshintrc file with additional options. The options do not take effect - only what is in the rc file.

On Mon, Nov 23, 2015 at 2:09 PM, JD Smith [email protected] wrote:

Just adding "'-W098':true" without changing anything else from the default Yeoman build worked great to get mine to ignore declared but never used errors. Thanks!

— Reply to this email directly or view it on GitHub https://github.com/gruntjs/grunt-contrib-jshint/issues/177#issuecomment-159030831 .

raijinsetsu avatar Nov 24 '15 00:11 raijinsetsu

It seems the usage doc needs to be updated. Right now it has this example:

grunt.initConfig({
  jshint: {
    ignore_warning: {
      options: {
        '-W015': true,
      },
      src: ['**/*.js'],
    },
  },
});

which doesn't work to ignore the warning.

dskrvk avatar Sep 29 '16 17:09 dskrvk

First, the version is : "grunt-contrib-jshint": "~0.8.0", And I write this config to ignore the specific warning W033,but it did not work:


jshint: {
            options: {
                jshintrc: '.jshintrc'
            },
            before_concat: ['Gruntfile.js', 'app/scripts/**/*.js', 'test/scripts/**/*.js'],
            after_concat: {
                options: {
                    '-W033': true,
                },
                src: ['dev_dest/scripts/**/*.js']
            }
        }

I read this issue, but cannot find the perfect answer. confused... however, I try this config, comment the jshintrc property, it really work:


jshint: {
            options: {
                '-W033': true,
                // jshintrc: '.jshintrc'
            },
            before_concat: ['Gruntfile.js', 'app/scripts/**/*.js', 'test/scripts/**/*.js'],
            after_concat: {
                options: {
                    // '-W033': true, //or write here will ok                
                },
                src: ['dev_dest/scripts/**/*.js']
            }
        }

but, but, I need the .jshintrc file.

emthink avatar Nov 10 '16 08:11 emthink

I have tested on version 3.2.0, but I guess that this issue can be solved for version before.

In fact the answer is quite simple :

If you are not using jshintrc option (in grunt.initConfig>jshint) , you can follow the documentation without issue, it is working.

If you are using jshintrc option you have to put the following option inside your rc file like that :

{
  "-W003": true,
  "browser": true,
  "curly": true,
  "eqeqeq": true,
  ...
  "eqnull": true,
  "globals": {
    "jQuery": true,
    "require": true,
    ...
    "window": true
  }
}

Bryce-Colton avatar Sep 05 '23 13:09 Bryce-Colton