Skip to content
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
3 changes: 2 additions & 1 deletion packages/eslint-plugin/src/rules/no-misused-promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
70 changes: 70 additions & 0 deletions packages/eslint-plugin/tests/rules/no-misused-promises.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,36 @@ class Bar extends Foo {
}
`,
`
class Foo {
public doThing = (): void => {};
}

class Bar extends Foo {
public static accessor doThing = async (): Promise<void> => {};
}
`,
`
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<void>;
}
`,
options: [{ checksVoidReturn: { inheritedMethods: true } }],
},
`
function restTuple(...args: []): void;
function restTuple(...args: [string]): void;
function restTuple(..._args: string[]): void {}
Expand Down Expand Up @@ -2031,6 +2061,46 @@ abstract class MyAbstractClassImplementsMyInterface implements MyInterface {
},
{
code: `
class MyClass {
accessor setThing = (): void => {
return;
};
}

class MySubclassExtendsMyClass extends MyClass {
accessor setThing = async (): Promise<void> => {
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<void>;
}
`,
errors: [
{
data: { heritageTypeName: 'MyClass' },
line: 7,
messageId: 'voidReturnInheritedMethod',
},
],
},
{
code: `
interface MyInterface {
setThing(): void;
}
Expand Down
Loading