From 81b21a52cde0642256785131cd6ec16b012ad70b Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 21 Dec 2020 17:02:55 +0800 Subject: [PATCH] `no-unreadable-array-destructuring`: Update tests (#947) --- test/no-unreadable-array-destructuring.js | 66 +++-------- .../no-unreadable-array-destructuring.js.md | 110 ++++++++++++++++++ .../no-unreadable-array-destructuring.js.snap | Bin 217 -> 643 bytes 3 files changed, 126 insertions(+), 50 deletions(-) diff --git a/test/no-unreadable-array-destructuring.js b/test/no-unreadable-array-destructuring.js index 54d1710114..1f95accb41 100644 --- a/test/no-unreadable-array-destructuring.js +++ b/test/no-unreadable-array-destructuring.js @@ -1,11 +1,5 @@ import {test} from './utils/test'; -const errors = [ - { - messageId: 'no-unreadable-array-destructuring' - } -]; - test({ valid: [ 'const [, foo] = parts;', @@ -15,6 +9,8 @@ test({ 'const [foo,] = parts;', 'const [foo,,] = parts;', 'const [foo,, bar,, baz] = parts;', + '[,foo] = bar;', + '({parts: [,foo]} = bar);', 'function foo([, bar]) {}', 'function foo([bar]) {}', 'function foo([bar,,baz]) {}', @@ -26,51 +22,21 @@ test({ // This is stupid, but valid code 'const [,,] = parts;' ], - invalid: [ - { - code: 'const [,, foo] = parts;', - errors - }, - { - code: 'const [foo,,, bar] = parts;', - errors - }, - { - code: 'const [foo,,,] = parts;', - errors - }, - { - code: 'const [foo, bar,, baz ,,, qux] = parts;', - errors - }, - { - code: 'function foo([,, bar]) {}', - errors - }, - { - code: 'function foo([bar,,, baz]) {}', - errors - }, - { - code: 'function foo([bar,,,]) {}', - errors - }, - { - code: 'function foo([bar, baz,, qux ,,, quux]) {}', - errors - }, - { - code: 'const [,,...rest] = parts;', - errors - }, - // This is stupid, but valid code - { - code: 'const [,,,] = parts;', - errors - } - ] + invalid: [] }); test.visualize([ - 'const [foo, bar,, baz ,,, qux] = parts;' + 'const [,, foo] = parts;', + 'const [foo,,, bar] = parts;', + 'const [foo,,,] = parts;', + 'const [foo, bar,, baz ,,, qux] = parts;', + '[,, foo] = bar;', + '({parts: [,, foo]} = bar);', + 'function foo([,, bar]) {}', + 'function foo([bar,,, baz]) {}', + 'function foo([bar,,,]) {}', + 'function foo([bar, baz,, qux ,,, quux]) {}', + 'const [,,...rest] = parts;', + // This is stupid, but valid code + 'const [,,,] = parts;' ]); diff --git a/test/snapshots/no-unreadable-array-destructuring.js.md b/test/snapshots/no-unreadable-array-destructuring.js.md index d3b1a36eaa..4df427f049 100644 --- a/test/snapshots/no-unreadable-array-destructuring.js.md +++ b/test/snapshots/no-unreadable-array-destructuring.js.md @@ -6,6 +6,36 @@ Generated by [AVA](https://avajs.dev). ## no-unreadable-array-destructuring - #1 +> Snapshot 1 + + `␊ + Error 1/1:␊ + > 1 | const [,, foo] = parts;␊ + | ^^^^^^^^ Array destructuring may not contain consecutive ignored values.␊ + ` + +## no-unreadable-array-destructuring - #2 + +> Snapshot 1 + + `␊ + Error 1/1:␊ + > 1 | const [foo,,, bar] = parts;␊ + | ^^^^^^^^^^^^ Array destructuring may not contain consecutive ignored values.␊ + ` + +## no-unreadable-array-destructuring - #3 + +> Snapshot 1 + + `␊ + Error 1/1:␊ + > 1 | const [foo,,,] = parts;␊ + | ^^^^^^^^ Array destructuring may not contain consecutive ignored values.␊ + ` + +## no-unreadable-array-destructuring - #4 + > Snapshot 1 `␊ @@ -13,3 +43,83 @@ Generated by [AVA](https://avajs.dev). > 1 | const [foo, bar,, baz ,,, qux] = parts;␊ | ^^^^^^^^^^^^^^^^^^^^^^^^ Array destructuring may not contain consecutive ignored values.␊ ` + +## no-unreadable-array-destructuring - #5 + +> Snapshot 1 + + `␊ + Error 1/1:␊ + > 1 | [,, foo] = bar;␊ + | ^^^^^^^^ Array destructuring may not contain consecutive ignored values.␊ + ` + +## no-unreadable-array-destructuring - #6 + +> Snapshot 1 + + `␊ + Error 1/1:␊ + > 1 | ({parts: [,, foo]} = bar);␊ + | ^^^^^^^^ Array destructuring may not contain consecutive ignored values.␊ + ` + +## no-unreadable-array-destructuring - #7 + +> Snapshot 1 + + `␊ + Error 1/1:␊ + > 1 | function foo([,, bar]) {}␊ + | ^^^^^^^^ Array destructuring may not contain consecutive ignored values.␊ + ` + +## no-unreadable-array-destructuring - #8 + +> Snapshot 1 + + `␊ + Error 1/1:␊ + > 1 | function foo([bar,,, baz]) {}␊ + | ^^^^^^^^^^^^ Array destructuring may not contain consecutive ignored values.␊ + ` + +## no-unreadable-array-destructuring - #9 + +> Snapshot 1 + + `␊ + Error 1/1:␊ + > 1 | function foo([bar,,,]) {}␊ + | ^^^^^^^^ Array destructuring may not contain consecutive ignored values.␊ + ` + +## no-unreadable-array-destructuring - #10 + +> Snapshot 1 + + `␊ + Error 1/1:␊ + > 1 | function foo([bar, baz,, qux ,,, quux]) {}␊ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ Array destructuring may not contain consecutive ignored values.␊ + ` + +## no-unreadable-array-destructuring - #11 + +> Snapshot 1 + + `␊ + Error 1/1:␊ + > 1 | const [,,...rest] = parts;␊ + | ^^^^^^^^^^^ Array destructuring may not contain consecutive ignored values.␊ + ` + +## no-unreadable-array-destructuring - #12 + +> Snapshot 1 + + `␊ + Error 1/1:␊ + > 1 | const [,,,] = parts;␊ + | ^^^^^ Array destructuring may not contain consecutive ignored values.␊ + ` diff --git a/test/snapshots/no-unreadable-array-destructuring.js.snap b/test/snapshots/no-unreadable-array-destructuring.js.snap index df813fa8a7004a840abec29632424f04de187a78..0aef7d7ed4c8c9e08379c9c178c023c1fd7a57e7 100644 GIT binary patch literal 643 zcmV-}0(|{JRzVPRbT_1}G00000000BC zV`O09VNkcNtM(SuWllL>cYWr$7YBiYKrju69e5+NJ|(GFWV{Of7sjeGjS(!W1ytZR zPcWmRJVp136+`Qx_0v=s!J;RDxWYSqfv9$os3}7FeV0uO176tH>UjK zko>z`{iWh$5k|1+D;kUX!ML67(-}E2PeCFQS#0VCB3dFanQesMll5ds0F}%VUd5M=1ESkc`z;Ji* z*2yO3+Kk*kt(GPR+*r&A78PP=U|?oo2Zt0RD}x|YI|G+%QBi)8f}y^l6_=fYp+b#9 za(-TMi9&Q*e!h;5jzUsmQLKWkLP26tNwGDT0uaT4`Q#NoIZ?$UPd-K*vA=tSVMhp}H2` zSu_nY#(DzrNFWYrAAeBS=;-L_=@kL3A)KhF>!uDOjAS#Wa0O}^VN<2}FH?`3_TA^haU85CGc7&E*bj*&7g_w>(at1JPV2+?o5}%L1 dj!^*TJ5UOTrtJzM>Km%2YXFP`446;|0059`ABg|} literal 217 zcmV;~04D!IRzVA}CTK3iE+2~s00000000A1 zU|?WiWH|g*_ooPld-9w9=Xu~`9hyBqu&Hw-aj?`B!