Skip to content

Commit d099698

Browse files
fix(no-floating-observables): re-add call expression check for performance
Previously the selector was `ExpressionStatement > CallExpression`, but in order to support `ignoreVoid`, the selector was broadened to just `ExpressionStatement`. This could have a performance impact, but re-adding this call expression check should revert to the original performance.
1 parent eca0cba commit d099698

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/rules/no-floating-observables.ts

Lines changed: 4 additions & 3 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, isUnaryExpression } from '../etc';
2+
import { getTypeServices, isCallExpression, isUnaryExpression } from '../etc';
33
import { ruleCreator } from '../utils';
44

55
const defaultOptions: readonly {
@@ -44,7 +44,8 @@ export const noFloatingObservablesRule = ruleCreator({
4444
return {
4545
ExpressionStatement: (node: es.ExpressionStatement) => {
4646
const { expression } = node;
47-
if (couldBeObservable(expression)) {
47+
48+
if (isCallExpression(expression) && couldBeObservable(expression)) {
4849
context.report({
4950
messageId: ignoreVoid ? 'forbidden' : 'forbiddenNoVoid',
5051
node,
@@ -54,7 +55,7 @@ export const noFloatingObservablesRule = ruleCreator({
5455

5556
if (!ignoreVoid && isUnaryExpression(expression)) {
5657
const { operator, argument } = expression;
57-
if (operator === 'void' && couldBeObservable(argument)) {
58+
if (operator === 'void' && isCallExpression(argument) && couldBeObservable(argument)) {
5859
context.report({
5960
messageId: 'forbiddenNoVoid',
6061
node: argument,

0 commit comments

Comments
 (0)