0

I am building a JSHint set for a JavaScript suite that I am writing. My habit with writing objects is as follows:

var obj = {
   hello: 'World'
  ,foo: 'Bar'
  ,name: 'Dave'
};

I use Grunt and grunt-contrib-jshint to run the validations with the following options:

  • browser: true
  • eqeqeq: false
  • laxcomma: true
  • white: true
  • indent: 2

When I run grunt jshint I get errors that a space is expected after the commas. How do I ignore this space?

Dave Long
  • 9,569
  • 14
  • 59
  • 89
  • I think this is currently not possible. You actually need to disable the `white` rule (i.e. `white: false`). But if you do that, the `indent` rule is no longer checked. Unfortunately these two settings are tied together. – Odi Feb 13 '13 at 05:36
  • 1
    This style makes me frightened and confused. Not to start a war, but dear God ... why? – carbontax Feb 13 '13 at 23:24
  • @carbontax for one thing, it makes commenting out object fields much easier... a double `//` and you're done... no dangling commas to worry about. – Dancrumb Feb 14 '13 at 00:09
  • @carbontax besides dancrumb's comment, It's also a lot easier to find missing commas in this format as well. Just scan down the code and you'll find them easily. – Dave Long Feb 14 '13 at 14:10
  • Okay, those are pretty good reasons actually. I am not going to start doing it but I see your point. – carbontax Feb 14 '13 at 15:53

1 Answers1

0

You can ignore specific errors in the way written in the doc; https://github.com/gruntjs/grunt-contrib-jshint here is a quote

Ignoring specific warnings

If you would like to ignore a specific warning:

[L24:C9] W015: Expected '}' to have an indentation at 11 instead at 9. You can toggle it by prepending - to the warning id as an option:

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

Update. Also, I am using such config and don't have comma errors

,defaultOptions = {
            curly: true,
            eqeqeq: true,
            immed: true,
            latedef: 'nofunc',
            newcap: true,
            noarg: true,
            nonew: true,
            sub: true,
            undef: true,
            boss: true,
            eqnull: true,
            camelcase: true,
            quotmark: true,

            // lax
            laxcomma: true,

            // environment
            browser: true,
            devel: true,
            jquery: true,
        }
sneakyfildy
  • 361
  • 1
  • 4
  • 10