diff --git a/packages/eslint-plugin/src/rules/no-extraneous-class.ts b/packages/eslint-plugin/src/rules/no-extraneous-class.ts index b5a4a19a1cb1..591a50ee95b7 100644 --- a/packages/eslint-plugin/src/rules/no-extraneous-class.ts +++ b/packages/eslint-plugin/src/rules/no-extraneous-class.ts @@ -123,10 +123,12 @@ export default createRule({ 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; } diff --git a/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts b/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts index 960e167218d7..19d501a347b8 100644 --- a/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts +++ b/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts @@ -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; } `, ], @@ -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], + }, ], }); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy