Skip to content

Commit 864dbcf

Browse files
yeonjuanJoshuaKGoldberg
andauthoredAug 16, 2022
fix(eslint-plugin): [no-useless-constructor] handle parameter decorator (#5450)
* fix(eslint-plugin): [no-useless-constructor] handle parameter decorator * Update packages/eslint-plugin/src/rules/no-useless-constructor.ts Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
1 parent f92e66a commit 864dbcf

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed
 

‎packages/eslint-plugin/src/rules/no-useless-constructor.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ function checkAccessibility(node: TSESTree.MethodDefinition): boolean {
3131
}
3232

3333
/**
34-
* Check if method is not unless due to typescript parameter properties
34+
* Check if method is not useless due to typescript parameter properties and decorators
3535
*/
3636
function checkParams(node: TSESTree.MethodDefinition): boolean {
3737
return (
3838
!node.value.params ||
3939
!node.value.params.some(
40-
param => param.type === AST_NODE_TYPES.TSParameterProperty,
40+
param =>
41+
param.type === AST_NODE_TYPES.TSParameterProperty ||
42+
param.decorators?.length,
4143
)
4244
);
4345
}

‎packages/eslint-plugin/tests/rules/no-useless-constructor.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,20 @@ class A extends B {
206206
`
207207
class A {
208208
constructor(foo);
209+
}
210+
`,
211+
`
212+
class A extends Object {
213+
constructor(@Foo foo: string) {
214+
super(foo);
215+
}
216+
}
217+
`,
218+
`
219+
class A extends Object {
220+
constructor(foo: string, @Bar() bar) {
221+
super(foo, bar);
222+
}
209223
}
210224
`,
211225
],

0 commit comments

Comments
 (0)
Please sign in to comment.