@@ -5,6 +5,12 @@ import {
5
5
isAwaited ,
6
6
isPromiseResolved ,
7
7
getVariableReferences ,
8
+ isMemberExpression ,
9
+ isImportSpecifier ,
10
+ isImportNamespaceSpecifier ,
11
+ isCallExpression ,
12
+ isArrayExpression ,
13
+ isIdentifier
8
14
} from '../node-utils' ;
9
15
10
16
export const RULE_NAME = 'await-async-utils' ;
@@ -13,6 +19,17 @@ type Options = [];
13
19
14
20
const ASYNC_UTILS_REGEXP = new RegExp ( `^(${ ASYNC_UTILS . join ( '|' ) } )$` ) ;
15
21
22
+ // verifies the CallExpression is Promise.all()
23
+ function isPromiseAll ( node : TSESTree . CallExpression ) {
24
+ return isMemberExpression ( node . callee ) && isIdentifier ( node . callee . object ) && node . callee . object . name === 'Promise' && isIdentifier ( node . callee . property ) && node . callee . property . name === 'all'
25
+ }
26
+
27
+ // verifies the node is part of an array used in a CallExpression
28
+ function isInPromiseAll ( node : TSESTree . Node ) {
29
+ const parent = node . parent
30
+ return isCallExpression ( parent ) && isArrayExpression ( parent . parent ) && isCallExpression ( parent . parent . parent ) && isPromiseAll ( parent . parent . parent )
31
+ }
32
+
16
33
export default ESLintUtils . RuleCreator ( getDocsUrl ) < Options , MessageIds > ( {
17
34
name : RULE_NAME ,
18
35
meta : {
@@ -45,11 +62,11 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
45
62
46
63
if ( ! LIBRARY_MODULES . includes ( parent . source . value . toString ( ) ) ) return ;
47
64
48
- if ( node . type === 'ImportSpecifier' ) {
65
+ if ( isImportSpecifier ( node ) ) {
49
66
importedAsyncUtils . push ( node . imported . name ) ;
50
67
}
51
68
52
- if ( node . type === 'ImportNamespaceSpecifier' ) {
69
+ if ( isImportNamespaceSpecifier ( node ) ) {
53
70
importedAsyncUtils . push ( node . local . name ) ;
54
71
}
55
72
} ,
@@ -72,7 +89,7 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
72
89
} ,
73
90
'Program:exit' ( ) {
74
91
const testingLibraryUtilUsage = asyncUtilsUsage . filter ( usage => {
75
- if ( usage . node . type === 'MemberExpression' ) {
92
+ if ( isMemberExpression ( usage . node ) ) {
76
93
const object = usage . node . object as TSESTree . Identifier ;
77
94
78
95
return importedAsyncUtils . includes ( object . name ) ;
@@ -88,7 +105,8 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
88
105
references &&
89
106
references . length === 0 &&
90
107
! isAwaited ( node . parent . parent ) &&
91
- ! isPromiseResolved ( node )
108
+ ! isPromiseResolved ( node ) &&
109
+ ! isInPromiseAll ( node )
92
110
) {
93
111
context . report ( {
94
112
node,
0 commit comments