I know eslint CLI itself has a --fix flag, but I can't tell from the documentation how to use this via eslintConfig (in package.json) or in the grunt-eslint configuration in my Gruntfile.
I have the following config in package.json:
"env": {
  "browser": true,
  "amd": true
},
"extends": "eslint:recommended",
and invoke it via a lint task using this Grunt config:
    eslint: {
        target: [
            'src/app/**/*.js'
        ],
        format: 'checkstyle'
    },
How can I enable the --fix flag in this scenario?
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'
  ]
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With