From 8081b16dcff82ada0ed380359d3b42e737512b9e Mon Sep 17 00:00:00 2001 From: mdm317 <62943813+mdm317@users.noreply.github.com> Date: Sat, 18 Jan 2025 20:46:57 +0900 Subject: [PATCH 1/4] fix : handle accessor keyword --- .../eslint-plugin/src/rules/no-extraneous-class.ts | 3 ++- .../tests/rules/no-extraneous-class.test.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/no-extraneous-class.ts b/packages/eslint-plugin/src/rules/no-extraneous-class.ts index b5a4a19a1cb1..78564b296cab 100644 --- a/packages/eslint-plugin/src/rules/no-extraneous-class.ts +++ b/packages/eslint-plugin/src/rules/no-extraneous-class.ts @@ -123,7 +123,8 @@ 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 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..530932ed679d 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,19 @@ abstract class Foo { ` abstract class Foo { abstract method(): string; +} + `, + ` +class Foo { + accessor prop = 1; +} + `, + ` +class Foo { + accessor prop: string; + static bar() { + return false + } } `, ], From b7f651b9960ce86af4b17fb9724e4cfbac86ce28 Mon Sep 17 00:00:00 2001 From: mdm317 <62943813+mdm317@users.noreply.github.com> Date: Sat, 18 Jan 2025 20:51:58 +0900 Subject: [PATCH 2/4] test: change test code --- packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 530932ed679d..b7e8c4971b28 100644 --- a/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts +++ b/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts @@ -100,7 +100,7 @@ abstract class Foo { `, ` class Foo { - accessor prop = 1; + accessor prop: string; } `, ` From 5b19f6355f829fbea169ce1024d6f62f1dfd2864 Mon Sep 17 00:00:00 2001 From: mdm317 <62943813+mdm317@users.noreply.github.com> Date: Sat, 18 Jan 2025 22:36:46 +0900 Subject: [PATCH 3/4] test : add invalid case --- .../tests/rules/no-extraneous-class.test.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 b7e8c4971b28..f8bdeafb7e59 100644 --- a/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts +++ b/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts @@ -105,9 +105,9 @@ class Foo { `, ` class Foo { - accessor prop: string; + accessor prop = 'bar'; static bar() { - return false + return false; } } `, @@ -225,5 +225,13 @@ abstract class Foo { `, errors: [onlyConstructor], }, + { + code: ` +class Foo { + static accessor prop: string; +} + `, + errors: [onlyStatic], + }, ], }); From 2b512a719a79306daa111e46341b0d3d372f7746 Mon Sep 17 00:00:00 2001 From: mdm317 Date: Thu, 23 Jan 2025 19:16:02 +0900 Subject: [PATCH 4/4] fix : apply for abstract class --- .../src/rules/no-extraneous-class.ts | 3 ++- .../tests/rules/no-extraneous-class.test.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/no-extraneous-class.ts b/packages/eslint-plugin/src/rules/no-extraneous-class.ts index 78564b296cab..591a50ee95b7 100644 --- a/packages/eslint-plugin/src/rules/no-extraneous-class.ts +++ b/packages/eslint-plugin/src/rules/no-extraneous-class.ts @@ -127,7 +127,8 @@ export default createRule({ 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 f8bdeafb7e59..19d501a347b8 100644 --- a/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts +++ b/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts @@ -109,6 +109,16 @@ class Foo { static bar() { return false; } +} + `, + ` +abstract class Foo { + accessor prop: string; +} + `, + ` +abstract class Foo { + abstract accessor prop: string; } `, ], @@ -229,6 +239,14 @@ abstract class Foo { code: ` class Foo { static accessor prop: string; +} + `, + errors: [onlyStatic], + }, + { + code: ` +abstract class Foo { + static accessor prop: string; } `, errors: [onlyStatic],