英文:
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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论