@@ -8,41 +8,41 @@ test.snapshot({
8
8
valid : [
9
9
] ,
10
10
invalid : [
11
- 'await Promise.all ([(0, promise)])' ,
12
- 'async function * foo() {await Promise.all ([yield promise])}' ,
13
- 'async function * foo() {await Promise.all ([yield* promise])}' ,
14
- 'await Promise.all ([() => promise,],)' ,
15
- 'await Promise.all ([a ? b : c,],)' ,
16
- 'await Promise.all ([x ??= y,],)' ,
17
- 'await Promise.all ([x ||= y,],)' ,
18
- 'await Promise.all ([x &&= y,],)' ,
19
- 'await Promise.all ([x |= y,],)' ,
20
- 'await Promise.all ([x ^= y,],)' ,
21
- 'await Promise.all ([x ??= y,],)' ,
22
- 'await Promise.all ([x ||= y,],)' ,
23
- 'await Promise.all ([x &&= y,],)' ,
24
- 'await Promise.all ([x | y,],)' ,
25
- 'await Promise.all ([x ^ y,],)' ,
26
- 'await Promise.all ([x & y,],)' ,
27
- 'await Promise.all ([x !== y,],)' ,
28
- 'await Promise.all ([x == y,],)' ,
29
- 'await Promise.all ([x in y,],)' ,
30
- 'await Promise.all ([x >>> y,],)' ,
31
- 'await Promise.all ([x + y,],)' ,
32
- 'await Promise.all ([x / y,],)' ,
33
- 'await Promise.all ([x ** y,],)' ,
34
- 'await Promise.all ([promise,],)' ,
35
- 'await Promise.all ([getPromise(),],)' ,
36
- 'await Promise.all ([promises[0],],)' ,
37
- 'await Promise.all ([await promise])' ,
11
+ 'await Promise.race ([(0, promise)])' ,
12
+ 'async function * foo() {await Promise.race ([yield promise])}' ,
13
+ 'async function * foo() {await Promise.race ([yield* promise])}' ,
14
+ 'await Promise.race ([() => promise,],)' ,
15
+ 'await Promise.race ([a ? b : c,],)' ,
16
+ 'await Promise.race ([x ??= y,],)' ,
17
+ 'await Promise.race ([x ||= y,],)' ,
18
+ 'await Promise.race ([x &&= y,],)' ,
19
+ 'await Promise.race ([x |= y,],)' ,
20
+ 'await Promise.race ([x ^= y,],)' ,
21
+ 'await Promise.race ([x ??= y,],)' ,
22
+ 'await Promise.race ([x ||= y,],)' ,
23
+ 'await Promise.race ([x &&= y,],)' ,
24
+ 'await Promise.race ([x | y,],)' ,
25
+ 'await Promise.race ([x ^ y,],)' ,
26
+ 'await Promise.race ([x & y,],)' ,
27
+ 'await Promise.race ([x !== y,],)' ,
28
+ 'await Promise.race ([x == y,],)' ,
29
+ 'await Promise.race ([x in y,],)' ,
30
+ 'await Promise.race ([x >>> y,],)' ,
31
+ 'await Promise.race ([x + y,],)' ,
32
+ 'await Promise.race ([x / y,],)' ,
33
+ 'await Promise.race ([x ** y,],)' ,
34
+ 'await Promise.race ([promise,],)' ,
35
+ 'await Promise.race ([getPromise(),],)' ,
36
+ 'await Promise.race ([promises[0],],)' ,
37
+ 'await Promise.race ([await promise])' ,
38
38
'await Promise.any([promise])' ,
39
39
'await Promise.race([promise])' ,
40
- 'await Promise.all ([new Promise(() => {})])' ,
41
- '+await Promise.all ([+1])' ,
40
+ 'await Promise.race ([new Promise(() => {})])' ,
41
+ '+await Promise.race ([+1])' ,
42
42
43
- // ASI, `Promise.all ()` is not really `await`ed
43
+ // ASI, `Promise.race ()` is not really `await`ed
44
44
outdent `
45
- await Promise.all ([(x,y)])
45
+ await Promise.race ([(x,y)])
46
46
[0].toString()
47
47
` ,
48
48
] ,
@@ -51,54 +51,79 @@ test.snapshot({
51
51
// Not `await`ed
52
52
test . snapshot ( {
53
53
valid : [
54
- 'Promise.all ([promise, anotherPromise])' ,
55
- 'Promise.all (notArrayLiteral)' ,
56
- 'Promise.all ([...promises])' ,
54
+ 'Promise.race ([promise, anotherPromise])' ,
55
+ 'Promise.race (notArrayLiteral)' ,
56
+ 'Promise.race ([...promises])' ,
57
57
'Promise.any([promise, anotherPromise])' ,
58
58
'Promise.race([promise, anotherPromise])' ,
59
59
'Promise.notListedMethod([promise])' ,
60
- 'Promise[all ]([promise])' ,
61
- 'Promise.all ([,])' ,
62
- 'NotPromise.all ([promise])' ,
63
- 'Promise?.all ([promise])' ,
64
- 'Promise.all ?.([promise])' ,
65
- 'Promise.all (...[promise])' ,
66
- 'Promise.all ([promise], extraArguments)' ,
67
- 'Promise.all ()' ,
68
- 'new Promise.all ([promise])' ,
60
+ 'Promise[race ]([promise])' ,
61
+ 'Promise.race ([,])' ,
62
+ 'NotPromise.race ([promise])' ,
63
+ 'Promise?.race ([promise])' ,
64
+ 'Promise.race ?.([promise])' ,
65
+ 'Promise.race (...[promise])' ,
66
+ 'Promise.race ([promise], extraArguments)' ,
67
+ 'Promise.race ()' ,
68
+ 'new Promise.race ([promise])' ,
69
69
70
70
// We are not checking these cases
71
- 'globalThis.Promise.all ([promise])' ,
72
- 'Promise["all "]([promise])' ,
71
+ 'globalThis.Promise.race ([promise])' ,
72
+ 'Promise["race "]([promise])' ,
73
73
74
74
// This can't be checked
75
75
'Promise.allSettled([promise])' ,
76
76
] ,
77
77
invalid : [
78
- 'Promise.all ([promise,],)' ,
78
+ 'Promise.race ([promise,],)' ,
79
79
outdent `
80
80
foo
81
- Promise.all ([(0, promise),],)
81
+ Promise.race ([(0, promise),],)
82
82
` ,
83
83
outdent `
84
84
foo
85
- Promise.all ([[array][0],],)
85
+ Promise.race ([[array][0],],)
86
86
` ,
87
- 'Promise.all([promise]).then()' ,
88
- 'Promise.all([1]).then()' ,
89
- 'Promise.all([1.]).then()' ,
90
- 'Promise.all([.1]).then()' ,
91
- 'Promise.all([(0, promise)]).then()' ,
92
- 'const _ = () => Promise.all([ a ?? b ,],)' ,
93
- 'Promise.all([ {a} = 1 ,],)' ,
94
- 'Promise.all([ function () {} ,],)' ,
95
- 'Promise.all([ class {} ,],)' ,
96
- 'Promise.all([ new Foo ,],).then()' ,
97
- 'Promise.all([ new Foo ,],).toString' ,
98
- 'foo(Promise.all([promise]))' ,
99
- 'Promise.all([promise]).foo = 1' ,
100
- 'Promise.all([promise])[0] ||= 1' ,
101
- 'Promise.all([undefined]).then()' ,
102
- 'Promise.all([null]).then()' ,
87
+ 'Promise.race([promise]).then()' ,
88
+ 'Promise.race([1]).then()' ,
89
+ 'Promise.race([1.]).then()' ,
90
+ 'Promise.race([.1]).then()' ,
91
+ 'Promise.race([(0, promise)]).then()' ,
92
+ 'const _ = () => Promise.race([ a ?? b ,],)' ,
93
+ 'Promise.race([ {a} = 1 ,],)' ,
94
+ 'Promise.race([ function () {} ,],)' ,
95
+ 'Promise.race([ class {} ,],)' ,
96
+ 'Promise.race([ new Foo ,],).then()' ,
97
+ 'Promise.race([ new Foo ,],).toString' ,
98
+ 'foo(Promise.race([promise]))' ,
99
+ 'Promise.race([promise]).foo = 1' ,
100
+ 'Promise.race([promise])[0] ||= 1' ,
101
+ 'Promise.race([undefined]).then()' ,
102
+ 'Promise.race([null]).then()' ,
103
+ ] ,
104
+ } ) ;
105
+
106
+ // `Promise.all`
107
+ test . snapshot ( {
108
+ valid : [ ] ,
109
+ invalid : [
110
+ // Only fixable if it's in `ExpressionStatement`
111
+ 'Promise.all([promise])' ,
112
+ 'await Promise.all([promise])' ,
113
+
114
+ 'const foo = () => Promise.all([promise])' ,
115
+ 'const foo = await Promise.all([promise])' ,
116
+ 'foo = await Promise.all([promise])' ,
117
+
118
+ // `Promise.{all, race}()` should not care if the result is used
119
+ 'const foo = await Promise.race([promise])' ,
120
+ 'const foo = () => Promise.race([promise])' ,
121
+ 'foo = await Promise.race([promise])' ,
122
+ 'const results = await Promise.any([promise])' ,
123
+ 'const results = await Promise.race([promise])' ,
124
+
125
+ // Fixable, but not provide at this point
126
+ // https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2388
127
+ 'const [foo] = await Promise.all([promise])' ,
103
128
] ,
104
129
} ) ;
0 commit comments