如何在 Angular 14 项目中运行代码纠错的自动修复?

huangapple go评论123阅读模式
英文:

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

问题

我正在使用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的自动修复选项的正确方式是什么?

英文:

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?

答案1

得分: -1

npm run lint -- --fix 这样运行可能会有帮助:

英文:

It might help to run it like this:

npm run lint -- --fix

huangapple
  • 本文由 发表于 2023年3月4日 02:04:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75630477.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定