Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure ESlint to fix indent only

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?

like image 721
zabumba Avatar asked Aug 06 '18 10:08

zabumba


People also ask

How do I automatically fix ESLint?

You can set up ESLint to run auto-fix every time you press CTRL+S (or COMMAND+S ). For ESLint to work correctly on file same, you must change the Visual Studio Code preferences. Go to File > Preferences > Settings (or Code > Preferences > Settings).

How do you trigger ESLint?

The ./node_modules/. bin/eslint section of the command is the path to ESLint in your project. Using the --init flag activates ESLint for your project. Activating or initializing ESLint will create an ESLint configuration file that will allow you to customize how ESLint works with your project.


1 Answers

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

like image 174
remix23 Avatar answered Sep 30 '22 15:09

remix23