Skip to content

Commit a6a51e0

Browse files
fix: also handle namespace import of throwError
1 parent 25e9534 commit a6a51e0

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/rules/throw-error.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,21 @@ export const throwErrorRule = ruleCreator({
6969
});
7070
}
7171

72+
function checkNode(node: es.CallExpression) {
73+
if (couldBeObservable(node)) {
74+
const [arg] = node.arguments;
75+
if (arg) {
76+
checkThrowArgument(arg);
77+
}
78+
}
79+
}
80+
7281
return {
7382
'CallExpression[callee.name=\'throwError\']': (node: es.CallExpression) => {
74-
if (couldBeObservable(node)) {
75-
const [arg] = node.arguments;
76-
if (arg) {
77-
checkThrowArgument(arg);
78-
}
79-
}
83+
checkNode(node);
84+
},
85+
'CallExpression[callee.property.name=\'throwError\']': (node: es.CallExpression) => {
86+
checkNode(node);
8087
},
8188
};
8289
},

tests/rules/throw-error.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,5 +255,14 @@ ruleTester({ types: true }).run('throw-error', throwErrorRule, {
255255
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [forbidden]
256256
`,
257257
),
258+
fromFixture(
259+
stripIndent`
260+
// namespace import
261+
import * as Rx from "rxjs";
262+
263+
Rx.throwError(() => "Boom!");
264+
~~~~~~~ [forbidden]
265+
`,
266+
),
258267
],
259268
});

0 commit comments

Comments
 (0)