ESLint `no-useless-constructor`: 如何忽略带有属性赋值的构造函数

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

ESLint `no-useless-constructor`: how to ignore constructors with property assignments

问题

在NestJS中,构造函数中的这种模式相当常见:

constructor(private service: MyService) {}

我在ESLint中有一个规则,它指出无用的构造函数是一个错误

"no-useless-constructor": "error"

由于分配属性的构造函数实际上并不无用,是否有一种方式可以忽略这种情况?

英文:

In NestJS, the pattern in the constructor is quite common:

constructor(private service: MyService) {}

I've got a rule in ESlint that says that useless constructors are an error:

"no-useless-constructor": "error"

Since constructors that assign properties aren't really useless, is there a way to ignore this scenario?

答案1

得分: 3

你需要关闭 eslint/no-useless-constructor 规则,而是使用来自 @typescript-eslint 的规则。

"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "error"
英文:

You need to turn eslint/no-useless-constructor rule off and instead use the one coming from @typescript-eslint

    "no-useless-constructor": "off",
    "@typescript-eslint/no-useless-constructor": "error"

huangapple
  • 本文由 发表于 2023年4月10日 23:57:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75978638.html
匿名

发表评论

匿名网友

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

确定