diff --git a/packages/eslint-plugin/src/rules/no-misused-promises.ts b/packages/eslint-plugin/src/rules/no-misused-promises.ts index 91df1786ba31..952ca3c3d7ec 100644 --- a/packages/eslint-plugin/src/rules/no-misused-promises.ts +++ b/packages/eslint-plugin/src/rules/no-misused-promises.ts @@ -987,7 +987,8 @@ function getMemberIfExists( function isStaticMember(node: TSESTree.Node): boolean { return ( (node.type === AST_NODE_TYPES.MethodDefinition || - node.type === AST_NODE_TYPES.PropertyDefinition) && + node.type === AST_NODE_TYPES.PropertyDefinition || + node.type === AST_NODE_TYPES.AccessorProperty) && node.static ); } diff --git a/packages/eslint-plugin/tests/rules/no-misused-promises.test.ts b/packages/eslint-plugin/tests/rules/no-misused-promises.test.ts index 16ee46b5f01d..5f7f1faf8bb4 100644 --- a/packages/eslint-plugin/tests/rules/no-misused-promises.test.ts +++ b/packages/eslint-plugin/tests/rules/no-misused-promises.test.ts @@ -467,6 +467,36 @@ class Bar extends Foo { } `, ` +class Foo { + public doThing = (): void => {}; +} + +class Bar extends Foo { + public static accessor doThing = async (): Promise => {}; +} + `, + ` +class Foo { + public accessor doThing = (): void => {}; +} + +class Bar extends Foo { + public static accessor doThing = (): void => {}; +} + `, + { + code: ` +class Foo { + [key: string]: void; +} + +class Bar extends Foo { + [key: string]: Promise; +} + `, + options: [{ checksVoidReturn: { inheritedMethods: true } }], + }, + ` function restTuple(...args: []): void; function restTuple(...args: [string]): void; function restTuple(..._args: string[]): void {} @@ -2031,6 +2061,46 @@ abstract class MyAbstractClassImplementsMyInterface implements MyInterface { }, { code: ` +class MyClass { + accessor setThing = (): void => { + return; + }; +} + +class MySubclassExtendsMyClass extends MyClass { + accessor setThing = async (): Promise => { + await Promise.resolve(); + }; +} + `, + errors: [ + { + data: { heritageTypeName: 'MyClass' }, + line: 9, + messageId: 'voidReturnInheritedMethod', + }, + ], + }, + { + code: ` +abstract class MyClass { + abstract accessor setThing: () => void; +} + +abstract class MySubclassExtendsMyClass extends MyClass { + abstract accessor setThing: () => Promise; +} + `, + errors: [ + { + data: { heritageTypeName: 'MyClass' }, + line: 7, + messageId: 'voidReturnInheritedMethod', + }, + ], + }, + { + code: ` interface MyInterface { setThing(): void; }