From 445e1da2f16a4de48929238d445e933b6e2da0be Mon Sep 17 00:00:00 2001 From: Jason Weinzierl Date: Wed, 25 Jun 2025 14:47:52 -0500 Subject: [PATCH] fix(no-misused-observables): don't report on static accessor properties --- src/etc/is.ts | 6 ++++++ src/rules/no-misused-observables.ts | 7 +++++-- tests/rules/no-misused-observables.test.ts | 23 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/etc/is.ts b/src/etc/is.ts index c4459ab9..d712acca 100644 --- a/src/etc/is.ts +++ b/src/etc/is.ts @@ -6,6 +6,12 @@ export function hasTypeAnnotation( 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; } diff --git a/src/rules/no-misused-observables.ts b/src/rules/no-misused-observables.ts index 50303c9e..1b28b03b 100644 --- a/src/rules/no-misused-observables.ts +++ b/src/rules/no-misused-observables.ts @@ -4,6 +4,7 @@ import * as tsutils from 'ts-api-utils'; import ts from 'typescript'; import { getTypeServices, + isAccessorProperty, isArrowFunctionExpression, isFunctionDeclaration, isFunctionExpression, @@ -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( diff --git a/tests/rules/no-misused-observables.test.ts b/tests/rules/no-misused-observables.test.ts index d0f06da1..5f93c8aa 100644 --- a/tests/rules/no-misused-observables.test.ts +++ b/tests/rules/no-misused-observables.test.ts @@ -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 => 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 {