Navigation Menu

Skip to content

Commit

Permalink
fix(eslint-plugin): [no-useless-constructor] handle parameter decorat…
Browse files Browse the repository at this point in the history
…or (#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>
  • Loading branch information
yeonjuan and JoshuaKGoldberg committed Aug 16, 2022
1 parent f92e66a commit 864dbcf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/eslint-plugin/src/rules/no-useless-constructor.ts
Expand Up @@ -31,13 +31,15 @@ function checkAccessibility(node: TSESTree.MethodDefinition): boolean {
}

/**
* Check if method is not unless due to typescript parameter properties
* Check if method is not useless due to typescript parameter properties and decorators
*/
function checkParams(node: TSESTree.MethodDefinition): boolean {
return (
!node.value.params ||
!node.value.params.some(
param => param.type === AST_NODE_TYPES.TSParameterProperty,
param =>
param.type === AST_NODE_TYPES.TSParameterProperty ||
param.decorators?.length,
)
);
}
Expand Down
14 changes: 14 additions & 0 deletions packages/eslint-plugin/tests/rules/no-useless-constructor.test.ts
Expand Up @@ -206,6 +206,20 @@ class A extends B {
`
class A {
constructor(foo);
}
`,
`
class A extends Object {
constructor(@Foo foo: string) {
super(foo);
}
}
`,
`
class A extends Object {
constructor(foo: string, @Bar() bar) {
super(foo, bar);
}
}
`,
],
Expand Down

0 comments on commit 864dbcf

Please sign in to comment.