Skip to content

Commit 07b195d

Browse files
feat(no-misused-observables): check ctors too
1 parent 2f08572 commit 07b195d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/rules/no-misused-observables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const noMisusedObservablesRule = ruleCreator({
4949

5050
const voidReturnChecks: TSESLint.RuleListener = {
5151
CallExpression: checkArguments,
52-
// NewExpression: checkArguments,
52+
NewExpression: checkArguments,
5353
// JSXAttribute: checkJSXAttribute,
5454
// ClassDeclaration: checkClassLikeOrInterfaceNode,
5555
// ClassExpression: checkClassLikeOrInterfaceNode,

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,24 @@ ruleTester({ types: true }).run('no-misused-observables', noMisusedObservablesRu
1212
1313
[1, 2, 3].forEach((i): Observable<number> => { return of(i); });
1414
[1, 2, 3].forEach(i => of(i));
15+
16+
class Foo {
17+
constructor(x: () => void) {}
18+
}
19+
new Foo(() => of(42));
1520
`,
1621
options: [{ checksVoidReturn: false }],
1722
},
1823
stripIndent`
1924
// void return argument; unrelated
2025
[1, 2, 3].forEach(i => i);
2126
[1, 2, 3].forEach(i => { return i; });
27+
28+
class Foo {
29+
constructor(x: () => void) {}
30+
}
31+
new Foo(() => 42);
32+
new Foo;
2233
`,
2334
stripIndent`
2435
// couldReturnType is bugged for block body implicit return types (#57)
@@ -79,6 +90,18 @@ ruleTester({ types: true }).run('no-misused-observables', noMisusedObservablesRu
7990
~~~~~~~~~~~~~~~~~~~~~~ [forbiddenVoidReturnArgument]
8091
`,
8192
),
93+
fromFixture(
94+
stripIndent`
95+
// void return argument; constructor
96+
import { of } from "rxjs";
97+
98+
class Foo {
99+
constructor(x: () => void) {}
100+
}
101+
new Foo(() => of(42));
102+
~~~~~~~~~~~~ [forbiddenVoidReturnArgument]
103+
`,
104+
),
82105
fromFixture(
83106
stripIndent`
84107
// spread variable

0 commit comments

Comments
 (0)