How to configure ESlint to fix indent only
Asked Answered
C

2

11

I am linting old NodeJS code and I want to clear out all indent issues before I start fixing the rest.

How do I configure ESlint to only show and fix the indent issues only?

Cyclothymia answered 6/8, 2018 at 10:37 Comment(0)
L
9

By using eslint in the command line with the proper options:

node node_modules/eslint/bin/eslint --fix --parser babel-eslint --ext js --no-eslintrc --rule 'indent: [1,4,{SwitchCase: 1}]' src/

Change these options according to your requirements

--fix to auto fix.

--parser babel-eslint the parser from my eslint.rc.

--ext js to lint only js files.

--no-eslintrc otherwise all rules from your eslintrc will be executed.

--rule 'indent: [1,4,{SwitchCase: 1}]' the rule you want to execute (you can copy paste it from your eslint.rc, it has to be single quoted (the double quotes from the original json were removed).

src/ the target folder.

eslint documentation

Loxodromics answered 6/8, 2018 at 11:33 Comment(2)
For complete noobs like myself : is there an even more basic parser than babel which doesn't require to install an extra package? (i.e. out of the box). I mean, if eslint is able to complain about indentation issues without babel, surely it can fix them too without it?Cabanatuan
What do you think eslint uses internally :) ?( espree and a lot more....) If you do not need a complete javascript implementation, your lightest solution could be using a parser generator like PEGJS (npmjs.com/package/pegjs)Loxodromics
R
1

If you want to use your normal .eslintrc file to keep your configuration (parser, plugins, rule config, etc), you can use eslint-nibble with the --rule= indent flag. This will respect your normal configuration, but only show you errors from that rule, and give you the option to fix only those, if the rule is auto-fixable.

Disclaimer: I'm the creator of eslint-nibble.

Reata answered 7/10, 2021 at 14:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.