Skip to content

Commit d021217

Browse files
fix(no-floating-observables): don't call isCallExpression unnecessarily
1 parent f1b79fe commit d021217

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/rules/no-floating-observables.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TSESTree as es } from '@typescript-eslint/utils';
2-
import { getTypeServices, isCallExpression, isUnaryExpression } from '../etc';
2+
import { getTypeServices, isCallExpression } from '../etc';
33
import { ruleCreator } from '../utils';
44

55
const defaultOptions: readonly {
@@ -41,12 +41,8 @@ export const noFloatingObservablesRule = ruleCreator({
4141
const [config = {}] = context.options;
4242
const { ignoreVoid = true } = config;
4343

44-
function checkNode(node: es.Expression) {
45-
if (!ignoreVoid && isUnaryExpression(node) && node.operator === 'void') {
46-
node = node.argument;
47-
}
48-
49-
if (isCallExpression(node) && couldBeObservable(node)) {
44+
function checkNode(node: es.CallExpression) {
45+
if (couldBeObservable(node)) {
5046
context.report({
5147
messageId: ignoreVoid ? 'forbidden' : 'forbiddenNoVoid',
5248
node,
@@ -59,7 +55,11 @@ export const noFloatingObservablesRule = ruleCreator({
5955
checkNode(node);
6056
},
6157
'ExpressionStatement > UnaryExpression': (node: es.UnaryExpression) => {
62-
checkNode(node);
58+
if (ignoreVoid) return;
59+
if (node.operator !== 'void') return;
60+
if (!isCallExpression(node.argument)) return;
61+
62+
checkNode(node.argument);
6363
},
6464
};
6565
},

0 commit comments

Comments
 (0)