From cfdfa22a07504228ad4b517986725c809eaabee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Bisson?= Date: Fri, 21 Jun 2024 22:49:43 +0200 Subject: [PATCH 01/12] `no-single-promise-in-promise-methods`: Suggest instead of fix when result is stored in array (#2385) --- rules/no-single-promise-in-promise-methods.js | 13 ++- test/no-single-promise-in-promise-methods.mjs | 4 + ...o-single-promise-in-promise-methods.mjs.md | 82 +++++++++++++++++- ...single-promise-in-promise-methods.mjs.snap | Bin 2274 -> 2448 bytes 4 files changed, 97 insertions(+), 2 deletions(-) diff --git a/rules/no-single-promise-in-promise-methods.js b/rules/no-single-promise-in-promise-methods.js index 94e30744a7..3f679a2400 100644 --- a/rules/no-single-promise-in-promise-methods.js +++ b/rules/no-single-promise-in-promise-methods.js @@ -33,6 +33,9 @@ const isPromiseMethodCallWithSingleElementArray = node => && node.arguments[0].elements[0] && node.arguments[0].elements[0].type !== 'SpreadElement'; +const isStoredInArray = node => isMethodCall(node, {methods: ['all']}) + && ['VariableDeclarator', 'AssignmentExpression'].includes(node.parent.parent.type); + const unwrapAwaitedCallExpression = (callExpression, sourceCode) => fixer => { const [promiseNode] = callExpression.arguments[0].elements; let text = getParenthesizedText(promiseNode, sourceCode); @@ -133,7 +136,15 @@ const create = context => ({ callExpression.parent.type === 'AwaitExpression' && callExpression.parent.argument === callExpression ) { - problem.fix = unwrapAwaitedCallExpression(callExpression, sourceCode); + if (isStoredInArray(callExpression)) { + problem.suggest = [{ + messageId: MESSAGE_ID_SUGGESTION_UNWRAP, + fix: unwrapAwaitedCallExpression(callExpression, sourceCode), + }]; + } else { + problem.fix = unwrapAwaitedCallExpression(callExpression, sourceCode); + } + return problem; } diff --git a/test/no-single-promise-in-promise-methods.mjs b/test/no-single-promise-in-promise-methods.mjs index 4e73df0926..bd11df9c4f 100644 --- a/test/no-single-promise-in-promise-methods.mjs +++ b/test/no-single-promise-in-promise-methods.mjs @@ -39,6 +39,10 @@ test.snapshot({ 'await Promise.race([promise])', 'await Promise.all([new Promise(() => {})])', '+await Promise.all([+1])', + 'const results = await Promise.all([promise])', + 'results = await Promise.all([promise])', + 'const results = await Promise.any([promise])', + 'const results = await Promise.race([promise])', // ASI, `Promise.all()` is not really `await`ed outdent` diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.md b/test/snapshots/no-single-promise-in-promise-methods.mjs.md index 4433570d96..c44d525b69 100644 --- a/test/snapshots/no-single-promise-in-promise-methods.mjs.md +++ b/test/snapshots/no-single-promise-in-promise-methods.mjs.md @@ -655,7 +655,87 @@ Generated by [AVA](https://avajs.dev). | ^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ ` -## invalid(32): await Promise.all([(x,y)]) [0].toString() +## invalid(32): const results = await Promise.all([promise]) + +> Input + + `␊ + 1 | const results = await Promise.all([promise])␊ + ` + +> Error 1/1 + + `␊ + > 1 | const results = await Promise.all([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/1: Use the value directly.␊ + 1 | const results = await promise␊ + ` + +## invalid(33): results = await Promise.all([promise]) + +> Input + + `␊ + 1 | results = await Promise.all([promise])␊ + ` + +> Error 1/1 + + `␊ + > 1 | results = await Promise.all([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/1: Use the value directly.␊ + 1 | results = await promise␊ + ` + +## invalid(34): const results = await Promise.any([promise]) + +> Input + + `␊ + 1 | const results = await Promise.any([promise])␊ + ` + +> Output + + `␊ + 1 | const results = await promise␊ + ` + +> Error 1/1 + + `␊ + > 1 | const results = await Promise.any([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.any()\` is unnecessary.␊ + ` + +## invalid(35): const results = await Promise.race([promise]) + +> Input + + `␊ + 1 | const results = await Promise.race([promise])␊ + ` + +> Output + + `␊ + 1 | const results = await promise␊ + ` + +> Error 1/1 + + `␊ + > 1 | const results = await Promise.race([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ` + +## invalid(36): await Promise.all([(x,y)]) [0].toString() > Input diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.snap b/test/snapshots/no-single-promise-in-promise-methods.mjs.snap index 6c58d9ef78bb5ac9b9a3d7df1ff568b36610cb4e..6db0ac3cb3660ee2d262c97c546bb8f3b2416104 100644 GIT binary patch literal 2448 zcmV;B32*j6RzV*Bbv!fW>5V?*85Iw zXKIp3zmo-OVCX0YajdE z$9SBnGwtk}#{b;=|6h*p@wNTN@)66aJ?fsEIc0dJXBq3GrhQbm%q2xD%o6>WZhGXN zy7QRn8mewt%AztpLe@5aP^c74*VfnERmXFmI<>T0)13`;*^SjJuUTEp|D6d-jikcuAdAG>^a!wU~S6+L*z3j;&*k^>=xkPVXjRKbTl zSl8FqOnZg6roCbrqlRTXX4oFl>vg?Jj+x#nIUN0(!eL^%q+#1e&2U}4-cRHQaF(e=U(9G{=m`n zUxCGT0DQ@`)R!ngnCikve+H3$K_l&A_^hy5pK9+YxHF(&A_WCSE(Z63gbt*{peW$r zcJM7T9dJ+-fba_d;j6SD6f-1YOHmjPP?%)Y{UfzmZF z2zoRg!s{S}=Q$z3VaNoqmF5=%^QUq1*U7@d9BJa#PXfb++15u?Fyr?CovWeo{;|02 zuL0Yile)E}l4hed5#@4eC1CU^!j}PVMGW&h~p3P`NU} zILqx=377P`H%>D;&vjDG!0Bpgr>j{wUCou#%rFGHu9UFBE?PLHK_dMpd4$8z8_E!$;gFIg;RP__e+6lJ@0X!m8C4j?CG zo6$yccQ~cXwqS3Q2e*G{mqoj?-OQeBESDMW|5ggP?fZaTCARHxsZQ_si5`yz za2f>gGADqDKL6bU;%djn{)~>B`k#k(7Fz2i3`$OAcvQD`}?t>`Zyv}-rht#XphX;wu|K!uWqTK_z-{)xbP=GSun8n)8bebm-gA6s*5 z*C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zt$O44>aJ=UmQ9`^(_~{W0K`ueGTS_ejQ5$dfJWIF8n++{<$nOme_SZ}MX4XIW32W9 zs9|e_4L7nxD=j_um%RY#%npOIi!lDv$~u`QGKJD2p!7bhW&#Bi%PRoOOK7cxD(o8B z3*ZUPe6vJage)%;j#XKXY%2I)ZPNT!lXVJV_!lt63ZbA~2cZ3kgNBL4e)QWj*umLn zn!a#QbO;4-a23W~)fLO4q+}`v!pbDGnZ#*#RHz3hss0M>jW ztg6nmw?Wh4CluRq6v26AR?f~d08#$%$DTQ) zPy&Ak1YYGK(3RU!47!uvCKSTRSw5x!$FJiV#T_r|w>jlukX$muDd^4gP*`n~`ohz1GUl)V$HV$|jX7c9ApuqhMfV;v5&X?L5#QF2hK62rh zS>x}X{AJYyS!gSn^-%G@u2xvx;>5Gm#@TrW`P%{lvBgg4aKCSn+Trvp6G wP}g+^a2%fj0|k_|F9B;GqpU#{8fLvfn9!W+HfU18FvDd14+N574vk*`00)^;*Z=?k From 7c9901a884bcc264d86274b6c14adaf95628295a Mon Sep 17 00:00:00 2001 From: fisker Date: Sat, 22 Jun 2024 18:45:55 +0800 Subject: [PATCH 02/12] Only fix `Promise.all` if it's a `ExpressionStatement` --- rules/no-single-promise-in-promise-methods.js | 39 ++++++++++-------- ...o-single-promise-in-promise-methods.mjs.md | 10 ++--- ...single-promise-in-promise-methods.mjs.snap | Bin 2448 -> 2456 bytes 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/rules/no-single-promise-in-promise-methods.js b/rules/no-single-promise-in-promise-methods.js index 3f679a2400..da573029e7 100644 --- a/rules/no-single-promise-in-promise-methods.js +++ b/rules/no-single-promise-in-promise-methods.js @@ -2,7 +2,10 @@ const { isCommaToken, } = require('@eslint-community/eslint-utils'); -const {isMethodCall} = require('./ast/index.js'); +const { + isMethodCall, + isExpressionStatement, +} = require('./ast/index.js'); const { getParenthesizedText, isParenthesized, @@ -33,9 +36,6 @@ const isPromiseMethodCallWithSingleElementArray = node => && node.arguments[0].elements[0] && node.arguments[0].elements[0].type !== 'SpreadElement'; -const isStoredInArray = node => isMethodCall(node, {methods: ['all']}) - && ['VariableDeclarator', 'AssignmentExpression'].includes(node.parent.parent.type); - const unwrapAwaitedCallExpression = (callExpression, sourceCode) => fixer => { const [promiseNode] = callExpression.arguments[0].elements; let text = getParenthesizedText(promiseNode, sourceCode); @@ -122,28 +122,28 @@ const create = context => ({ return; } + const methodName = callExpression.callee.property.name; + const problem = { node: callExpression.arguments[0], messageId: MESSAGE_ID_ERROR, data: { - method: callExpression.callee.property.name, + method: methodName, }, }; const {sourceCode} = context; + const isAwaited = callExpression.parent.type === 'AwaitExpression' + && callExpression.parent.argument === callExpression if ( - callExpression.parent.type === 'AwaitExpression' - && callExpression.parent.argument === callExpression + isAwaited + && ( + methodName !== 'all' + || isExpressionStatement(callExpression.parent.parent) + ) ) { - if (isStoredInArray(callExpression)) { - problem.suggest = [{ - messageId: MESSAGE_ID_SUGGESTION_UNWRAP, - fix: unwrapAwaitedCallExpression(callExpression, sourceCode), - }]; - } else { - problem.fix = unwrapAwaitedCallExpression(callExpression, sourceCode); - } + problem.fix = unwrapAwaitedCallExpression(callExpression, sourceCode); return problem; } @@ -153,11 +153,14 @@ const create = context => ({ messageId: MESSAGE_ID_SUGGESTION_UNWRAP, fix: unwrapNonAwaitedCallExpression(callExpression, sourceCode), }, - { + ]; + + if (!isAwaited) { + problem.suggest.push({ messageId: MESSAGE_ID_SUGGESTION_SWITCH_TO_PROMISE_RESOLVE, fix: switchToPromiseResolve(callExpression, sourceCode), - }, - ]; + }) + } return problem; }, diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.md b/test/snapshots/no-single-promise-in-promise-methods.mjs.md index c44d525b69..f4263e830e 100644 --- a/test/snapshots/no-single-promise-in-promise-methods.mjs.md +++ b/test/snapshots/no-single-promise-in-promise-methods.mjs.md @@ -642,17 +642,15 @@ Generated by [AVA](https://avajs.dev). 1 | +await Promise.all([+1])␊ ` -> Output - - `␊ - 1 | +await +1␊ - ` - > Error 1/1 `␊ > 1 | +await Promise.all([+1])␊ | ^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/1: Use the value directly.␊ + 1 | +await (+1)␊ ` ## invalid(32): const results = await Promise.all([promise]) diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.snap b/test/snapshots/no-single-promise-in-promise-methods.mjs.snap index 6db0ac3cb3660ee2d262c97c546bb8f3b2416104..6e41d0f2a8f9177e488437ae167bd025c898d2f0 100644 GIT binary patch literal 2456 zcmV;J31{{}RzVlthFkg(1h%z!Fe2o3zLxK>BdeMNzk|5v02YLC_#T(4bEga1*p}S9Q@v zmO*w|CYTX<$wQv|7!Ea}MxLEz@t@28|8(v>yd;0Me%W>#FL>AIZqdE)C}8JR+XssvFqPz`O(2Q;s>92b!2Q= zav+2dvP;sRI{1+9G>xq-%h@2FWlEypn% zrso;WwiXQAI^S%%O`=!yFoFwV1l3LiUfXGq^_J7{E!QC>vhKQyO0FR%(zZ-{Ej*Q) zx|a^;8Q|!Xp`+Qq0*mb_@FjCnU!nkEstY6iH;DAlG}1nX&kCFMsSl2VZ-f*~XP}_O z#o$?x&{G*PC{3NwtFtdgbW@MI=x6G&NJ z1Yt~Y%5qW*i?$5Zz6vWdP{51xEfC;!UU5zhN3K2}Y#SQj9bG{yFgbM|{Mk?H&l= z`V`CVdLDMyv)f(I#qN3`>@HKg8IAqDY4ZR*uil$C2k!awy@_+s6Q|B-PJ*o9w%;d#%7ZD!S#JLfxcw5Ja7nKR<20l5+#&TGoUUhfx}JyA^+Gw#Y%|AmaC$tm z)8lzKJzfB(ql(S!E+1LSqheE)3>CY3Z2uKI8p7dL>}c`LY%kfC_ptcpIWAayvkmWM z@h$K7VC-hLmX?!)-JwVZyE}*WZ#Nylq1sI=N|o7KE-x?VP*JE#hKkZXw*QI}4WS@w zz$&x9Eaxy^mNUWSDC$Jsgy(64n;DQ z?arb7mu)(Lf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Date: Sat, 22 Jun 2024 18:48:03 +0800 Subject: [PATCH 03/12] More tests --- rules/no-single-promise-in-promise-methods.js | 5 ++- test/no-single-promise-in-promise-methods.mjs | 1 + ...o-single-promise-in-promise-methods.mjs.md | 31 +++++++++++++++--- ...single-promise-in-promise-methods.mjs.snap | Bin 2456 -> 2503 bytes 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/rules/no-single-promise-in-promise-methods.js b/rules/no-single-promise-in-promise-methods.js index da573029e7..99039e82a3 100644 --- a/rules/no-single-promise-in-promise-methods.js +++ b/rules/no-single-promise-in-promise-methods.js @@ -134,7 +134,7 @@ const create = context => ({ const {sourceCode} = context; const isAwaited = callExpression.parent.type === 'AwaitExpression' - && callExpression.parent.argument === callExpression + && callExpression.parent.argument === callExpression; if ( isAwaited @@ -144,7 +144,6 @@ const create = context => ({ ) ) { problem.fix = unwrapAwaitedCallExpression(callExpression, sourceCode); - return problem; } @@ -159,7 +158,7 @@ const create = context => ({ problem.suggest.push({ messageId: MESSAGE_ID_SUGGESTION_SWITCH_TO_PROMISE_RESOLVE, fix: switchToPromiseResolve(callExpression, sourceCode), - }) + }); } return problem; diff --git a/test/no-single-promise-in-promise-methods.mjs b/test/no-single-promise-in-promise-methods.mjs index bd11df9c4f..6dcccf0a8d 100644 --- a/test/no-single-promise-in-promise-methods.mjs +++ b/test/no-single-promise-in-promise-methods.mjs @@ -40,6 +40,7 @@ test.snapshot({ 'await Promise.all([new Promise(() => {})])', '+await Promise.all([+1])', 'const results = await Promise.all([promise])', + 'const foo = () => Promise.all([promise])', 'results = await Promise.all([promise])', 'const results = await Promise.any([promise])', 'const results = await Promise.race([promise])', diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.md b/test/snapshots/no-single-promise-in-promise-methods.mjs.md index f4263e830e..55b0126d54 100644 --- a/test/snapshots/no-single-promise-in-promise-methods.mjs.md +++ b/test/snapshots/no-single-promise-in-promise-methods.mjs.md @@ -672,7 +672,30 @@ Generated by [AVA](https://avajs.dev). 1 | const results = await promise␊ ` -## invalid(33): results = await Promise.all([promise]) +## invalid(33): const foo = () => Promise.all([promise]) + +> Input + + `␊ + 1 | const foo = () => Promise.all([promise])␊ + ` + +> Error 1/1 + + `␊ + > 1 | const foo = () => Promise.all([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | const foo = () => promise␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | const foo = () => Promise.resolve(promise)␊ + ` + +## invalid(34): results = await Promise.all([promise]) > Input @@ -691,7 +714,7 @@ Generated by [AVA](https://avajs.dev). 1 | results = await promise␊ ` -## invalid(34): const results = await Promise.any([promise]) +## invalid(35): const results = await Promise.any([promise]) > Input @@ -712,7 +735,7 @@ Generated by [AVA](https://avajs.dev). | ^^^^^^^^^ Wrapping single-element array with \`Promise.any()\` is unnecessary.␊ ` -## invalid(35): const results = await Promise.race([promise]) +## invalid(36): const results = await Promise.race([promise]) > Input @@ -733,7 +756,7 @@ Generated by [AVA](https://avajs.dev). | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(36): await Promise.all([(x,y)]) [0].toString() +## invalid(37): await Promise.all([(x,y)]) [0].toString() > Input diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.snap b/test/snapshots/no-single-promise-in-promise-methods.mjs.snap index 6e41d0f2a8f9177e488437ae167bd025c898d2f0..d7572f36ec61038740932180c698c3843211ad83 100644 GIT binary patch literal 2503 zcmV;&2{`saRzV%NmLpOy-SY> z5zm%1yB~`P00000000B+oKI}zRvpKatqM{k4m|*Z7V*mNX6>0|5>GbCCT$W#TMDNF zt5T|Hrt6(JiG^!NW6y3zo0Y0^0mK1`e~UOE7TOBIjS5w*kg8U+P$898Mdd`R9yp@j zdMuiW{p_Fp`@Q$Z<4l~{o!hR)-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FV!}(mLxUYW`$E%~42lh*0$xc0<8Ii7=dtm_?+oNfpy2%lfcF*- z9+Wu-mv)u#j0=rf6pKuin@$1Nx!3dSuG>wO*?Y)TIYbDB?LPpvzu~Z9V#i=s4Nm(A zG#ybw!j^+R(4?m}5fV8E_W-2%!yjmpkU|OkFCg%?41uBCv0^Yh=_5iRjGQ;k&hGE5 zD)<(X^fb$nK)L%n;O^~^JDv>Q(GC@GozpMoKE9It1$vc5;=L)U4Txxqva_kbMD#Rf z_~WvC6_m8wfV6i7Tc)8Br??FRXyKk|c)G=5jk#$GGv>VWSWj(H(0Es;YTXyXA-v53 z-p+7&qcSLP9{}Lq;{z8-9S`E7^DRDd$(VV}rFJq}&YHPyIp!K?8$*J*v<%AJzW{T8 zLYYIPxJ$TUppKq%@w*5*RACblT?1Z7Qs=a6n**H0HDI8Cvi3*7+V4@;pb87KVIWND Woazy1Qo%5jWPJv*p$ZOXX8-_!zNb3? From 73d6f6ac1e7c7fa52898824f6063cbc46fdcfefe Mon Sep 17 00:00:00 2001 From: fisker Date: Sat, 22 Jun 2024 18:49:33 +0800 Subject: [PATCH 04/12] One more test --- test/no-single-promise-in-promise-methods.mjs | 3 +++ ...o-single-promise-in-promise-methods.mjs.md | 21 +++++++++++++++++- ...single-promise-in-promise-methods.mjs.snap | Bin 2503 -> 2539 bytes 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/test/no-single-promise-in-promise-methods.mjs b/test/no-single-promise-in-promise-methods.mjs index 6dcccf0a8d..510e7c8db4 100644 --- a/test/no-single-promise-in-promise-methods.mjs +++ b/test/no-single-promise-in-promise-methods.mjs @@ -45,6 +45,9 @@ test.snapshot({ 'const results = await Promise.any([promise])', 'const results = await Promise.race([promise])', + // Fixable, but not provide at this point + 'const [foo] = await Promise.all([promise])', + // ASI, `Promise.all()` is not really `await`ed outdent` await Promise.all([(x,y)]) diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.md b/test/snapshots/no-single-promise-in-promise-methods.mjs.md index 55b0126d54..0b7a275cd9 100644 --- a/test/snapshots/no-single-promise-in-promise-methods.mjs.md +++ b/test/snapshots/no-single-promise-in-promise-methods.mjs.md @@ -756,7 +756,26 @@ Generated by [AVA](https://avajs.dev). | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(37): await Promise.all([(x,y)]) [0].toString() +## invalid(37): const [foo] = await Promise.all([promise]) + +> Input + + `␊ + 1 | const [foo] = await Promise.all([promise])␊ + ` + +> Error 1/1 + + `␊ + > 1 | const [foo] = await Promise.all([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/1: Use the value directly.␊ + 1 | const [foo] = await promise␊ + ` + +## invalid(38): await Promise.all([(x,y)]) [0].toString() > Input diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.snap b/test/snapshots/no-single-promise-in-promise-methods.mjs.snap index d7572f36ec61038740932180c698c3843211ad83..5ca7bad61007cd613e58d8f73e02736bc3ee3a3b 100644 GIT binary patch literal 2539 zcmV z#t}3V``JJH_j~V+$C)^@o7=A9@4WZ@e)4%0E-l^a%I2adHrYrB_C z$KKKmeU+J4OgmtYw7n;7->R98qit&QGi>khKlFxf`>wg??|Om%^o^}8GcdoseA~pQ zCVD@UpP0B~QlDbXUq*NEnAvWdU3SF|cG<<`$LJTC?X!;S zS}n`>&33mI4%>dP-S*ndm@}dX9*QEU_agASZi{Vq+*V+FE~~I@&(m~v6`4raww$eK zDh>TwHk?O+qxVOS=KlyRwg&`D>G2Qi}TAM!0V#ooEeT%gpa{#kN)F5W*A8!aJcN>1em7K&u59;6 z05|3-yPHMW-OO)yvk<$RrLeoo?Is%gTg&DVdS1V^ZjRjZgXq+ZG&wbV`!0Bdgr<+AM-7J;UWSco%fYZ~t zot`ej>FE+U9an6!yS!_yh>Fcsa#Za8wZm8JcnHT^vE$7**_4V}vDhgN0QBnHW4qs8?A(Uhf zSS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J)!fUq6@e8JPM+s(Ji$u_5Lvtp;3>*2PRB<;)*<2u=}MA{IFj3!I2; z&tq%su;i%HunuUL2V;`!p(K0^Nca$vprENj!AT;Zu0}x8nJE1u9a+6MvWr*kptZ{a zFERUDzUN%Av=5$oR=-4#G5z(_?a^6e7dW!Liy?W-*Zlz4Xm~>uF7R;2sl^D_!b;Xj zLRDI<1}#(Z#I-1&xFk(bu8B+96yeK#m7)yShc5t(em|i$|EV=i1tB$96Sc~tTard6 zZK@ssE-xx&r_f{-72ZoAyg#air`&`U6W^ds*%Hr>xbUOx&vf;M&Nk;8wZOX=v~71s zLnWo$dJus*z@A63ef)9bSHATqvHF~$Y2uH8_gd)Q zLKYU7#3R!g(4_|{{RU7MKt@yLIU*00lV;gqq8j!Z`5TV7;qM})5!JD#Y*E>%C&{IzbrzHc+V$ z3fg-Bw148DVPeutzhi?PJo{49mkx@CPy=sKfpNDS)Awoo@S9l$5-51D1MptJ!Gkil zz@=R+I^$Af7RRDeBjr_IDgMOzakzRm0Oh0Zm7o zkhJCC&)^xEO@vg=;XMFZ{_tn;6r@lB{{skoQ-#1t?v`ROI_VQaA&gu!%`P79tZMic zlJYbwkU+V61910J#GOb6?`X#gxZdfPb01$ze}P|RQFzr)W&jm#DWk9Tvv(SLU#!rLO??VOM| zE`tL1HUREbF>tZetwCITzU4i9XAzl-2Ql{OLaHQ<#rb#BLT1i&d=0|p8xYp(#-{)DmyRVd8HfiSIiswbdH R1;b2}^?#M;U|Je#007-nzeE54 From ba33c8dbb6dcb8ecb4bb5aea59c336855dfa0264 Mon Sep 17 00:00:00 2001 From: fisker Date: Sat, 22 Jun 2024 18:52:51 +0800 Subject: [PATCH 05/12] Remove invalid suggestions too --- rules/no-single-promise-in-promise-methods.js | 18 ++++++------- ...o-single-promise-in-promise-methods.mjs.md | 24 +++++++++++++++--- ...single-promise-in-promise-methods.mjs.snap | Bin 2539 -> 2558 bytes 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/rules/no-single-promise-in-promise-methods.js b/rules/no-single-promise-in-promise-methods.js index 99039e82a3..ac194c48ac 100644 --- a/rules/no-single-promise-in-promise-methods.js +++ b/rules/no-single-promise-in-promise-methods.js @@ -133,11 +133,10 @@ const create = context => ({ }; const {sourceCode} = context; - const isAwaited = callExpression.parent.type === 'AwaitExpression' - && callExpression.parent.argument === callExpression; if ( - isAwaited + callExpression.parent.type === 'AwaitExpression' + && callExpression.parent.argument === callExpression && ( methodName !== 'all' || isExpressionStatement(callExpression.parent.parent) @@ -147,19 +146,20 @@ const create = context => ({ return problem; } + if (methodName !== 'all') { + return problem; + } + problem.suggest = [ { messageId: MESSAGE_ID_SUGGESTION_UNWRAP, fix: unwrapNonAwaitedCallExpression(callExpression, sourceCode), }, - ]; - - if (!isAwaited) { - problem.suggest.push({ + { messageId: MESSAGE_ID_SUGGESTION_SWITCH_TO_PROMISE_RESOLVE, fix: switchToPromiseResolve(callExpression, sourceCode), - }); - } + }, + ]; return problem; }, diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.md b/test/snapshots/no-single-promise-in-promise-methods.mjs.md index 0b7a275cd9..079de58b79 100644 --- a/test/snapshots/no-single-promise-in-promise-methods.mjs.md +++ b/test/snapshots/no-single-promise-in-promise-methods.mjs.md @@ -649,8 +649,12 @@ Generated by [AVA](https://avajs.dev). | ^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ ␊ --------------------------------------------------------------------------------␊ - Suggestion 1/1: Use the value directly.␊ + Suggestion 1/2: Use the value directly.␊ 1 | +await (+1)␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | +await Promise.resolve(+1)␊ ` ## invalid(32): const results = await Promise.all([promise]) @@ -668,8 +672,12 @@ Generated by [AVA](https://avajs.dev). | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ ␊ --------------------------------------------------------------------------------␊ - Suggestion 1/1: Use the value directly.␊ + Suggestion 1/2: Use the value directly.␊ 1 | const results = await promise␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | const results = await Promise.resolve(promise)␊ ` ## invalid(33): const foo = () => Promise.all([promise]) @@ -710,8 +718,12 @@ Generated by [AVA](https://avajs.dev). | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ ␊ --------------------------------------------------------------------------------␊ - Suggestion 1/1: Use the value directly.␊ + Suggestion 1/2: Use the value directly.␊ 1 | results = await promise␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | results = await Promise.resolve(promise)␊ ` ## invalid(35): const results = await Promise.any([promise]) @@ -771,8 +783,12 @@ Generated by [AVA](https://avajs.dev). | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ ␊ --------------------------------------------------------------------------------␊ - Suggestion 1/1: Use the value directly.␊ + Suggestion 1/2: Use the value directly.␊ 1 | const [foo] = await promise␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | const [foo] = await Promise.resolve(promise)␊ ` ## invalid(38): await Promise.all([(x,y)]) [0].toString() diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.snap b/test/snapshots/no-single-promise-in-promise-methods.mjs.snap index 5ca7bad61007cd613e58d8f73e02736bc3ee3a3b..b818ec534e223157aab7b7896db1ec37e49a10a9 100644 GIT binary patch literal 2558 zcmV=B4+rigQZnb*A${} zeeTunt{;mC00000000B+olk7!)E&n&TT!H3svg>^po-V-Zq}YjoOrTHNVZ833#C0l zSyh0d8P+>-6063J#-81bHY*{xP}D=E{@bbt)NKKw_Ec6C0wK|&7K)ITR;`v3i#VX3 zs@}FY&`j)S|LouUGahH+csDmz@ps<)en0uW_w)0Z-)x+--PRAi%Zpb`-|}s9XUcNU z8@9Es=;{(NE*O?i9%;KzS)QpGwymrwGm~U{?;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Mr2*?^a5$p@9V^@zr@8t2KbtTsV$x z&kLaz%Au5f1StD(G9kIHASr@wY{-lKy$8G~p*$pJ3E(v^nHUWwe^_7v19P(6MXtw3yjk+BO1I~hWI{D%O5Un9VY!)E)B@8h`4A<)b zu9s1`3<*}_0F-9v<%h|TV#Irdr3^+j0Y?fwLgIQ9q~8FLeuaZnlNG4(K&f^TSgNVR zw48>iCMrq_Fx4bgNd=~wtSpTOOtq6xm}>IMR7<}0g6!l3SmDp#$(2yR{sjR03kn#n zCTlat0=mS^%MV|2v{DTD0|P7kG~he6fvZ2^3H)-v(H|hSo}` zBCe6+0G<}kw@jpE$l{qOtjb2_P$7QbV((Rp*9gM!x57$=P|!XEp#2#K4HJ{z`W+kW z;Ot9HUpgonLJho42gcoUOy8&R!yjrENTA^T9)R}-4jz=b32yCb(Tq!tSsaT>m0QRF z)_Y9-Yo6CnmFzuKsvIJO!uAgU+aGY)FtM9pRSl;HxK5WOO7000He B*C7A^ From 22c13257faf62d536ac9663cc64113684f7e4b19 Mon Sep 17 00:00:00 2001 From: fisker Date: Sat, 22 Jun 2024 18:53:30 +0800 Subject: [PATCH 06/12] Update comments --- rules/no-single-promise-in-promise-methods.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rules/no-single-promise-in-promise-methods.js b/rules/no-single-promise-in-promise-methods.js index ac194c48ac..1a1764ffc9 100644 --- a/rules/no-single-promise-in-promise-methods.js +++ b/rules/no-single-promise-in-promise-methods.js @@ -80,7 +80,7 @@ const unwrapNonAwaitedCallExpression = (callExpression, sourceCode) => fixer => const switchToPromiseResolve = (callExpression, sourceCode) => function * (fixer) { /* ``` - Promise.all([promise,]) + Promise.race([promise,]) // ^^^ methodNameNode ``` */ @@ -90,14 +90,14 @@ const switchToPromiseResolve = (callExpression, sourceCode) => function * (fixer const [arrayExpression] = callExpression.arguments; /* ``` - Promise.all([promise,]) + Promise.race([promise,]) // ^ openingBracketToken ``` */ const openingBracketToken = sourceCode.getFirstToken(arrayExpression); /* ``` - Promise.all([promise,]) + Promise.race([promise,]) // ^ penultimateToken // ^ closingBracketToken ``` From 46c7f0d84acbee02895e0f76dbd0da777ff7159c Mon Sep 17 00:00:00 2001 From: fisker Date: Sat, 22 Jun 2024 18:57:28 +0800 Subject: [PATCH 07/12] Use `.race` to test --- test/no-single-promise-in-promise-methods.mjs | 150 ++-- ...o-single-promise-in-promise-methods.mjs.md | 689 ++++++++---------- ...single-promise-in-promise-methods.mjs.snap | Bin 2558 -> 2292 bytes 3 files changed, 366 insertions(+), 473 deletions(-) diff --git a/test/no-single-promise-in-promise-methods.mjs b/test/no-single-promise-in-promise-methods.mjs index 510e7c8db4..67fa47b64e 100644 --- a/test/no-single-promise-in-promise-methods.mjs +++ b/test/no-single-promise-in-promise-methods.mjs @@ -8,49 +8,46 @@ test.snapshot({ valid: [ ], invalid: [ - 'await Promise.all([(0, promise)])', - 'async function * foo() {await Promise.all([yield promise])}', - 'async function * foo() {await Promise.all([yield* promise])}', - 'await Promise.all([() => promise,],)', - 'await Promise.all([a ? b : c,],)', - 'await Promise.all([x ??= y,],)', - 'await Promise.all([x ||= y,],)', - 'await Promise.all([x &&= y,],)', - 'await Promise.all([x |= y,],)', - 'await Promise.all([x ^= y,],)', - 'await Promise.all([x ??= y,],)', - 'await Promise.all([x ||= y,],)', - 'await Promise.all([x &&= y,],)', - 'await Promise.all([x | y,],)', - 'await Promise.all([x ^ y,],)', - 'await Promise.all([x & y,],)', - 'await Promise.all([x !== y,],)', - 'await Promise.all([x == y,],)', - 'await Promise.all([x in y,],)', - 'await Promise.all([x >>> y,],)', - 'await Promise.all([x + y,],)', - 'await Promise.all([x / y,],)', - 'await Promise.all([x ** y,],)', - 'await Promise.all([promise,],)', - 'await Promise.all([getPromise(),],)', - 'await Promise.all([promises[0],],)', - 'await Promise.all([await promise])', + 'await Promise.race([(0, promise)])', + 'async function * foo() {await Promise.race([yield promise])}', + 'async function * foo() {await Promise.race([yield* promise])}', + 'await Promise.race([() => promise,],)', + 'await Promise.race([a ? b : c,],)', + 'await Promise.race([x ??= y,],)', + 'await Promise.race([x ||= y,],)', + 'await Promise.race([x &&= y,],)', + 'await Promise.race([x |= y,],)', + 'await Promise.race([x ^= y,],)', + 'await Promise.race([x ??= y,],)', + 'await Promise.race([x ||= y,],)', + 'await Promise.race([x &&= y,],)', + 'await Promise.race([x | y,],)', + 'await Promise.race([x ^ y,],)', + 'await Promise.race([x & y,],)', + 'await Promise.race([x !== y,],)', + 'await Promise.race([x == y,],)', + 'await Promise.race([x in y,],)', + 'await Promise.race([x >>> y,],)', + 'await Promise.race([x + y,],)', + 'await Promise.race([x / y,],)', + 'await Promise.race([x ** y,],)', + 'await Promise.race([promise,],)', + 'await Promise.race([getPromise(),],)', + 'await Promise.race([promises[0],],)', + 'await Promise.race([await promise])', 'await Promise.any([promise])', 'await Promise.race([promise])', - 'await Promise.all([new Promise(() => {})])', - '+await Promise.all([+1])', - 'const results = await Promise.all([promise])', - 'const foo = () => Promise.all([promise])', - 'results = await Promise.all([promise])', + 'await Promise.race([new Promise(() => {})])', + '+await Promise.race([+1])', + 'const foo = await Promise.race([promise])', + 'const foo = () => Promise.race([promise])', + 'foo = await Promise.race([promise])', 'const results = await Promise.any([promise])', 'const results = await Promise.race([promise])', - // Fixable, but not provide at this point - 'const [foo] = await Promise.all([promise])', - - // ASI, `Promise.all()` is not really `await`ed + // ASI, `Promise.race()` is not really `await`ed outdent` - await Promise.all([(x,y)]) + await Promise.race([(x,y)]) [0].toString() `, ], @@ -59,54 +56,69 @@ test.snapshot({ // Not `await`ed test.snapshot({ valid: [ - 'Promise.all([promise, anotherPromise])', - 'Promise.all(notArrayLiteral)', - 'Promise.all([...promises])', + 'Promise.race([promise, anotherPromise])', + 'Promise.race(notArrayLiteral)', + 'Promise.race([...promises])', 'Promise.any([promise, anotherPromise])', 'Promise.race([promise, anotherPromise])', 'Promise.notListedMethod([promise])', 'Promise[all]([promise])', - 'Promise.all([,])', - 'NotPromise.all([promise])', - 'Promise?.all([promise])', - 'Promise.all?.([promise])', - 'Promise.all(...[promise])', - 'Promise.all([promise], extraArguments)', - 'Promise.all()', - 'new Promise.all([promise])', + 'Promise.race([,])', + 'NotPromise.race([promise])', + 'Promise?.race([promise])', + 'Promise.race?.([promise])', + 'Promise.race(...[promise])', + 'Promise.race([promise], extraArguments)', + 'Promise.race()', + 'new Promise.race([promise])', // We are not checking these cases - 'globalThis.Promise.all([promise])', - 'Promise["all"]([promise])', + 'globalThis.Promise.race([promise])', + 'Promise["race"]([promise])', // This can't be checked 'Promise.allSettled([promise])', ], invalid: [ - 'Promise.all([promise,],)', + 'Promise.race([promise,],)', outdent` foo - Promise.all([(0, promise),],) + Promise.race([(0, promise),],) `, outdent` foo - Promise.all([[array][0],],) + Promise.race([[array][0],],) `, - 'Promise.all([promise]).then()', - 'Promise.all([1]).then()', - 'Promise.all([1.]).then()', - 'Promise.all([.1]).then()', - 'Promise.all([(0, promise)]).then()', - 'const _ = () => Promise.all([ a ?? b ,],)', - 'Promise.all([ {a} = 1 ,],)', - 'Promise.all([ function () {} ,],)', - 'Promise.all([ class {} ,],)', - 'Promise.all([ new Foo ,],).then()', - 'Promise.all([ new Foo ,],).toString', - 'foo(Promise.all([promise]))', - 'Promise.all([promise]).foo = 1', - 'Promise.all([promise])[0] ||= 1', - 'Promise.all([undefined]).then()', - 'Promise.all([null]).then()', + 'Promise.race([promise]).then()', + 'Promise.race([1]).then()', + 'Promise.race([1.]).then()', + 'Promise.race([.1]).then()', + 'Promise.race([(0, promise)]).then()', + 'const _ = () => Promise.race([ a ?? b ,],)', + 'Promise.race([ {a} = 1 ,],)', + 'Promise.race([ function () {} ,],)', + 'Promise.race([ class {} ,],)', + 'Promise.race([ new Foo ,],).then()', + 'Promise.race([ new Foo ,],).toString', + 'foo(Promise.race([promise]))', + 'Promise.race([promise]).foo = 1', + 'Promise.race([promise])[0] ||= 1', + 'Promise.race([undefined]).then()', + 'Promise.race([null]).then()', + ], +}); + +// `Promise.all` +test.snapshot({ + valid: [], + invalid: [ + 'const foo = () => Promise.race([promise])', + 'const foo = await Promise.all([promise])', + 'foo = await Promise.all([promise])', + + // Fixable, but not provide at this point + 'const [foo] = await Promise.all([promise])', ], }); + + diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.md b/test/snapshots/no-single-promise-in-promise-methods.mjs.md index 079de58b79..4ac0285eeb 100644 --- a/test/snapshots/no-single-promise-in-promise-methods.mjs.md +++ b/test/snapshots/no-single-promise-in-promise-methods.mjs.md @@ -4,12 +4,12 @@ The actual snapshot is saved in `no-single-promise-in-promise-methods.mjs.snap`. Generated by [AVA](https://avajs.dev). -## invalid(1): await Promise.all([(0, promise)]) +## invalid(1): await Promise.race([(0, promise)]) > Input `␊ - 1 | await Promise.all([(0, promise)])␊ + 1 | await Promise.race([(0, promise)])␊ ` > Output @@ -21,16 +21,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([(0, promise)])␊ - | ^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([(0, promise)])␊ + | ^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(2): async function * foo() {await Promise.all([yield promise])} +## invalid(2): async function * foo() {await Promise.race([yield promise])} > Input `␊ - 1 | async function * foo() {await Promise.all([yield promise])}␊ + 1 | async function * foo() {await Promise.race([yield promise])}␊ ` > Output @@ -42,16 +42,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | async function * foo() {await Promise.all([yield promise])}␊ - | ^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | async function * foo() {await Promise.race([yield promise])}␊ + | ^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(3): async function * foo() {await Promise.all([yield* promise])} +## invalid(3): async function * foo() {await Promise.race([yield* promise])} > Input `␊ - 1 | async function * foo() {await Promise.all([yield* promise])}␊ + 1 | async function * foo() {await Promise.race([yield* promise])}␊ ` > Output @@ -63,16 +63,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | async function * foo() {await Promise.all([yield* promise])}␊ - | ^^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | async function * foo() {await Promise.race([yield* promise])}␊ + | ^^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(4): await Promise.all([() => promise,],) +## invalid(4): await Promise.race([() => promise,],) > Input `␊ - 1 | await Promise.all([() => promise,],)␊ + 1 | await Promise.race([() => promise,],)␊ ` > Output @@ -84,16 +84,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([() => promise,],)␊ - | ^^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([() => promise,],)␊ + | ^^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(5): await Promise.all([a ? b : c,],) +## invalid(5): await Promise.race([a ? b : c,],) > Input `␊ - 1 | await Promise.all([a ? b : c,],)␊ + 1 | await Promise.race([a ? b : c,],)␊ ` > Output @@ -105,16 +105,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([a ? b : c,],)␊ - | ^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([a ? b : c,],)␊ + | ^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(6): await Promise.all([x ??= y,],) +## invalid(6): await Promise.race([x ??= y,],) > Input `␊ - 1 | await Promise.all([x ??= y,],)␊ + 1 | await Promise.race([x ??= y,],)␊ ` > Output @@ -126,16 +126,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x ??= y,],)␊ - | ^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x ??= y,],)␊ + | ^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(7): await Promise.all([x ||= y,],) +## invalid(7): await Promise.race([x ||= y,],) > Input `␊ - 1 | await Promise.all([x ||= y,],)␊ + 1 | await Promise.race([x ||= y,],)␊ ` > Output @@ -147,16 +147,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x ||= y,],)␊ - | ^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x ||= y,],)␊ + | ^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(8): await Promise.all([x &&= y,],) +## invalid(8): await Promise.race([x &&= y,],) > Input `␊ - 1 | await Promise.all([x &&= y,],)␊ + 1 | await Promise.race([x &&= y,],)␊ ` > Output @@ -168,16 +168,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x &&= y,],)␊ - | ^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x &&= y,],)␊ + | ^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(9): await Promise.all([x |= y,],) +## invalid(9): await Promise.race([x |= y,],) > Input `␊ - 1 | await Promise.all([x |= y,],)␊ + 1 | await Promise.race([x |= y,],)␊ ` > Output @@ -189,16 +189,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x |= y,],)␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x |= y,],)␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(10): await Promise.all([x ^= y,],) +## invalid(10): await Promise.race([x ^= y,],) > Input `␊ - 1 | await Promise.all([x ^= y,],)␊ + 1 | await Promise.race([x ^= y,],)␊ ` > Output @@ -210,16 +210,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x ^= y,],)␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x ^= y,],)␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(11): await Promise.all([x ??= y,],) +## invalid(11): await Promise.race([x ??= y,],) > Input `␊ - 1 | await Promise.all([x ??= y,],)␊ + 1 | await Promise.race([x ??= y,],)␊ ` > Output @@ -231,16 +231,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x ??= y,],)␊ - | ^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x ??= y,],)␊ + | ^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(12): await Promise.all([x ||= y,],) +## invalid(12): await Promise.race([x ||= y,],) > Input `␊ - 1 | await Promise.all([x ||= y,],)␊ + 1 | await Promise.race([x ||= y,],)␊ ` > Output @@ -252,16 +252,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x ||= y,],)␊ - | ^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x ||= y,],)␊ + | ^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(13): await Promise.all([x &&= y,],) +## invalid(13): await Promise.race([x &&= y,],) > Input `␊ - 1 | await Promise.all([x &&= y,],)␊ + 1 | await Promise.race([x &&= y,],)␊ ` > Output @@ -273,16 +273,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x &&= y,],)␊ - | ^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x &&= y,],)␊ + | ^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(14): await Promise.all([x | y,],) +## invalid(14): await Promise.race([x | y,],) > Input `␊ - 1 | await Promise.all([x | y,],)␊ + 1 | await Promise.race([x | y,],)␊ ` > Output @@ -294,16 +294,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x | y,],)␊ - | ^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x | y,],)␊ + | ^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(15): await Promise.all([x ^ y,],) +## invalid(15): await Promise.race([x ^ y,],) > Input `␊ - 1 | await Promise.all([x ^ y,],)␊ + 1 | await Promise.race([x ^ y,],)␊ ` > Output @@ -315,16 +315,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x ^ y,],)␊ - | ^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x ^ y,],)␊ + | ^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(16): await Promise.all([x & y,],) +## invalid(16): await Promise.race([x & y,],) > Input `␊ - 1 | await Promise.all([x & y,],)␊ + 1 | await Promise.race([x & y,],)␊ ` > Output @@ -336,16 +336,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x & y,],)␊ - | ^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x & y,],)␊ + | ^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(17): await Promise.all([x !== y,],) +## invalid(17): await Promise.race([x !== y,],) > Input `␊ - 1 | await Promise.all([x !== y,],)␊ + 1 | await Promise.race([x !== y,],)␊ ` > Output @@ -357,16 +357,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x !== y,],)␊ - | ^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x !== y,],)␊ + | ^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(18): await Promise.all([x == y,],) +## invalid(18): await Promise.race([x == y,],) > Input `␊ - 1 | await Promise.all([x == y,],)␊ + 1 | await Promise.race([x == y,],)␊ ` > Output @@ -378,16 +378,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x == y,],)␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x == y,],)␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(19): await Promise.all([x in y,],) +## invalid(19): await Promise.race([x in y,],) > Input `␊ - 1 | await Promise.all([x in y,],)␊ + 1 | await Promise.race([x in y,],)␊ ` > Output @@ -399,16 +399,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x in y,],)␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x in y,],)␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(20): await Promise.all([x >>> y,],) +## invalid(20): await Promise.race([x >>> y,],) > Input `␊ - 1 | await Promise.all([x >>> y,],)␊ + 1 | await Promise.race([x >>> y,],)␊ ` > Output @@ -420,16 +420,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x >>> y,],)␊ - | ^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x >>> y,],)␊ + | ^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(21): await Promise.all([x + y,],) +## invalid(21): await Promise.race([x + y,],) > Input `␊ - 1 | await Promise.all([x + y,],)␊ + 1 | await Promise.race([x + y,],)␊ ` > Output @@ -441,16 +441,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x + y,],)␊ - | ^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x + y,],)␊ + | ^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(22): await Promise.all([x / y,],) +## invalid(22): await Promise.race([x / y,],) > Input `␊ - 1 | await Promise.all([x / y,],)␊ + 1 | await Promise.race([x / y,],)␊ ` > Output @@ -462,16 +462,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x / y,],)␊ - | ^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x / y,],)␊ + | ^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(23): await Promise.all([x ** y,],) +## invalid(23): await Promise.race([x ** y,],) > Input `␊ - 1 | await Promise.all([x ** y,],)␊ + 1 | await Promise.race([x ** y,],)␊ ` > Output @@ -483,16 +483,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([x ** y,],)␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([x ** y,],)␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(24): await Promise.all([promise,],) +## invalid(24): await Promise.race([promise,],) > Input `␊ - 1 | await Promise.all([promise,],)␊ + 1 | await Promise.race([promise,],)␊ ` > Output @@ -504,16 +504,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([promise,],)␊ - | ^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([promise,],)␊ + | ^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(25): await Promise.all([getPromise(),],) +## invalid(25): await Promise.race([getPromise(),],) > Input `␊ - 1 | await Promise.all([getPromise(),],)␊ + 1 | await Promise.race([getPromise(),],)␊ ` > Output @@ -525,16 +525,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([getPromise(),],)␊ - | ^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([getPromise(),],)␊ + | ^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(26): await Promise.all([promises[0],],) +## invalid(26): await Promise.race([promises[0],],) > Input `␊ - 1 | await Promise.all([promises[0],],)␊ + 1 | await Promise.race([promises[0],],)␊ ` > Output @@ -546,16 +546,16 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([promises[0],],)␊ - | ^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([promises[0],],)␊ + | ^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(27): await Promise.all([await promise]) +## invalid(27): await Promise.race([await promise]) > Input `␊ - 1 | await Promise.all([await promise])␊ + 1 | await Promise.race([await promise])␊ ` > Output @@ -567,8 +567,8 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([await promise])␊ - | ^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([await promise])␊ + | ^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` ## invalid(28): await Promise.any([promise]) @@ -613,12 +613,12 @@ Generated by [AVA](https://avajs.dev). | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(30): await Promise.all([new Promise(() => {})]) +## invalid(30): await Promise.race([new Promise(() => {})]) > Input `␊ - 1 | await Promise.all([new Promise(() => {})])␊ + 1 | await Promise.race([new Promise(() => {})])␊ ` > Output @@ -630,100 +630,86 @@ Generated by [AVA](https://avajs.dev). > Error 1/1 `␊ - > 1 | await Promise.all([new Promise(() => {})])␊ - | ^^^^^^^^^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | await Promise.race([new Promise(() => {})])␊ + | ^^^^^^^^^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(31): +await Promise.all([+1]) +## invalid(31): +await Promise.race([+1]) > Input `␊ - 1 | +await Promise.all([+1])␊ + 1 | +await Promise.race([+1])␊ + ` + +> Output + + `␊ + 1 | +await +1␊ ` > Error 1/1 `␊ - > 1 | +await Promise.all([+1])␊ - | ^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | +await (+1)␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | +await Promise.resolve(+1)␊ + > 1 | +await Promise.race([+1])␊ + | ^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(32): const results = await Promise.all([promise]) +## invalid(32): const foo = await Promise.race([promise]) > Input `␊ - 1 | const results = await Promise.all([promise])␊ + 1 | const foo = await Promise.race([promise])␊ + ` + +> Output + + `␊ + 1 | const foo = await promise␊ ` > Error 1/1 `␊ - > 1 | const results = await Promise.all([promise])␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | const results = await promise␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | const results = await Promise.resolve(promise)␊ + > 1 | const foo = await Promise.race([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(33): const foo = () => Promise.all([promise]) +## invalid(33): const foo = () => Promise.race([promise]) > Input `␊ - 1 | const foo = () => Promise.all([promise])␊ + 1 | const foo = () => Promise.race([promise])␊ ` > Error 1/1 `␊ - > 1 | const foo = () => Promise.all([promise])␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | const foo = () => promise␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | const foo = () => Promise.resolve(promise)␊ + > 1 | const foo = () => Promise.race([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(34): results = await Promise.all([promise]) +## invalid(34): foo = await Promise.race([promise]) > Input `␊ - 1 | results = await Promise.all([promise])␊ + 1 | foo = await Promise.race([promise])␊ + ` + +> Output + + `␊ + 1 | foo = await promise␊ ` > Error 1/1 `␊ - > 1 | results = await Promise.all([promise])␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | results = await promise␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | results = await Promise.resolve(promise)␊ + > 1 | foo = await Promise.race([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` ## invalid(35): const results = await Promise.any([promise]) @@ -768,497 +754,392 @@ Generated by [AVA](https://avajs.dev). | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(37): const [foo] = await Promise.all([promise]) +## invalid(37): await Promise.race([(x,y)]) [0].toString() > Input `␊ - 1 | const [foo] = await Promise.all([promise])␊ + 1 | await Promise.race([(x,y)])␊ + 2 | [0].toString()␊ ` > Error 1/1 `␊ - > 1 | const [foo] = await Promise.all([promise])␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | const [foo] = await promise␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | const [foo] = await Promise.resolve(promise)␊ + > 1 | await Promise.race([(x,y)])␊ + | ^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + 2 | [0].toString()␊ ` -## invalid(38): await Promise.all([(x,y)]) [0].toString() +## invalid(1): Promise.race([promise,],) > Input `␊ - 1 | await Promise.all([(x,y)])␊ - 2 | [0].toString()␊ + 1 | Promise.race([promise,],)␊ ` > Error 1/1 `␊ - > 1 | await Promise.all([(x,y)])␊ - | ^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - 2 | [0].toString()␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | await (x,y)␊ - 2 | [0].toString()␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | await Promise.resolve((x,y))␊ - 2 | [0].toString()␊ + > 1 | Promise.race([promise,],)␊ + | ^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(1): Promise.all([promise,],) +## invalid(2): foo Promise.race([(0, promise),],) > Input `␊ - 1 | Promise.all([promise,],)␊ + 1 | foo␊ + 2 | Promise.race([(0, promise),],)␊ ` > Error 1/1 `␊ - > 1 | Promise.all([promise,],)␊ - | ^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | promise␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | Promise.resolve(promise,)␊ + 1 | foo␊ + > 2 | Promise.race([(0, promise),],)␊ + | ^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(2): foo Promise.all([(0, promise),],) +## invalid(3): foo Promise.race([[array][0],],) > Input `␊ 1 | foo␊ - 2 | Promise.all([(0, promise),],)␊ + 2 | Promise.race([[array][0],],)␊ ` > Error 1/1 `␊ 1 | foo␊ - > 2 | Promise.all([(0, promise),],)␊ - | ^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | foo␊ - 2 | ;(0, promise)␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | foo␊ - 2 | Promise.resolve((0, promise),)␊ + > 2 | Promise.race([[array][0],],)␊ + | ^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(3): foo Promise.all([[array][0],],) +## invalid(4): Promise.race([promise]).then() > Input `␊ - 1 | foo␊ - 2 | Promise.all([[array][0],],)␊ + 1 | Promise.race([promise]).then()␊ ` > Error 1/1 `␊ - 1 | foo␊ - > 2 | Promise.all([[array][0],],)␊ - | ^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | foo␊ - 2 | ;[array][0]␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | foo␊ - 2 | Promise.resolve([array][0],)␊ + > 1 | Promise.race([promise]).then()␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(4): Promise.all([promise]).then() +## invalid(5): Promise.race([1]).then() > Input `␊ - 1 | Promise.all([promise]).then()␊ + 1 | Promise.race([1]).then()␊ ` > Error 1/1 `␊ - > 1 | Promise.all([promise]).then()␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | promise.then()␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | Promise.resolve(promise).then()␊ + > 1 | Promise.race([1]).then()␊ + | ^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(5): Promise.all([1]).then() +## invalid(6): Promise.race([1.]).then() > Input `␊ - 1 | Promise.all([1]).then()␊ + 1 | Promise.race([1.]).then()␊ ` > Error 1/1 `␊ - > 1 | Promise.all([1]).then()␊ - | ^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | (1).then()␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | Promise.resolve(1).then()␊ + > 1 | Promise.race([1.]).then()␊ + | ^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(6): Promise.all([1.]).then() +## invalid(7): Promise.race([.1]).then() > Input `␊ - 1 | Promise.all([1.]).then()␊ + 1 | Promise.race([.1]).then()␊ ` > Error 1/1 `␊ - > 1 | Promise.all([1.]).then()␊ - | ^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | (1.).then()␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | Promise.resolve(1.).then()␊ + > 1 | Promise.race([.1]).then()␊ + | ^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(7): Promise.all([.1]).then() +## invalid(8): Promise.race([(0, promise)]).then() > Input `␊ - 1 | Promise.all([.1]).then()␊ + 1 | Promise.race([(0, promise)]).then()␊ ` > Error 1/1 `␊ - > 1 | Promise.all([.1]).then()␊ - | ^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | (.1).then()␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | Promise.resolve(.1).then()␊ + > 1 | Promise.race([(0, promise)]).then()␊ + | ^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(8): Promise.all([(0, promise)]).then() +## invalid(9): const _ = () => Promise.race([ a ?? b ,],) > Input `␊ - 1 | Promise.all([(0, promise)]).then()␊ + 1 | const _ = () => Promise.race([ a ?? b ,],)␊ ` > Error 1/1 `␊ - > 1 | Promise.all([(0, promise)]).then()␊ - | ^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | (0, promise).then()␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | Promise.resolve((0, promise)).then()␊ + > 1 | const _ = () => Promise.race([ a ?? b ,],)␊ + | ^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(9): const _ = () => Promise.all([ a ?? b ,],) +## invalid(10): Promise.race([ {a} = 1 ,],) > Input `␊ - 1 | const _ = () => Promise.all([ a ?? b ,],)␊ + 1 | Promise.race([ {a} = 1 ,],)␊ ` > Error 1/1 `␊ - > 1 | const _ = () => Promise.all([ a ?? b ,],)␊ - | ^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | const _ = () => (a ?? b)␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | const _ = () => Promise.resolve( a ?? b ,)␊ + > 1 | Promise.race([ {a} = 1 ,],)␊ + | ^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(10): Promise.all([ {a} = 1 ,],) +## invalid(11): Promise.race([ function () {} ,],) > Input `␊ - 1 | Promise.all([ {a} = 1 ,],)␊ + 1 | Promise.race([ function () {} ,],)␊ ` > Error 1/1 `␊ - > 1 | Promise.all([ {a} = 1 ,],)␊ - | ^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | ({a} = 1)␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | Promise.resolve( {a} = 1 ,)␊ + > 1 | Promise.race([ function () {} ,],)␊ + | ^^^^^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(11): Promise.all([ function () {} ,],) +## invalid(12): Promise.race([ class {} ,],) > Input `␊ - 1 | Promise.all([ function () {} ,],)␊ + 1 | Promise.race([ class {} ,],)␊ ` > Error 1/1 `␊ - > 1 | Promise.all([ function () {} ,],)␊ - | ^^^^^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | (function () {})␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | Promise.resolve( function () {} ,)␊ + > 1 | Promise.race([ class {} ,],)␊ + | ^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(12): Promise.all([ class {} ,],) +## invalid(13): Promise.race([ new Foo ,],).then() > Input `␊ - 1 | Promise.all([ class {} ,],)␊ + 1 | Promise.race([ new Foo ,],).then()␊ ` > Error 1/1 `␊ - > 1 | Promise.all([ class {} ,],)␊ - | ^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | (class {})␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | Promise.resolve( class {} ,)␊ + > 1 | Promise.race([ new Foo ,],).then()␊ + | ^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(13): Promise.all([ new Foo ,],).then() +## invalid(14): Promise.race([ new Foo ,],).toString > Input `␊ - 1 | Promise.all([ new Foo ,],).then()␊ + 1 | Promise.race([ new Foo ,],).toString␊ ` > Error 1/1 `␊ - > 1 | Promise.all([ new Foo ,],).then()␊ - | ^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | (new Foo).then()␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | Promise.resolve( new Foo ,).then()␊ + > 1 | Promise.race([ new Foo ,],).toString␊ + | ^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(14): Promise.all([ new Foo ,],).toString +## invalid(15): foo(Promise.race([promise])) > Input `␊ - 1 | Promise.all([ new Foo ,],).toString␊ + 1 | foo(Promise.race([promise]))␊ ` > Error 1/1 `␊ - > 1 | Promise.all([ new Foo ,],).toString␊ - | ^^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | (new Foo).toString␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | Promise.resolve( new Foo ,).toString␊ + > 1 | foo(Promise.race([promise]))␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(15): foo(Promise.all([promise])) +## invalid(16): Promise.race([promise]).foo = 1 > Input `␊ - 1 | foo(Promise.all([promise]))␊ + 1 | Promise.race([promise]).foo = 1␊ ` > Error 1/1 `␊ - > 1 | foo(Promise.all([promise]))␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | foo(promise)␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | foo(Promise.resolve(promise))␊ + > 1 | Promise.race([promise]).foo = 1␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(16): Promise.all([promise]).foo = 1 +## invalid(17): Promise.race([promise])[0] ||= 1 > Input `␊ - 1 | Promise.all([promise]).foo = 1␊ + 1 | Promise.race([promise])[0] ||= 1␊ ` > Error 1/1 `␊ - > 1 | Promise.all([promise]).foo = 1␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | promise.foo = 1␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | Promise.resolve(promise).foo = 1␊ + > 1 | Promise.race([promise])[0] ||= 1␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(17): Promise.all([promise])[0] ||= 1 +## invalid(18): Promise.race([undefined]).then() > Input `␊ - 1 | Promise.all([promise])[0] ||= 1␊ + 1 | Promise.race([undefined]).then()␊ ` > Error 1/1 `␊ - > 1 | Promise.all([promise])[0] ||= 1␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | Promise.race([undefined]).then()␊ + | ^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ` + +## invalid(19): Promise.race([null]).then() + +> Input + + `␊ + 1 | Promise.race([null]).then()␊ + ` + +> Error 1/1 + + `␊ + > 1 | Promise.race([null]).then()␊ + | ^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ` + +## invalid(1): const foo = () => Promise.race([promise]) + +> Input + + `␊ + 1 | const foo = () => Promise.race([promise])␊ + ` + +> Error 1/1 + + `␊ + > 1 | const foo = () => Promise.race([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ` + +## invalid(2): const foo = await Promise.all([promise]) + +> Input + + `␊ + 1 | const foo = await Promise.all([promise])␊ + ` + +> Error 1/1 + + `␊ + > 1 | const foo = await Promise.all([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ ␊ --------------------------------------------------------------------------------␊ Suggestion 1/2: Use the value directly.␊ - 1 | promise[0] ||= 1␊ + 1 | const foo = await promise␊ ␊ --------------------------------------------------------------------------------␊ Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | Promise.resolve(promise)[0] ||= 1␊ + 1 | const foo = await Promise.resolve(promise)␊ ` -## invalid(18): Promise.all([undefined]).then() +## invalid(3): foo = await Promise.all([promise]) > Input `␊ - 1 | Promise.all([undefined]).then()␊ + 1 | foo = await Promise.all([promise])␊ ` > Error 1/1 `␊ - > 1 | Promise.all([undefined]).then()␊ - | ^^^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | foo = await Promise.all([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ ␊ --------------------------------------------------------------------------------␊ Suggestion 1/2: Use the value directly.␊ - 1 | undefined.then()␊ + 1 | foo = await promise␊ ␊ --------------------------------------------------------------------------------␊ Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | Promise.resolve(undefined).then()␊ + 1 | foo = await Promise.resolve(promise)␊ ` -## invalid(19): Promise.all([null]).then() +## invalid(4): const [foo] = await Promise.all([promise]) > Input `␊ - 1 | Promise.all([null]).then()␊ + 1 | const [foo] = await Promise.all([promise])␊ ` > Error 1/1 `␊ - > 1 | Promise.all([null]).then()␊ - | ^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | const [foo] = await Promise.all([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ ␊ --------------------------------------------------------------------------------␊ Suggestion 1/2: Use the value directly.␊ - 1 | (null).then()␊ + 1 | const [foo] = await promise␊ ␊ --------------------------------------------------------------------------------␊ Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | Promise.resolve(null).then()␊ + 1 | const [foo] = await Promise.resolve(promise)␊ ` diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.snap b/test/snapshots/no-single-promise-in-promise-methods.mjs.snap index b818ec534e223157aab7b7896db1ec37e49a10a9..23660401b466a52ac272a3fa896197a39f754f98 100644 GIT binary patch literal 2292 zcmVBoeepP?eWLMO!H4rJ|*v-arD0Pk{IW6-O>yIdTKp@y_nE`^@Zk zv%9vc_!wpWJO2Hjd1juOS%15HMmKA3S=W!dF~aS5Fyh4ZEY21zJx4EpO{i+vS%Uw%ho&xADHK14DD7Jt2gUErNWi;6q-k zD{E_-u|h1(SkcuHRaeidhE0@uU1^ea&0Zy^!GomJM6*c4Fw~lASxUWG==5AWQLmeI zA{S-HhZh|mN-ZC(rcooy4Wnjjra^LK*)+2f*~Gp}Q&aUN=i5}I?Vv-i0IJ6ws=Igw z=G}4dlnJ4yWPvc%g}&YgzWz>q-A(_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$^cq;W*SbnIIJ-bO<~5I|LuUDI-;QQuFW+1?_x!Gn*+R^ z;POUgP~iRvfP0${TqJdC5Esq2_{b$=<}sH#$>=!i=7!~%>zrc@3Fgu=D0BY;%>5N* z4w2$+;mSZAopbTK2s%_@6A|45UQANwbZnagoWwm~pn$UW7r@%9C~HuKg;^O0Q+iW9 U1WhU!W|FMW0Y??RG3ssr0G`0$WB>pF From a6e6979e25d7e9cb2665f8bd0e7e48b13c5b7edc Mon Sep 17 00:00:00 2001 From: fisker Date: Sat, 22 Jun 2024 18:58:35 +0800 Subject: [PATCH 08/12] Fix --- rules/no-single-promise-in-promise-methods.js | 2 +- ...o-single-promise-in-promise-methods.mjs.md | 206 ++++++++++++++++-- ...single-promise-in-promise-methods.mjs.snap | Bin 2292 -> 2599 bytes 3 files changed, 183 insertions(+), 25 deletions(-) diff --git a/rules/no-single-promise-in-promise-methods.js b/rules/no-single-promise-in-promise-methods.js index 1a1764ffc9..c063f88b17 100644 --- a/rules/no-single-promise-in-promise-methods.js +++ b/rules/no-single-promise-in-promise-methods.js @@ -146,7 +146,7 @@ const create = context => ({ return problem; } - if (methodName !== 'all') { + if (methodName === 'all') { return problem; } diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.md b/test/snapshots/no-single-promise-in-promise-methods.mjs.md index 4ac0285eeb..8eeff6ea4d 100644 --- a/test/snapshots/no-single-promise-in-promise-methods.mjs.md +++ b/test/snapshots/no-single-promise-in-promise-methods.mjs.md @@ -689,6 +689,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | const foo = () => Promise.race([promise])␊ | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | const foo = () => promise␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | const foo = () => Promise.resolve(promise)␊ ` ## invalid(34): foo = await Promise.race([promise]) @@ -769,6 +777,16 @@ Generated by [AVA](https://avajs.dev). > 1 | await Promise.race([(x,y)])␊ | ^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ 2 | [0].toString()␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | await (x,y)␊ + 2 | [0].toString()␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | await Promise.resolve((x,y))␊ + 2 | [0].toString()␊ ` ## invalid(1): Promise.race([promise,],) @@ -784,6 +802,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | Promise.race([promise,],)␊ | ^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | promise␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | Promise.resolve(promise,)␊ ` ## invalid(2): foo Promise.race([(0, promise),],) @@ -801,6 +827,16 @@ Generated by [AVA](https://avajs.dev). 1 | foo␊ > 2 | Promise.race([(0, promise),],)␊ | ^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | foo␊ + 2 | ;(0, promise)␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | foo␊ + 2 | Promise.resolve((0, promise),)␊ ` ## invalid(3): foo Promise.race([[array][0],],) @@ -818,6 +854,16 @@ Generated by [AVA](https://avajs.dev). 1 | foo␊ > 2 | Promise.race([[array][0],],)␊ | ^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | foo␊ + 2 | ;[array][0]␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | foo␊ + 2 | Promise.resolve([array][0],)␊ ` ## invalid(4): Promise.race([promise]).then() @@ -833,6 +879,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | Promise.race([promise]).then()␊ | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | promise.then()␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | Promise.resolve(promise).then()␊ ` ## invalid(5): Promise.race([1]).then() @@ -848,6 +902,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | Promise.race([1]).then()␊ | ^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | (1).then()␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | Promise.resolve(1).then()␊ ` ## invalid(6): Promise.race([1.]).then() @@ -863,6 +925,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | Promise.race([1.]).then()␊ | ^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | (1.).then()␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | Promise.resolve(1.).then()␊ ` ## invalid(7): Promise.race([.1]).then() @@ -878,6 +948,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | Promise.race([.1]).then()␊ | ^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | (.1).then()␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | Promise.resolve(.1).then()␊ ` ## invalid(8): Promise.race([(0, promise)]).then() @@ -893,6 +971,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | Promise.race([(0, promise)]).then()␊ | ^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | (0, promise).then()␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | Promise.resolve((0, promise)).then()␊ ` ## invalid(9): const _ = () => Promise.race([ a ?? b ,],) @@ -908,6 +994,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | const _ = () => Promise.race([ a ?? b ,],)␊ | ^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | const _ = () => (a ?? b)␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | const _ = () => Promise.resolve( a ?? b ,)␊ ` ## invalid(10): Promise.race([ {a} = 1 ,],) @@ -923,6 +1017,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | Promise.race([ {a} = 1 ,],)␊ | ^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | ({a} = 1)␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | Promise.resolve( {a} = 1 ,)␊ ` ## invalid(11): Promise.race([ function () {} ,],) @@ -938,6 +1040,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | Promise.race([ function () {} ,],)␊ | ^^^^^^^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | (function () {})␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | Promise.resolve( function () {} ,)␊ ` ## invalid(12): Promise.race([ class {} ,],) @@ -953,6 +1063,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | Promise.race([ class {} ,],)␊ | ^^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | (class {})␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | Promise.resolve( class {} ,)␊ ` ## invalid(13): Promise.race([ new Foo ,],).then() @@ -968,6 +1086,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | Promise.race([ new Foo ,],).then()␊ | ^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | (new Foo).then()␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | Promise.resolve( new Foo ,).then()␊ ` ## invalid(14): Promise.race([ new Foo ,],).toString @@ -983,6 +1109,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | Promise.race([ new Foo ,],).toString␊ | ^^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | (new Foo).toString␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | Promise.resolve( new Foo ,).toString␊ ` ## invalid(15): foo(Promise.race([promise])) @@ -998,6 +1132,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | foo(Promise.race([promise]))␊ | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | foo(promise)␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | foo(Promise.resolve(promise))␊ ` ## invalid(16): Promise.race([promise]).foo = 1 @@ -1013,6 +1155,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | Promise.race([promise]).foo = 1␊ | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | promise.foo = 1␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | Promise.resolve(promise).foo = 1␊ ` ## invalid(17): Promise.race([promise])[0] ||= 1 @@ -1028,6 +1178,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | Promise.race([promise])[0] ||= 1␊ | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | promise[0] ||= 1␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | Promise.resolve(promise)[0] ||= 1␊ ` ## invalid(18): Promise.race([undefined]).then() @@ -1043,6 +1201,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | Promise.race([undefined]).then()␊ | ^^^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | undefined.then()␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | Promise.resolve(undefined).then()␊ ` ## invalid(19): Promise.race([null]).then() @@ -1058,6 +1224,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | Promise.race([null]).then()␊ | ^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | (null).then()␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | Promise.resolve(null).then()␊ ` ## invalid(1): const foo = () => Promise.race([promise]) @@ -1073,6 +1247,14 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | const foo = () => Promise.race([promise])␊ | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 1/2: Use the value directly.␊ + 1 | const foo = () => promise␊ + ␊ + --------------------------------------------------------------------------------␊ + Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ + 1 | const foo = () => Promise.resolve(promise)␊ ` ## invalid(2): const foo = await Promise.all([promise]) @@ -1088,14 +1270,6 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | const foo = await Promise.all([promise])␊ | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | const foo = await promise␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | const foo = await Promise.resolve(promise)␊ ` ## invalid(3): foo = await Promise.all([promise]) @@ -1111,14 +1285,6 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | foo = await Promise.all([promise])␊ | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | foo = await promise␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | foo = await Promise.resolve(promise)␊ ` ## invalid(4): const [foo] = await Promise.all([promise]) @@ -1134,12 +1300,4 @@ Generated by [AVA](https://avajs.dev). `␊ > 1 | const [foo] = await Promise.all([promise])␊ | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | const [foo] = await promise␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | const [foo] = await Promise.resolve(promise)␊ ` diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.snap b/test/snapshots/no-single-promise-in-promise-methods.mjs.snap index 23660401b466a52ac272a3fa896197a39f754f98..515a34e1581e74acd7ac6ae39b501272eb979003 100644 GIT binary patch literal 2599 zcmV+?3fT2QRzVRz+|{xZ)D^ zu2*Q+GiT=A4=5*G^mY+M~{eqn8ZVbS+~`HSIIH zWv(h(VS(vqb<<_PYSbSy9YbyCHA7iZCdb+4&R+_Zg6Y`$rn6CZohL7?uIjG-o5Q#4 z`{BO!XXFR_ZW}3%GN!R@38hiP(oY+f@qoSAbUiHvX#Esug|GImU3;+U1{YrmU%da1 z`$m^!Tf!J)+YI?s!G}HE&^I?td!0F^y>1zY49j@TuwAA%8hVSJHQfz%3Vc!F6f+&x zv~8niIF8=3Tt(&J(A_R$Eh6hQ<))B(b+OP%@$Y< zPh<{QSP&!vgs?R31yVnOY4EG@Brbs@o)skl+aZ-gPZKEl3Ct1+Y_a9#Mb^Uop8=-b zEAT%ggSmeY2>lqk?_G;~{~YlC_ag7ZZIE!jKfceAzHe`5;yaf~;d|%W415pTkQ?6* zlfI9QW#T)RN#T3v+6;UT+AwI}i@xvkH1DMC)4;7UG42A_4*;DX#b_r@|0^*4cL}h| zd)^<^wMo+RY9^jn(|cac#`9`UJRj$tQ?~+cj;B2~zI<~)9gOi)H%HWgjHnv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5(Z1m>-# zF)*h+=rMDeU`p&_bZ%}gjs!zxA|#l0+ZYmz+lO8!7&?)b*cE9$j)^oMc_PinGLh!{ zVj^{Mv+K}e9Jq^-aTjC3UF-|oG?kaw)n_gjM=EzzBBb(G(-=}Y?Lpt9a#rEVJw+8y zPBNWB0kj|+JxFu39}?>AuHJu&klCBgKD z-X!&pRhMTshMQ7FB8#Jyf^9C?bcx)Y5FsV9<b`pQcYR zjAc6KhGVP|T#*X)s%l`_5kJS`t6==D0)Fpt$FeKLYU?*h`tpcD$P+BsV z(?y`LiDHt&040isP6!i0GzAVDkqN;gfWf&0B(`xlh0yRx2hU^xPk|RYB6te?*b%`~ z2o0WO@f5u;NwH@j4k)~S6_CP^eFM_cCwN-I)k5dTbT(Y3Y5DRdV z3viY|ks+dpQT-WEy$uTvAyMW!7=@iE=`48H$=ByiWt+?rnZXv{Gv`P|o;jgPNNA=r zz~x}U;QjzW>)rot1~vQ_OTv{fc;5kdpE2NJV&Ti*#8J}I&i0E(zCPD<#j@BC@zYM8 z28NGuYRQ%9=~~x~zH$&*>qP0KX|}t`oL+>Y4^hJK-30hPV&KEXdO3pWZ6G;VF!(y# z***wT#BT$MXki?`1{^O7adhN*Nzxs_<2yxcmQn8r4`7}~7Xz3p!H~DanxtVYsmq$7E^!JH5p+Qv3?1W^bf^?R$ECD7o({k>8oJKmCbBvP5*V_}0NFb@ zGN{6&l_;oj?>_q80eMoG$GjWy?5h-tu5&5l+wr1$2;?^g{{xi&84SJd;nNg>9F1}7 zK?vfZk(fV23yqZ()oNE-a}uY ztrFYxM51b$`Z+cG*V}ib)9gO_|K0aHYn-E_GUG-^Sghg|OT;Ms8${{-LC%$ouHy57 zip>6w$z4U`g!iy$C%PAxO|#N Date: Sat, 22 Jun 2024 19:02:49 +0800 Subject: [PATCH 09/12] More tests --- test/no-single-promise-in-promise-methods.mjs | 20 +- ...o-single-promise-in-promise-methods.mjs.md | 264 ++++++++++-------- ...single-promise-in-promise-methods.mjs.snap | Bin 2599 -> 2653 bytes 3 files changed, 158 insertions(+), 126 deletions(-) diff --git a/test/no-single-promise-in-promise-methods.mjs b/test/no-single-promise-in-promise-methods.mjs index 67fa47b64e..66fe6f6454 100644 --- a/test/no-single-promise-in-promise-methods.mjs +++ b/test/no-single-promise-in-promise-methods.mjs @@ -39,11 +39,6 @@ test.snapshot({ 'await Promise.race([promise])', 'await Promise.race([new Promise(() => {})])', '+await Promise.race([+1])', - 'const foo = await Promise.race([promise])', - 'const foo = () => Promise.race([promise])', - 'foo = await Promise.race([promise])', - 'const results = await Promise.any([promise])', - 'const results = await Promise.race([promise])', // ASI, `Promise.race()` is not really `await`ed outdent` @@ -112,13 +107,22 @@ test.snapshot({ test.snapshot({ valid: [], invalid: [ - 'const foo = () => Promise.race([promise])', + // Only fixable if it's in `ExpressionStatement` + 'Promise.all([promise])', + 'await Promise.all([promise])', + + 'const foo = () => Promise.all([promise])', 'const foo = await Promise.all([promise])', 'foo = await Promise.all([promise])', + // `Promise.{all, race}()` should not care if the result is used + 'const foo = await Promise.race([promise])', + 'const foo = () => Promise.race([promise])', + 'foo = await Promise.race([promise])', + 'const results = await Promise.any([promise])', + 'const results = await Promise.race([promise])', + // Fixable, but not provide at this point 'const [foo] = await Promise.all([promise])', ], }); - - diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.md b/test/snapshots/no-single-promise-in-promise-methods.mjs.md index 8eeff6ea4d..0f2208626e 100644 --- a/test/snapshots/no-single-promise-in-promise-methods.mjs.md +++ b/test/snapshots/no-single-promise-in-promise-methods.mjs.md @@ -655,114 +655,7 @@ Generated by [AVA](https://avajs.dev). | ^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(32): const foo = await Promise.race([promise]) - -> Input - - `␊ - 1 | const foo = await Promise.race([promise])␊ - ` - -> Output - - `␊ - 1 | const foo = await promise␊ - ` - -> Error 1/1 - - `␊ - > 1 | const foo = await Promise.race([promise])␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ - ` - -## invalid(33): const foo = () => Promise.race([promise]) - -> Input - - `␊ - 1 | const foo = () => Promise.race([promise])␊ - ` - -> Error 1/1 - - `␊ - > 1 | const foo = () => Promise.race([promise])␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 1/2: Use the value directly.␊ - 1 | const foo = () => promise␊ - ␊ - --------------------------------------------------------------------------------␊ - Suggestion 2/2: Switch to \`Promise.resolve(…)\`.␊ - 1 | const foo = () => Promise.resolve(promise)␊ - ` - -## invalid(34): foo = await Promise.race([promise]) - -> Input - - `␊ - 1 | foo = await Promise.race([promise])␊ - ` - -> Output - - `␊ - 1 | foo = await promise␊ - ` - -> Error 1/1 - - `␊ - > 1 | foo = await Promise.race([promise])␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ - ` - -## invalid(35): const results = await Promise.any([promise]) - -> Input - - `␊ - 1 | const results = await Promise.any([promise])␊ - ` - -> Output - - `␊ - 1 | const results = await promise␊ - ` - -> Error 1/1 - - `␊ - > 1 | const results = await Promise.any([promise])␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.any()\` is unnecessary.␊ - ` - -## invalid(36): const results = await Promise.race([promise]) - -> Input - - `␊ - 1 | const results = await Promise.race([promise])␊ - ` - -> Output - - `␊ - 1 | const results = await promise␊ - ` - -> Error 1/1 - - `␊ - > 1 | const results = await Promise.race([promise])␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ - ` - -## invalid(37): await Promise.race([(x,y)]) [0].toString() +## invalid(32): await Promise.race([(x,y)]) [0].toString() > Input @@ -1234,7 +1127,109 @@ Generated by [AVA](https://avajs.dev). 1 | Promise.resolve(null).then()␊ ` -## invalid(1): const foo = () => Promise.race([promise]) +## invalid(1): Promise.all([promise]) + +> Input + + `␊ + 1 | Promise.all([promise])␊ + ` + +> Error 1/1 + + `␊ + > 1 | Promise.all([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + ` + +## invalid(2): await Promise.all([promise]) + +> Input + + `␊ + 1 | await Promise.all([promise])␊ + ` + +> Output + + `␊ + 1 | await promise␊ + ` + +> Error 1/1 + + `␊ + > 1 | await Promise.all([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + ` + +## invalid(3): const foo = () => Promise.all([promise]) + +> Input + + `␊ + 1 | const foo = () => Promise.all([promise])␊ + ` + +> Error 1/1 + + `␊ + > 1 | const foo = () => Promise.all([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + ` + +## invalid(4): const foo = await Promise.all([promise]) + +> Input + + `␊ + 1 | const foo = await Promise.all([promise])␊ + ` + +> Error 1/1 + + `␊ + > 1 | const foo = await Promise.all([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + ` + +## invalid(5): foo = await Promise.all([promise]) + +> Input + + `␊ + 1 | foo = await Promise.all([promise])␊ + ` + +> Error 1/1 + + `␊ + > 1 | foo = await Promise.all([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + ` + +## invalid(6): const foo = await Promise.race([promise]) + +> Input + + `␊ + 1 | const foo = await Promise.race([promise])␊ + ` + +> Output + + `␊ + 1 | const foo = await promise␊ + ` + +> Error 1/1 + + `␊ + > 1 | const foo = await Promise.race([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ + ` + +## invalid(7): const foo = () => Promise.race([promise]) > Input @@ -1257,37 +1252,70 @@ Generated by [AVA](https://avajs.dev). 1 | const foo = () => Promise.resolve(promise)␊ ` -## invalid(2): const foo = await Promise.all([promise]) +## invalid(8): foo = await Promise.race([promise]) > Input `␊ - 1 | const foo = await Promise.all([promise])␊ + 1 | foo = await Promise.race([promise])␊ + ` + +> Output + + `␊ + 1 | foo = await promise␊ ` > Error 1/1 `␊ - > 1 | const foo = await Promise.all([promise])␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | foo = await Promise.race([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(3): foo = await Promise.all([promise]) +## invalid(9): const results = await Promise.any([promise]) > Input `␊ - 1 | foo = await Promise.all([promise])␊ + 1 | const results = await Promise.any([promise])␊ + ` + +> Output + + `␊ + 1 | const results = await promise␊ ` > Error 1/1 `␊ - > 1 | foo = await Promise.all([promise])␊ - | ^^^^^^^^^ Wrapping single-element array with \`Promise.all()\` is unnecessary.␊ + > 1 | const results = await Promise.any([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.any()\` is unnecessary.␊ + ` + +## invalid(10): const results = await Promise.race([promise]) + +> Input + + `␊ + 1 | const results = await Promise.race([promise])␊ + ` + +> Output + + `␊ + 1 | const results = await promise␊ + ` + +> Error 1/1 + + `␊ + > 1 | const results = await Promise.race([promise])␊ + | ^^^^^^^^^ Wrapping single-element array with \`Promise.race()\` is unnecessary.␊ ` -## invalid(4): const [foo] = await Promise.all([promise]) +## invalid(11): const [foo] = await Promise.all([promise]) > Input diff --git a/test/snapshots/no-single-promise-in-promise-methods.mjs.snap b/test/snapshots/no-single-promise-in-promise-methods.mjs.snap index 515a34e1581e74acd7ac6ae39b501272eb979003..98c46b487a75c592eca011f8ec43623aaf3cebdc 100644 GIT binary patch literal 2653 zcmV-j3ZnHvRzVAGn?3oEupkGD4FbdztvWd(Qhl`^}s==ge#C=PalBefP@pRl_qq%h*;;`@C+M zYl>D{Wcmf&^w?u9=PA=Q)Rx{flvQQA%C`3ZrBpAOuB~smn~vu`eRXY3_w*+gzA$#% zSm!hT#j!ia%M*-gY*#{Q!m#vnhGjfrZ?!#NO95JU0j+pzzwP>?Z7*v4M!fNn=f@_N zWqZOHW4jFbG{A>_ucdEonf3;AO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u2bGqSW0`qSWLXH4%Qv0KLi+u!ZkeNJycSeFG@_H%=KY zm$(QW4)Q{M&p(0T)+VyZH+|>%E&oS|y;P>N<@VcY@Kxx~0Fq^JV_rtF`(0ltRr203 z3hYqO8g)n6@gq;jk^y@E%p;`1Rlw^jA_Sb%&$C6Q5vbzFpac?V)%*~!`37D!p-e)x z918jrug7`9Eru6QMPiWF;@c3xOYqw7zdKK0hQGBlSqY`>I-u=e1Z|jF@_pjrVGs5{ z*9b4J?{ltM3xbiUcT;i7 z+UIzW*Xx~N$wi4&y+f2x;=TgJeMS(6sqKkD*6a8#Sd9c3C9XyIBWzlH+aVIQcZwhm zA^r%Pj24RF*8s!Mr7-mM_85qMw|5DOFm=(WJF~MZs}TE6(xa|O1BLG&0KRuef}^0c z4zb=HF6!D2g4S!xbK?cR`bAa3XN!zWyl&H)N z1#SL*tKZ@L07q`P!k7gw*4E;i8a&~Z$x7!%f(Uf806Iks9oIpr`wyV*!vyLAt-XR> z(Bu4b7fo6OUVQJPX|EbP~biQz`c$G2W3dsh5|FC-Pv8Rgayr{@R|vqTEF@5A`{xA=Y4 zbgo_ouKq#vbZJ+9_QlEB@Tue-5LVXe^-9-{iq0y?C}PgO2AsVDd6g2CDzd$G`g;vL JUs$|w008n52~q$6 From d3ea8d81d4f1d0ff44866f56095bd4636d175b0a Mon Sep 17 00:00:00 2001 From: fisker Date: Sat, 22 Jun 2024 19:05:58 +0800 Subject: [PATCH 10/12] Missing one --- test/no-single-promise-in-promise-methods.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/no-single-promise-in-promise-methods.mjs b/test/no-single-promise-in-promise-methods.mjs index 66fe6f6454..7e5049f7f9 100644 --- a/test/no-single-promise-in-promise-methods.mjs +++ b/test/no-single-promise-in-promise-methods.mjs @@ -57,7 +57,7 @@ test.snapshot({ 'Promise.any([promise, anotherPromise])', 'Promise.race([promise, anotherPromise])', 'Promise.notListedMethod([promise])', - 'Promise[all]([promise])', + 'Promise[race]([promise])', 'Promise.race([,])', 'NotPromise.race([promise])', 'Promise?.race([promise])', From 0be2a709ae3d18893203334a2703d1a74f0e3dfe Mon Sep 17 00:00:00 2001 From: fisker Date: Sat, 22 Jun 2024 19:10:05 +0800 Subject: [PATCH 11/12] Add issue link --- test/no-single-promise-in-promise-methods.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/no-single-promise-in-promise-methods.mjs b/test/no-single-promise-in-promise-methods.mjs index 7e5049f7f9..ca65a43aef 100644 --- a/test/no-single-promise-in-promise-methods.mjs +++ b/test/no-single-promise-in-promise-methods.mjs @@ -123,6 +123,7 @@ test.snapshot({ 'const results = await Promise.race([promise])', // Fixable, but not provide at this point + // https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2388 'const [foo] = await Promise.all([promise])', ], }); From 5dddf13413f57b6a51036a350ca7146b2e395d1e Mon Sep 17 00:00:00 2001 From: fisker Date: Sat, 22 Jun 2024 19:12:17 +0800 Subject: [PATCH 12/12] Fix cursor --- rules/no-single-promise-in-promise-methods.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rules/no-single-promise-in-promise-methods.js b/rules/no-single-promise-in-promise-methods.js index c063f88b17..83bf9faacd 100644 --- a/rules/no-single-promise-in-promise-methods.js +++ b/rules/no-single-promise-in-promise-methods.js @@ -81,7 +81,7 @@ const switchToPromiseResolve = (callExpression, sourceCode) => function * (fixer /* ``` Promise.race([promise,]) - // ^^^ methodNameNode + // ^^^^ methodNameNode ``` */ const methodNameNode = callExpression.callee.property; @@ -91,15 +91,15 @@ const switchToPromiseResolve = (callExpression, sourceCode) => function * (fixer /* ``` Promise.race([promise,]) - // ^ openingBracketToken + // ^ openingBracketToken ``` */ const openingBracketToken = sourceCode.getFirstToken(arrayExpression); /* ``` Promise.race([promise,]) - // ^ penultimateToken - // ^ closingBracketToken + // ^ penultimateToken + // ^ closingBracketToken ``` */ const [