Angular-cli : Using Ng Lint


Answer :

Updated answer for Angular CLI v6.x, 7.x, 8.x:

ng lint <project-name> --fix

where <project-name> is "name:" from package.json

-- answer for Angular CLI v1.x --

ng lint -fix

-- Original answer below --

To have tslint autofix many errors run the following in the root of your code. Obviously it can only autofix simpler issues like let -> const, "" -> ' etc.

npx tslint src/**/*.ts --fix 

Yesterday I did this to auto-fix hundreds of let -> const issues in our fairly large code bases. Just reviewing the changes before committing took long enough, manually fixing them all would have taken over a day.


For Angular 6.0+ you can run ng lint with autofix like so:

ng lint <project> --fix 

where <project> is the name you gave to your project when running ng new.

Learn more here: https://github.com/angular/angular-cli/wiki/lint


The functionality you are asking about is partially available these days in VS Code using the TSLint extension which does support Auto Fixing for some (but not all) of the default TSLint warnings.

I've been using it for a few weeks now and I find it quite helpful.


Comments

Popular posts from this blog

Chemistry - Bond Angles In NH3 And NCl3

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?