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], } };
ESLint comes with a large number of built-in rules and you can add more rules through plugins. You can modify which rules your project uses either using configuration comments or configuration files. To change a rule setting, you must set the rule ID equal to one of these values: "off" or 0 - turn the rule off.
If you want to disable an ESLint rule in a file or on a specific line, you can add a comment. On a single line: const message = 'foo'; console. log(message); // eslint-disable-line no-console // eslint-disable-next-line no-console console.
If you have the ESLint extension installed you can use CTRL+SHIFT+P to open the Command Palette. Then search for ESLint: Fix all auto-fixable Problems and press ENTER (or RETURN ).
While ESLint (when running with --fix ) tries hard not to break your code functionally, any time you're manipulating your code in the time between writing it and running it you are putting yourself at risk of changing the behavior of your codebase.
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]'
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.
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