Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eslint-plugin): [no-useless-constructor] handle parameter decorator #5450

Merged
merged 4 commits into from Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside: it might be the case that param.decorators would make sense as a check, as it might be that the parser doesn't create param.decorators if it would have length 0. But that's a nuance not yet strongly defined in AST parsing. #5020

)
);
}
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