Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Ignore Warnings" not working #177

Open
raijinsetsu opened this issue Sep 25, 2014 · 10 comments
Open

"Ignore Warnings" not working #177

raijinsetsu opened this issue Sep 25, 2014 · 10 comments

Comments

@raijinsetsu
Copy link

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.

@whyvez
Copy link

whyvez commented Oct 8, 2014

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 pushed a commit to avalanche-canada/ac-web that referenced this issue Oct 8, 2014
@raijinsetsu
Copy link
Author

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
#177 (comment)
.

@raijinsetsu
Copy link
Author

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
#177 (comment)
.

@bhonnegowda
Copy link

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

should fix it.

@marian-r
Copy link

Any updates on this?

@jaydge
Copy link

jaydge commented Nov 23, 2015

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!

@raijinsetsu
Copy link
Author

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
#177 (comment)
.

@dskrvk
Copy link

dskrvk commented Sep 29, 2016

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.

@emthink
Copy link

emthink commented Nov 10, 2016

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.

@Bryce-Colton
Copy link

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
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants