@@ -26,6 +26,28 @@ export default createTestingLibraryRule<Options, MessageIds>({
2626 } ,
2727 defaultOptions : [ ] ,
2828 create : function ( context , _ , helpers ) {
29+ function isCallerWaitFor (
30+ node : TSESTree . BlockStatement | TSESTree . CallExpression
31+ ) {
32+ if ( ! node . parent ) {
33+ return false ;
34+ }
35+ const callExpressionNode = node . parent . parent as TSESTree . CallExpression ;
36+ const callExpressionIdentifier = getPropertyIdentifierNode (
37+ callExpressionNode
38+ ) ;
39+
40+ if ( ! callExpressionIdentifier ) {
41+ return false ;
42+ }
43+
44+ if ( ! helpers . isAsyncUtil ( callExpressionIdentifier , [ 'waitFor' ] ) ) {
45+ return false ;
46+ }
47+
48+ return true ;
49+ }
50+
2951 function getSideEffectNodes (
3052 body : TSESTree . Node [ ]
3153 ) : TSESTree . ExpressionStatement [ ] {
@@ -47,19 +69,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
4769 }
4870
4971 function reportSideEffects ( node : TSESTree . BlockStatement ) {
50- if ( ! node . parent ) {
51- return ;
52- }
53- const callExpressionNode = node . parent . parent as TSESTree . CallExpression ;
54- const callExpressionIdentifier = getPropertyIdentifierNode (
55- callExpressionNode
56- ) ;
57-
58- if ( ! callExpressionIdentifier ) {
59- return ;
60- }
61-
62- if ( ! helpers . isAsyncUtil ( callExpressionIdentifier , [ 'waitFor' ] ) ) {
72+ if ( ! isCallerWaitFor ( node ) ) {
6373 return ;
6474 }
6575
@@ -77,19 +87,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
7787 }
7888
7989 function reportImplicitReturnSideEffect ( node : TSESTree . CallExpression ) {
80- if ( ! node . parent ) {
81- return ;
82- }
83- const callExpressionNode = node . parent . parent as TSESTree . CallExpression ;
84- const callExpressionIdentifier = getPropertyIdentifierNode (
85- callExpressionNode
86- ) ;
87-
88- if ( ! callExpressionIdentifier ) {
89- return ;
90- }
91-
92- if ( ! helpers . isAsyncUtil ( callExpressionIdentifier , [ 'waitFor' ] ) ) {
90+ if ( ! isCallerWaitFor ) {
9391 return ;
9492 }
9593
0 commit comments