@@ -132,6 +132,13 @@ export default {
132
132
arrayExceptions [ key ] = true ;
133
133
} ;
134
134
135
+ /**
136
+ * Promise method that accepts an array of promises,
137
+ * ( eg. Promise.all), will throw warnings for the each
138
+ * unawaited or non-returned promise. To avoid throwing
139
+ * multiple warnings, we check if there is a warning in
140
+ * the given location.
141
+ */
135
142
const promiseArrayExceptionExists = loc => {
136
143
const key = promiseArrayExceptionKey ( loc ) ;
137
144
return ! ! arrayExceptions [ key ] ;
@@ -234,13 +241,23 @@ export default {
234
241
) {
235
242
let parentNode = getClosestParentCallExpressionNode ( node ) ;
236
243
if ( parentNode ) {
237
- const { options } = context ;
238
- const allowReturn = ! options [ 0 ] || ! options [ 0 ] . alwaysAwait ;
244
+ /**
245
+ * If parent node is an array expression, we'll report the warning,
246
+ * for the array object, not for each individual assertion.
247
+ */
239
248
const isParentArrayExpression =
240
249
parentNode . parent . type === 'ArrayExpression' ;
250
+
251
+ const { options } = context ;
252
+ const allowReturn = ! options [ 0 ] || ! options [ 0 ] . alwaysAwait ;
241
253
const orReturned = allowReturn ? ' or returned' : '' ;
242
254
let messageId = 'asyncMustBeAwaited' ;
243
255
256
+ /**
257
+ * An async assertion can be chained with `then` or `catch` statements.
258
+ * In that case our target CallExpression node is the one with
259
+ * the last `then` or `catch` statement.
260
+ */
244
261
parentNode = getParentIfThenified ( parentNode ) ;
245
262
246
263
// Promise.x([expect()]) || Promise.x(expect())
@@ -256,7 +273,9 @@ export default {
256
273
}
257
274
258
275
if (
276
+ // If node is not awaited or returned
259
277
! checkIfValidReturn ( parentNode . parent , allowReturn ) &&
278
+ // if we didn't warn user already
260
279
! promiseArrayExceptionExists ( parentNode . loc )
261
280
) {
262
281
context . report ( {
0 commit comments