Reputation: 1687
I want to use eslint command flag --fix
to just fix one rule. And I tried the command: eslint --fix --config ./.eslintrcsomerules.js .
. But it does not work. How to achieve the object?
My .eslintrcsomerules.js file is below:
module.exports = {
'rules': {
'indent': [2, 2],
}
};
Upvotes: 56
Views: 22872
Reputation: 5962
To fix the issues caused by just one rule, you need to combine --fix --rule
with --no-eslintrc
. Otherwise your rule will just be merged with your existing configuration and all fixable issues will be corrected. E.g.
$ eslint --no-eslintrc --fix --rule 'indent: [2, 2]'
Depending on your setup you'll need to re-add mandatory settings from your ESLint configuration to the command line for the lint run to succeed. In my case I had to use
$ eslint --no-eslintrc --parser babel-eslint --fix --rule 'indent: [2, 2]'
eslint.config.js
)For eslint > 9.x
(not sure about the lowest version) use a new option name:
$ eslint --no-config-lookup --fix --rule 'indent: [2, 2]'
Upvotes: 29
Reputation: 223
The answers suggesting ignoring .eslintrc with
eslint --no-eslintrc --fix --rule 'indent: [2, 2]'
may fail if your .eslintrc contains preprocessors without which you get errors, such as
Parsing error: The keyword 'import' is reserved
I recommend using eslint-interactive, which will let you select the rules you want to fix:
yarn install -D eslint-interactive
eslint-interactive . # This will interactively guide you.
yarn remove -D eslint-interactive
Upvotes: 3
Reputation: 605
I struggled with this. I was using create-react-app and it was very difficult to turn off all the rules but keep all the configs to parse ES6/TS/etc.
This library was exactly what I wanted! I can see how many errors there are for each rule and selectively fix one rule at a time
https://github.com/IanVS/eslint-nibble
Upvotes: 19
Reputation: 3255
You can pass a --rule
flag with the rule you want to fix. For example:
eslint --fix --rule 'quotes: [2, double]' .
Check out the official documentation for more information.
The list of available rules might also be helpful.
Upvotes: 16