Skip to content

Commit 445e1da

Browse files
fix(no-misused-observables): don't report on static accessor properties
1 parent 636c922 commit 445e1da

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
@@ -4,6 +4,7 @@ import * as tsutils from 'ts-api-utils';
44
import ts from 'typescript';
55
import {
66
getTypeServices,
7+
isAccessorProperty,
78
isArrowFunctionExpression,
89
isFunctionDeclaration,
910
isFunctionExpression,
@@ -443,8 +444,10 @@ function getMemberIfExists(
443444
}
444445

445446
function isStaticMember(node: es.Node): boolean {
446-
return (isMethodDefinition(node) || isPropertyDefinition(node))
447-
&& node.static;
447+
return (isMethodDefinition(node)
448+
|| isPropertyDefinition(node)
449+
|| isAccessorProperty(node))
450+
&& node.static;
448451
}
449452

450453
function getPropertyContextualType(

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,29 @@ ruleTester({ types: true }).run('no-misused-observables', noMisusedObservablesRu
136136
foo(): Observable<45>;
137137
}
138138
`,
139+
stripIndent`
140+
// void return inherited method; static accessor properties
141+
import { Observable, of } from "rxjs";
142+
143+
class Foo {
144+
public foo = (): void => {};
145+
}
146+
147+
class Bar extends Foo {
148+
public static accessor foo = (): Observable<number> => of(42);
149+
}
150+
`,
151+
stripIndent`
152+
// void return inherited method; static accessor properties; unrelated
153+
154+
class Foo {
155+
public foo = (): void => {};
156+
}
157+
158+
class Bar extends Foo {
159+
public static accessor foo = (): void => {};
160+
}
161+
`,
139162
stripIndent`
140163
// void return inherited method; unrelated
141164
class Foo {

0 commit comments

Comments
 (0)