@@ -5,6 +5,12 @@ import {
55 isAwaited ,
66 isPromiseResolved ,
77 getVariableReferences ,
8+ isMemberExpression ,
9+ isImportSpecifier ,
10+ isImportNamespaceSpecifier ,
11+ isCallExpression ,
12+ isArrayExpression ,
13+ isIdentifier
814} from '../node-utils' ;
915
1016export const RULE_NAME = 'await-async-utils' ;
@@ -13,6 +19,17 @@ type Options = [];
1319
1420const ASYNC_UTILS_REGEXP = new RegExp ( `^(${ ASYNC_UTILS . join ( '|' ) } )$` ) ;
1521
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+
1633export default ESLintUtils . RuleCreator ( getDocsUrl ) < Options , MessageIds > ( {
1734 name : RULE_NAME ,
1835 meta : {
@@ -45,11 +62,11 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
4562
4663 if ( ! LIBRARY_MODULES . includes ( parent . source . value . toString ( ) ) ) return ;
4764
48- if ( node . type === 'ImportSpecifier' ) {
65+ if ( isImportSpecifier ( node ) ) {
4966 importedAsyncUtils . push ( node . imported . name ) ;
5067 }
5168
52- if ( node . type === 'ImportNamespaceSpecifier' ) {
69+ if ( isImportNamespaceSpecifier ( node ) ) {
5370 importedAsyncUtils . push ( node . local . name ) ;
5471 }
5572 } ,
@@ -72,7 +89,7 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
7289 } ,
7390 'Program:exit' ( ) {
7491 const testingLibraryUtilUsage = asyncUtilsUsage . filter ( usage => {
75- if ( usage . node . type === 'MemberExpression' ) {
92+ if ( isMemberExpression ( usage . node ) ) {
7693 const object = usage . node . object as TSESTree . Identifier ;
7794
7895 return importedAsyncUtils . includes ( object . name ) ;
@@ -88,7 +105,8 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
88105 references &&
89106 references . length === 0 &&
90107 ! isAwaited ( node . parent . parent ) &&
91- ! isPromiseResolved ( node )
108+ ! isPromiseResolved ( node ) &&
109+ ! isInPromiseAll ( node )
92110 ) {
93111 context . report ( {
94112 node,
0 commit comments