Grunt-eslint & enabling `--fix` flag to auto fix violations

Adding to the answer, If You don't wan't always to fix, You could pass the flag to the grunt like

grunt eslint --fix

And in the grunt config for eslint

eslint: {
  options: {
    fix: grunt.option('fix') // this will get params from the flags
  }
}

So Running grunt eslint won't fix anything. You have to run grunt eslint --fix for eslint to fix errors.

Read More about grunt.option


For the --fix flag, you only have to add an options: { fix: true } to your gruntfile.

Here is an example of my gruntfile eslint task (grunt-eslint 18.1.0 with eslint 2.12.0):

eslint: {
  options: {
    configFile: '.eslintrc.json',
    format: 'html',
    outputFile: 'report.html',
    fix: true
  },
  target: [
    'routes/**',
    'server.js',
    'gruntfile.js'
  ]
}