@@ -33,33 +33,26 @@ export default createTestingLibraryRule<[], MessageIds>({
33
33
34
34
create ( context , _ , helpers ) {
35
35
/**
36
- * Determines whether a given list of statements has some call non-related to Testing Library utils .
36
+ * Determines whether some call is non Testing Library related for a given list of statements .
37
37
*/
38
- function hasNonTestingLibraryCall (
38
+ function hasSomeNonTestingLibraryCall (
39
39
statements : TSESTree . Statement [ ]
40
40
) : boolean {
41
- // TODO: refactor to use Array.every
42
- for ( const statement of statements ) {
41
+ return statements . some ( ( statement ) => {
43
42
const callExpression = getStatementCallExpression ( statement ) ;
44
43
45
44
if ( ! callExpression ) {
46
- continue ;
45
+ return false ;
47
46
}
48
47
49
48
const identifier = getDeepestIdentifierNode ( callExpression ) ;
50
49
51
50
if ( ! identifier ) {
52
- continue ;
51
+ return false ;
53
52
}
54
53
55
- if ( helpers . isTestingLibraryUtil ( identifier ) ) {
56
- continue ;
57
- }
58
-
59
- // at this point the statement is a non testing library call
60
- return true ;
61
- }
62
- return false ;
54
+ return ! helpers . isTestingLibraryUtil ( identifier ) ;
55
+ } ) ;
63
56
}
64
57
65
58
function checkNoUnnecessaryActFromBlockStatement (
@@ -94,18 +87,12 @@ export default createTestingLibraryRule<[], MessageIds>({
94
87
node : callExpressionIdentifier ,
95
88
messageId : 'noUnnecessaryActEmptyFunction' ,
96
89
} ) ;
97
-
98
- return ;
99
- }
100
-
101
- if ( hasNonTestingLibraryCall ( blockStatementNode . body ) ) {
102
- return ;
90
+ } else if ( ! hasSomeNonTestingLibraryCall ( blockStatementNode . body ) ) {
91
+ context . report ( {
92
+ node : callExpressionIdentifier ,
93
+ messageId : 'noUnnecessaryActTestingLibraryUtil' ,
94
+ } ) ;
103
95
}
104
-
105
- context . report ( {
106
- node : callExpressionIdentifier ,
107
- messageId : 'noUnnecessaryActTestingLibraryUtil' ,
108
- } ) ;
109
96
}
110
97
111
98
function checkNoUnnecessaryActFromImplicitReturn (
0 commit comments