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
6 changes: 6 additions & 0 deletions src/etc/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ export function hasTypeAnnotation<T extends TSESTree.Node>(
return 'typeAnnotation' in node && !!node.typeAnnotation;
}

export function isAccessorProperty(
node: TSESTree.Node,
): node is TSESTree.AccessorProperty {
return node.type === AST_NODE_TYPES.AccessorProperty;
}

export function isArrayExpression(node: TSESTree.Node): node is TSESTree.ArrayExpression {
return node.type === AST_NODE_TYPES.ArrayExpression;
}
Expand Down
7 changes: 5 additions & 2 deletions src/rules/no-misused-observables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as tsutils from 'ts-api-utils';
import ts from 'typescript';
import {
getTypeServices,
isAccessorProperty,
isArrowFunctionExpression,
isFunctionDeclaration,
isFunctionExpression,
Expand Down Expand Up @@ -443,8 +444,10 @@ function getMemberIfExists(
}

function isStaticMember(node: es.Node): boolean {
return (isMethodDefinition(node) || isPropertyDefinition(node))
&& node.static;
return (isMethodDefinition(node)
|| isPropertyDefinition(node)
|| isAccessorProperty(node))
&& node.static;
}

function getPropertyContextualType(
Expand Down
23 changes: 23 additions & 0 deletions tests/rules/no-misused-observables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,29 @@ ruleTester({ types: true }).run('no-misused-observables', noMisusedObservablesRu
foo(): Observable<45>;
}
`,
stripIndent`
// void return inherited method; static accessor properties
import { Observable, of } from "rxjs";
class Foo {
public foo = (): void => {};
}
class Bar extends Foo {
public static accessor foo = (): Observable<number> => of(42);
}
`,
stripIndent`
// void return inherited method; static accessor properties; unrelated
class Foo {
public foo = (): void => {};
}
class Bar extends Foo {
public static accessor foo = (): void => {};
}
`,
stripIndent`
// void return inherited method; unrelated
class Foo {
Expand Down