angularlintangular14autocorrect

How do I run auto-corrections for lint in an Angular 14 project?


I'm using Angular 14 and the corresponding lint version. I hvae this in my package.json ...

  "name": "my-project",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    ...
    "lint": "ng lint"
  },

When I run "npm run lint," I get errors like

  42:10  error    Type number trivially inferred from a number literal, remove type annotation  @typescript-eslint/no-inferrable-types

Referring to this error in my code ...

  run(myParam: number = 0): Observable<any> {

This seems like the kind of issue lint coudl auto-correct, but when I run

npm run lint --fix

Nothing happens, and in fact, this message is printed out at the end

 2 errors and 0 warnings potentially fixable with the `--fix` option.

What is the proper way to run the auto-fix option for lint in Angular?


Solution

  • It might help to run it like this:

    npm run lint -- --fix