如何在 Angular 14 项目中为 lint 运行自动更正?

问题描述 投票:0回答:1

我正在使用 Angular 14 和相应的 lint 版本。我把这个放在我的 package.json 中 ...

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

当我运行“npm run lint”时,出现如下错误

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

在我的代码中提到这个错误......

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

这似乎是 lint 可以自动更正的问题,但是当我运行时

npm run lint --fix

什么都没有发生,事实上,这条消息是在最后打印出来的

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

在 Angular 中运行 lint 自动修复选项的正确方法是什么?

angular lint angular14 autocorrect
1个回答
0
投票

像这样运行它可能会有所帮助:

npm run lint -- --fix

© www.soinside.com 2019 - 2024. All rights reserved.