From 33aa2bcb2aa99309f1ff7b5aac20a8cd72801752 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Tue, 4 Feb 2025 20:55:56 +0200 Subject: [PATCH 1/2] handle accessor property with explicit-module-boundary-types --- .../rules/explicit-module-boundary-types.ts | 4 +- packages/eslint-plugin/src/util/misc.ts | 1 + .../explicit-module-boundary-types.test.ts | 46 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts b/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts index eaa7b8baf0b4..c8a627e7aca5 100644 --- a/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts +++ b/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts @@ -270,7 +270,8 @@ export default createRule({ node.type === AST_NODE_TYPES.MethodDefinition || node.type === AST_NODE_TYPES.TSAbstractMethodDefinition || (node.type === AST_NODE_TYPES.Property && node.method) || - node.type === AST_NODE_TYPES.PropertyDefinition + node.type === AST_NODE_TYPES.PropertyDefinition || + node.type === AST_NODE_TYPES.AccessorProperty ) { return isStaticMemberAccessOfValue( node, @@ -369,6 +370,7 @@ export default createRule({ return; case AST_NODE_TYPES.PropertyDefinition: + case AST_NODE_TYPES.AccessorProperty: case AST_NODE_TYPES.MethodDefinition: case AST_NODE_TYPES.TSAbstractMethodDefinition: if ( diff --git a/packages/eslint-plugin/src/util/misc.ts b/packages/eslint-plugin/src/util/misc.ts index 6313740bf0d0..b24758fd426a 100644 --- a/packages/eslint-plugin/src/util/misc.ts +++ b/packages/eslint-plugin/src/util/misc.ts @@ -239,6 +239,7 @@ export function isParenlessArrowFunction( } export type NodeWithKey = + | TSESTree.AccessorProperty | TSESTree.MemberExpression | TSESTree.MethodDefinition | TSESTree.Property diff --git a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts index 45deb7d1124f..f3567b219660 100644 --- a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts @@ -1670,6 +1670,52 @@ class Foo { return arg; }; } +export default Foo; + `, + errors: [ + { + line: 3, + messageId: 'missingReturnType', + }, + { + data: { + name: 'arg', + }, + line: 3, + messageId: 'missingArgType', + }, + ], + }, + { + code: ` +class Foo { + accessor bool = arg => { + return arg; + }; +} +export default Foo; + `, + errors: [ + { + data: { + name: 'arg', + }, + line: 3, + messageId: 'missingArgType', + }, + { + line: 3, + messageId: 'missingReturnType', + }, + ], + }, + { + code: ` +class Foo { + accessor bool = function (arg) { + return arg; + }; +} export default Foo; `, errors: [ From d081cca2a7c939a285c5f3b81bc03d354a6b14e6 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Thu, 6 Feb 2025 17:48:00 +0200 Subject: [PATCH 2/2] add valid test --- .../tests/rules/explicit-module-boundary-types.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts index f3567b219660..1bd477f206ce 100644 --- a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts @@ -601,6 +601,15 @@ export default { Foo }; }, { code: ` +export class Foo { + accessor bar = (): void => { + return; + }; +} + `, + }, + { + code: ` export function foo(): (n: number) => string { return n => String(n); }