Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto fix TSLint Warnings

    [64, 1]: space indentation expected
    [15, 27]: Missing semicolon
    [109, 36]: missing whitespace
    [111, 24]: missing whitespace
    [70, 1]: Consecutive blank lines are forbidden

I keep getting warnings like these from TSLint. There are huge amount of warnings, and it will be very difficult to fix it manually.

I was looking for a way which can auto-fix most of the warnings.

like image 222
ANKIT HALDAR Avatar asked Jun 30 '17 07:06

ANKIT HALDAR


3 Answers

You can use the --fix option of TSLint to automatically fix most warnings. This might look something like this in a common use case:

tslint --fix -c ./config/tslint.json 'src/**/*{.ts,.tsx}'

Keep in mind that this will overwrite your source code. While this is safe 99.9% of the time, I recommend the following workflow:

  1. Commit the changes you have made to your code
  2. Run TSLint with the --fix flag like above
  3. Quickly review the changes TSLint has made
  4. Make a new commit with these changes, or simply amend them to your previous commit

This way, you'll never be taken surprise by a rogue autocorrection gone wrong.

like image 132
JKillian Avatar answered Oct 13 '22 00:10

JKillian


tslint --fix --project ./tsconfig.json

This is auto fix all Error is root folder

like image 40
ANKIT HALDAR Avatar answered Oct 13 '22 00:10

ANKIT HALDAR


With @angular/cli you can use ng lint --fix

like image 40
splash Avatar answered Oct 13 '22 00:10

splash