From 7bd6c63af13e9f82e17bab706392a767a91d3898 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 2 Nov 2021 09:56:00 +0800 Subject: [PATCH 1/3] `require-array-join-separator`: Check optional member and call --- rules/require-array-join-separator.js | 7 ++- test/require-array-join-separator.mjs | 4 +- .../require-array-join-separator.mjs.md | 48 ++++++++++++++++++ .../require-array-join-separator.mjs.snap | Bin 624 -> 752 bytes 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/rules/require-array-join-separator.js b/rules/require-array-join-separator.js index 50fa5c176a..3f15c172f8 100644 --- a/rules/require-array-join-separator.js +++ b/rules/require-array-join-separator.js @@ -9,7 +9,12 @@ const messages = { const selector = matches([ // `foo.join()` - methodCallSelector({method: 'join', argumentsLength: 0}), + methodCallSelector({ + method: 'join', + argumentsLength: 0, + includeOptionalCall: true, + includeOptionalMember: true, + }), // `[].join.call(foo)` and `Array.prototype.join.call(foo)` [ methodCallSelector({method: 'call', argumentsLength: 1}), diff --git a/test/require-array-join-separator.mjs b/test/require-array-join-separator.mjs index fa7740cb36..2aaa1b8f98 100644 --- a/test/require-array-join-separator.mjs +++ b/test/require-array-join-separator.mjs @@ -8,7 +8,6 @@ test.snapshot({ 'foo.join(",")', 'join()', 'foo.join(...[])', - 'foo?.join()', 'foo[join]()', 'foo["join"]()', '[].join.call(foo, ",")', @@ -71,5 +70,8 @@ test.snapshot({ )/**/ ) `, + 'foo?.join()', + 'foo.join?.()', + 'foo?.join?.()', ], }); diff --git a/test/snapshots/require-array-join-separator.mjs.md b/test/snapshots/require-array-join-separator.mjs.md index 3a1d224163..f53cc8edf7 100644 --- a/test/snapshots/require-array-join-separator.mjs.md +++ b/test/snapshots/require-array-join-separator.mjs.md @@ -192,3 +192,51 @@ Generated by [AVA](https://avajs.dev). | ^^^^ Missing the separator argument.␊ 26 | )␊ ` + +## Invalid #8 + 1 | foo?.join() + +> Output + + `␊ + 1 | foo?.join(',')␊ + ` + +> Error 1/1 + + `␊ + > 1 | foo?.join()␊ + | ^^ Missing the separator argument.␊ + ` + +## Invalid #9 + 1 | foo.join?.() + +> Output + + `␊ + 1 | foo.join?.(',')␊ + ` + +> Error 1/1 + + `␊ + > 1 | foo.join?.()␊ + | ^^ Missing the separator argument.␊ + ` + +## Invalid #10 + 1 | foo?.join?.() + +> Output + + `␊ + 1 | foo?.join?.(',')␊ + ` + +> Error 1/1 + + `␊ + > 1 | foo?.join?.()␊ + | ^^ Missing the separator argument.␊ + ` diff --git a/test/snapshots/require-array-join-separator.mjs.snap b/test/snapshots/require-array-join-separator.mjs.snap index 93be20ae958723a7008616baef0d6df6d1156eb4..0605f436df8913573abbd8fd36d1abc4530f82df 100644 GIT binary patch literal 752 zcmV@FvydR4Q00000000Av zVq{?8Vi24lKGD^w@n%Uy{?rA@TjH4*KtLCY`+!*bwAZP*FXk%Tx&80XT;^S(OkmMX zP|ON6MgHL}1>Yr6-&)>>%cbw{=41kkYC~}o5SxAy*Ja+K_>sTbXmwL3b0!m5^c52X zPi0|Xs9smN zu_n+I1)u~5h*R**EH2K>OIIk#NL46KEl4a%EXglYNGwV(%}vcK(L=RB4C)%7nf72S zG=Q!^bA&6@5ePLHw#SiZtpvKY_Ig+>_C&WBs0xe6Nwl0Pk`ZJE$Y2c+!wAUW)YsC| z2XTx+oM;fs1jK@in}T?;AeI@5xH*`o2Vz>FNLYe-AV-6|YJeLLxd}D;nC6UzGof&{LkVYa!UnPx;y@Cpfex07g8+~$#F?7tvIKJi z)~I5X!&fMwsSU(YCgCcQNGuve5k&*80?8RsE?_T@NG*{eJ6(v^c6%^%{J|c8ahBJpK}DjwwTW{#W(Z~z<7%SZOrndGa3nMZSm;`#s*k{t*nsMR iN^!Z5)Nm9>OLJIjBX_h^hqW>y!e#)O@=o4p2><}yQd98& literal 624 zcmV-$0+0PcRzVVjJBbM_dK-!(SQ!{*mkAUK%ZMrk&h}P`dA8#%6IgU2 z6mzjLFl^Y9So&RJV(YfrZNW3b{_ST1i&{bP0w87v`WOTlSs4Tw<+&6T3>9h=qGR>4 z@-y@Fk`r@sG}7|(brjTf)O9quP!tDq*Ir?Z6J>Pi7R`O zmOB|mp-uss2sU2>(*@2@7r>RETTMhbpctqNwbQYvD6vwnpeVm2zofDt6+JAll~(ys zw-C^Zv+P0*DiYnTO`N+iLok~dR}BcUn4Lf0BqeFTog22>AJipzaOgd+ek KrVAF72LJ%u+xlDp From 4364748268d4fc0b310facacf98b2b0a610703be Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 2 Nov 2021 11:17:25 +0800 Subject: [PATCH 2/3] Don't check optional call --- rules/require-array-join-separator.js | 1 - test/require-array-join-separator.mjs | 4 +-- .../require-array-join-separator.mjs.md | 32 ------------------ .../require-array-join-separator.mjs.snap | Bin 752 -> 668 bytes 4 files changed, 2 insertions(+), 35 deletions(-) diff --git a/rules/require-array-join-separator.js b/rules/require-array-join-separator.js index 3f15c172f8..b09b2f18eb 100644 --- a/rules/require-array-join-separator.js +++ b/rules/require-array-join-separator.js @@ -12,7 +12,6 @@ const selector = matches([ methodCallSelector({ method: 'join', argumentsLength: 0, - includeOptionalCall: true, includeOptionalMember: true, }), // `[].join.call(foo)` and `Array.prototype.join.call(foo)` diff --git a/test/require-array-join-separator.mjs b/test/require-array-join-separator.mjs index 2aaa1b8f98..5a13e8ae5f 100644 --- a/test/require-array-join-separator.mjs +++ b/test/require-array-join-separator.mjs @@ -10,6 +10,8 @@ test.snapshot({ 'foo.join(...[])', 'foo[join]()', 'foo["join"]()', + 'foo.join?.()', + 'foo?.join?.()', '[].join.call(foo, ",")', '[].join.call()', '[].join.call(...[foo])', @@ -71,7 +73,5 @@ test.snapshot({ ) `, 'foo?.join()', - 'foo.join?.()', - 'foo?.join?.()', ], }); diff --git a/test/snapshots/require-array-join-separator.mjs.md b/test/snapshots/require-array-join-separator.mjs.md index f53cc8edf7..820c0351f9 100644 --- a/test/snapshots/require-array-join-separator.mjs.md +++ b/test/snapshots/require-array-join-separator.mjs.md @@ -208,35 +208,3 @@ Generated by [AVA](https://avajs.dev). > 1 | foo?.join()␊ | ^^ Missing the separator argument.␊ ` - -## Invalid #9 - 1 | foo.join?.() - -> Output - - `␊ - 1 | foo.join?.(',')␊ - ` - -> Error 1/1 - - `␊ - > 1 | foo.join?.()␊ - | ^^ Missing the separator argument.␊ - ` - -## Invalid #10 - 1 | foo?.join?.() - -> Output - - `␊ - 1 | foo?.join?.(',')␊ - ` - -> Error 1/1 - - `␊ - > 1 | foo?.join?.()␊ - | ^^ Missing the separator argument.␊ - ` diff --git a/test/snapshots/require-array-join-separator.mjs.snap b/test/snapshots/require-array-join-separator.mjs.snap index 0605f436df8913573abbd8fd36d1abc4530f82df..e41d3d4a82c2fc48a1d314c28f32ace25879deb6 100644 GIT binary patch delta 630 zcmV-+0*U?b1)K#kK~_N^Q*L2!b7*gLAa*he0stLLFr1Mnn7k$$+c&}2ON$?i2mk;8 z000036Jumx;9!w5Gk?YOlejMP7R8VJ)kdqEI+-(>z@oWK5G=vMz)-!wOh`3DTGhDo z#*!}uj6fA2Q5Ps)48--j9A$SOx+nEKU{!N&8h;=YSo9bai?cE?OkDr1%Gx|WhwJ*A zjpyumCozFVgP{045YH|XC=`|vRSKN#trGKW$6F?_C_f}uiw0{R%p#gLSnj>7HjzFlvusx16YndV$K_-9<)c`S!fDBH3EiHWz#~8$k z2C+;)EV#HSh!+cDnW2cAgL!%&rUi} z5bOd@kc$l=PJqim+yIe+I07MO3FQNW56Cq#K$SLvxPOEb6r@H*D5e@g+`_2?Vw<2! zL7W0fGB7can^2>UY0hXk6AEWLlyC+oYam-84kUpZ=wP`x2mr}KoT-T}OE4#3jVeYt zeB}a~+CUt|0W69i9XVPL3UU?!xRA+2iMd1J|!0!E+;kmx}uR$ygdsNdx%yZg{RspkQ! znsd|m1DU|0&QLrBh$pW9R%LA-pTl+i&Bk+fypx!~qUWL5hkuQMVRo57p|FgoQs8WF zm6&Hc-ZFtjTcP+L5O3I%So&RJV(YfrZNW3b{_ST1i|VmM@Dw0E^!!|(Zq3E%FoQxOHRzm(MZeB*HKW{ zQPOIIk#NL46KEl4a%EXglYNGwV(%}vcK z(L=RB4C)%7nf72SG=Q!^bA&6@5ePLHw#SiZtpvKY_Ig+>_C&WBs0xe6Nwl0Pk`ZJE z$Y2c+!wAUW)YsC|2XTx+oM;fs1jK@in}T?;AeI@5xPLjArw3wMph#GPc_2rFylQ|f zXJ`o5WN3sU0k)kJ6v-eSiVFY*bw3bxD3P%5GjZw5OS7KJ}?M@Tq6TiX(NbB zI6;AGWQ1a>5yUN=Iv}UDw0Sn8blFA1Fize8Bs1^FONtqj&z}R zIu;crR_YZL<(K4_R2HP7hXuA0Iv?s50$OpF*Qh~7qPw+;b2nxPW)tITqTEcPi(O1>VZmexsTLv6h}*QSZgD9v=CH>wK5{YW&oM;PTpt<000{2J)i&p From 91eb5b45286a6f2e40b5d1f949a79f509a40c102 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 2 Nov 2021 11:18:05 +0800 Subject: [PATCH 3/3] Reduce diff --- test/require-array-join-separator.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/require-array-join-separator.mjs b/test/require-array-join-separator.mjs index 5a13e8ae5f..b0f861aa0e 100644 --- a/test/require-array-join-separator.mjs +++ b/test/require-array-join-separator.mjs @@ -8,10 +8,10 @@ test.snapshot({ 'foo.join(",")', 'join()', 'foo.join(...[])', - 'foo[join]()', - 'foo["join"]()', 'foo.join?.()', 'foo?.join?.()', + 'foo[join]()', + 'foo["join"]()', '[].join.call(foo, ",")', '[].join.call()', '[].join.call(...[foo])',