1
1
import { TSESTree as es } from '@typescript-eslint/utils' ;
2
- import { getTypeServices , isCallExpression , isChainExpression } from '../etc' ;
2
+ import { getTypeServices , isCallExpression , isChainExpression , isUnaryExpression } from '../etc' ;
3
3
import { ruleCreator } from '../utils' ;
4
4
5
5
const defaultOptions : readonly {
@@ -50,21 +50,25 @@ export const noFloatingObservablesRule = ruleCreator({
50
50
}
51
51
}
52
52
53
+ function checkVoid ( node : es . UnaryExpression ) {
54
+ if ( ignoreVoid ) return ;
55
+ if ( node . operator !== 'void' ) return ;
56
+
57
+ let expression = node . argument ;
58
+ if ( isChainExpression ( expression ) ) {
59
+ expression = expression . expression ;
60
+ }
61
+
62
+ if ( ! isCallExpression ( expression ) ) return ;
63
+ checkNode ( expression ) ;
64
+ }
65
+
53
66
return {
54
67
'ExpressionStatement > CallExpression' : ( node : es . CallExpression ) => {
55
68
checkNode ( node ) ;
56
69
} ,
57
70
'ExpressionStatement > UnaryExpression' : ( node : es . UnaryExpression ) => {
58
- if ( ignoreVoid ) return ;
59
- if ( node . operator !== 'void' ) return ;
60
-
61
- let expression = node . argument ;
62
- if ( isChainExpression ( expression ) ) {
63
- expression = expression . expression ;
64
- }
65
-
66
- if ( ! isCallExpression ( expression ) ) return ;
67
- checkNode ( expression ) ;
71
+ checkVoid ( node ) ;
68
72
} ,
69
73
'ExpressionStatement > ChainExpression' : ( node : es . ChainExpression ) => {
70
74
if ( ! isCallExpression ( node . expression ) ) return ;
@@ -78,6 +82,16 @@ export const noFloatingObservablesRule = ruleCreator({
78
82
}
79
83
} ) ;
80
84
} ,
85
+ 'ExpressionStatement > ArrayExpression' : ( node : es . ArrayExpression ) => {
86
+ node . elements . forEach ( expression => {
87
+ if ( ! expression ) return ;
88
+ if ( isCallExpression ( expression ) ) {
89
+ checkNode ( expression ) ;
90
+ } else if ( isUnaryExpression ( expression ) ) {
91
+ checkVoid ( expression ) ;
92
+ }
93
+ } ) ;
94
+ } ,
81
95
} ;
82
96
} ,
83
97
} ) ;
0 commit comments