Skip to content

Commit 1af5199

Browse files
fix(no-misused-observables): don't report on static accessor properties
1 parent c712a22 commit 1af5199

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/etc/is.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ export function hasTypeAnnotation<T extends TSESTree.Node>(
66
return 'typeAnnotation' in node && !!node.typeAnnotation;
77
}
88

9+
export function isAccessorProperty(
10+
node: TSESTree.Node,
11+
): node is TSESTree.AccessorProperty {
12+
return node.type === AST_NODE_TYPES.AccessorProperty;
13+
}
14+
915
export function isArrayExpression(node: TSESTree.Node): node is TSESTree.ArrayExpression {
1016
return node.type === AST_NODE_TYPES.ArrayExpression;
1117
}

src/rules/no-misused-observables.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as tsutils from 'ts-api-utils';
33
import ts from 'typescript';
44
import {
55
getTypeServices,
6+
isAccessorProperty,
67
isArrowFunctionExpression,
78
isFunctionDeclaration,
89
isFunctionExpression,
@@ -416,8 +417,10 @@ function getMemberIfExists(
416417
}
417418

418419
function isStaticMember(node: es.Node): boolean {
419-
return (isMethodDefinition(node) || isPropertyDefinition(node))
420-
&& node.static;
420+
return (isMethodDefinition(node)
421+
|| isPropertyDefinition(node)
422+
|| isAccessorProperty(node))
423+
&& node.static;
421424
}
422425

423426
function getPropertyContextualType(

tests/rules/no-misused-observables.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,29 @@ ruleTester({ types: true }).run('no-misused-observables', noMisusedObservablesRu
123123
foo(): Observable<45>;
124124
}
125125
`,
126+
stripIndent`
127+
// void return inherited method; static accessor properties
128+
import { Observable, of } from "rxjs";
129+
130+
class Foo {
131+
public foo = (): void => {};
132+
}
133+
134+
class Bar extends Foo {
135+
public static accessor foo = (): Observable<number> => of(42);
136+
}
137+
`,
138+
stripIndent`
139+
// void return inherited method; static accessor properties; unrelated
140+
141+
class Foo {
142+
public foo = (): void => {};
143+
}
144+
145+
class Bar extends Foo {
146+
public static accessor foo = (): void => {};
147+
}
148+
`,
126149
stripIndent`
127150
// void return inherited method; unrelated
128151
class Foo {

0 commit comments

Comments
 (0)