Skip to content

Commit 9882bd9

Browse files
feat(no-misused-observables): class expressions
1 parent 1f23005 commit 9882bd9

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/rules/no-misused-observables.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TSESTree as es, ESLintUtils, TSESLint } from '@typescript-eslint/utils';
1+
import { TSESTree as es, TSESLint as eslint, ESLintUtils } from '@typescript-eslint/utils';
22
import * as tsutils from 'ts-api-utils';
33
import ts from 'typescript';
44
import { getTypeServices, isJSXExpressionContainer, isMethodDefinition, isPropertyDefinition } from '../etc';
@@ -47,20 +47,20 @@ export const noMisusedObservablesRule = ruleCreator({
4747
const [config = {}] = context.options;
4848
const { checksVoidReturn = true, checksSpreads = true } = config;
4949

50-
const voidReturnChecks: TSESLint.RuleListener = {
50+
const voidReturnChecks: eslint.RuleListener = {
5151
CallExpression: checkArguments,
5252
NewExpression: checkArguments,
5353
JSXAttribute: checkJSXAttribute,
5454
ClassDeclaration: checkClassLikeOrInterfaceNode,
55-
// ClassExpression: checkClassLikeOrInterfaceNode,
55+
ClassExpression: checkClassLikeOrInterfaceNode,
5656
// TSInterfaceDeclaration: checkClassLikeOrInterfaceNode,
5757
// Property: checkProperty,
5858
// ReturnStatement: checkReturnStatement,
5959
// AssignmentExpression: checkAssignment,
6060
// VariableDeclarator: checkVariableDeclarator,
6161
};
6262

63-
const spreadChecks: TSESLint.RuleListener = {
63+
const spreadChecks: eslint.RuleListener = {
6464
SpreadElement: (node) => {
6565
if (couldBeObservable(node.argument)) {
6666
context.report({

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ ruleTester({ types: true }).run('no-misused-observables', noMisusedObservablesRu
8080
class Bar extends Foo {
8181
foo(): Observable<number> { return of(42); }
8282
}
83+
84+
const Baz = class extends Foo {
85+
foo(): Observable<number> { return of(42); }
86+
}
8387
`,
8488
options: [{ checksVoidReturn: false }],
8589
},
@@ -341,6 +345,36 @@ ruleTester({ types: true }).run('no-misused-observables', noMisusedObservablesRu
341345
}
342346
`,
343347
),
348+
fromFixture(
349+
stripIndent`
350+
// void return inherited method; class expression; extends
351+
import { Observable, of } from "rxjs";
352+
353+
const Foo = class {
354+
foo(): void {}
355+
}
356+
357+
const Bar = class extends Foo {
358+
foo(): Observable<number> { return of(42); }
359+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [forbiddenVoidReturnInheritedMethod { "heritageTypeName": "Foo" }]
360+
}
361+
`,
362+
),
363+
fromFixture(
364+
stripIndent`
365+
// void return inherited method; class expression; implements
366+
import { Observable, of } from "rxjs";
367+
368+
interface Foo {
369+
foo(): void;
370+
}
371+
372+
const Bar = class implements Foo {
373+
foo(): Observable<number> { return of(42); }
374+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [forbiddenVoidReturnInheritedMethod { "heritageTypeName": "Foo" }]
375+
}
376+
`,
377+
),
344378
// #endregion invalid; void return inherited method
345379
// #region invalid; spread
346380
fromFixture(

0 commit comments

Comments
 (0)