Search code examples
jslintangular-cli

Angular-cli : Using ng lint


I'm aware the angular-cli uses codelyzer which uses lint.js

When using the command: ng lint

Can it automatically fix formatting? or will it only notify of formatting errors?

ng lint --help outputs all help commands for the angular-cli.


Solution

  • 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.