Automatically fix TSLint alerts

[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 from TSLint. There are a huge number of warnings, and it will be very difficult to fix it manually.

I was looking for a way that can automatically fix most warnings.

+5
source share
2 answers

You can use the --fix for TSLint to automatically fix most warnings. This might look something like this in the general case:

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

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

  • Commit the changes made to your code.
  • Run TSLint with the --fix flag as above
  • Quick view of changes made by TSLint
  • Make a new commit with these changes, or simply change them to the previous commit.

Thus, you will never be surprised that the auto-correction of the rogue went wrong.

+11
source
 tslint --fix --project ./tsconfig.json 

This is an automatic fix for the entire error - this is the root folder

-1
source

Source: https://habr.com/ru/post/1269361/


All Articles