0

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?

Dave
  • 15,639
  • 133
  • 442
  • 830
  • The answer below shows the correct way to pass the `--fix` flag to the underlying command, `ng lint`, rather than to `npm run`, but then this is just a dupe of https://stackoverflow.com/q/11580961/3001761. [The docs](https://typescript-eslint.io/rules/no-inferrable-types) for the relevant rule say _"**Some** problems reported by this rule are automatically fixable..."_, emphasis mine; maybe this is one of the cases that aren't. – jonrsharpe Mar 07 '23 at 12:43
  • What is an example of a case that would be fixable? If I can successfully see that working then you have yourself a bounty. – Dave Mar 08 '23 at 22:08
  • As far as I can tell you _have_ an example of a case that would be fixable, with `npm run -- --fix` -> `ng lint --fix`, as shown by the correct answer you already got. All the incorrect examples in the docs (pretty reputable source I'd think) are fixable too. – jonrsharpe Mar 08 '23 at 22:33
  • So running "npm run -- --fix" does not auto-fix it so I'm wondering why and what other information I can provide to solve this. – Dave Mar 09 '23 at 14:21

1 Answers1

-1

It might help to run it like this:

npm run lint -- --fix

Felix
  • 1,337
  • 10
  • 10
  • Which types of errors/warnings is this meant to correct? I ran the above and this did not auto-correct the error I listed in my question. – Dave Mar 03 '23 at 19:12
  • 2
    It should propagate the fix command to the ng lint and prevent the npm command to interpret it. – Felix Mar 04 '23 at 20:54