8000 fix(eslint-plugin): [no-extraneous-class] handle accessor keyword by mdm317 · Pull Request #10678 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

fix(eslint-plugin): [no-extraneous-class] handle accessor keyword #10678

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/eslint-plugin/src/rules/no-extraneous-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ export default createRule<Options, MessageIds>({
onlyConstructor = false;
if (
((prop.type === AST_NODE_TYPES.PropertyDefinition ||
prop.type === AST_NODE_TYPES.MethodDefinition) &&
prop.type === AST_NODE_TYPES.MethodDefinition ||
prop.type === AST_NODE_TYPES.AccessorProperty) &&
!prop.static) ||
prop.type === AST_NODE_TYPES.TSAbstractPropertyDefinition ||
prop.type === AST_NODE_TYPES.TSAbstractMethodDefinition // `static abstract` methods and properties are currently not supported. See: https://github.com/microsoft/TypeScript/issues/34516
prop.type === AST_NODE_TYPES.TSAbstractMethodDefinition || // `static abstract` methods and properties are currently not supported. See: https://github.com/microsoft/TypeScript/issues/34516
prop.type === AST_NODE_TYPES.TSAbstractAccessorProperty
) {
onlyStatic = false;
}
Expand Down
39 changes: 39 additions & 0 deletions packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,29 @@ abstract class Foo {
`
abstract class Foo {
abstract method(): string;
}
`,
`
class Foo {
accessor prop: string;
}
`,
`
class Foo {
accessor prop = 'bar';
static bar() {
return false;
}
}
`,
`
abstract class Foo {
accessor prop: string;
}
`,
`
abstract class Foo {
abstract accessor prop: string;
}
`,
],
Expand Down Expand Up @@ -212,5 +235,21 @@ abstract class Foo {
`,
errors: [onlyConstructor],
},
{
code: `
class Foo {
static accessor prop: string;
}
`,
errors: [onlyStatic],
},
{
code: `
abstract class Foo {
static accessor prop: string;
}
`,
errors: [onlyStatic],
},
],
});
Loading
0