prettier-plugin-multiline-arrays-2 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +3 -0
- package/LICENSE-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/README.md +91 -0
- package/dist/augments/array.d.ts +3 -0
- package/dist/augments/array.js +21 -0
- package/dist/augments/array.test.d.ts +1 -0
- package/dist/augments/array.test.js +34 -0
- package/dist/augments/doc.d.ts +5 -0
- package/dist/augments/doc.js +30 -0
- package/dist/augments/string.d.ts +1 -0
- package/dist/augments/string.js +6 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +46 -0
- package/dist/options.d.ts +32 -0
- package/dist/options.js +71 -0
- package/dist/options.test.d.ts +1 -0
- package/dist/options.test.js +48 -0
- package/dist/plugin-marker.d.ts +1 -0
- package/dist/plugin-marker.js +2 -0
- package/dist/preprocessing.d.ts +2 -0
- package/dist/preprocessing.js +94 -0
- package/dist/printer/child-docs.d.ts +18 -0
- package/dist/printer/child-docs.js +89 -0
- package/dist/printer/comment-triggers.d.ts +25 -0
- package/dist/printer/comment-triggers.js +327 -0
- package/dist/printer/comments.d.ts +2 -0
- package/dist/printer/comments.js +34 -0
- package/dist/printer/insert-new-lines.d.ts +15 -0
- package/dist/printer/insert-new-lines.js +580 -0
- package/dist/printer/insert-new-lines.test.d.ts +1 -0
- package/dist/printer/insert-new-lines.test.js +36 -0
- package/dist/printer/leading-new-line.d.ts +7 -0
- package/dist/printer/leading-new-line.js +31 -0
- package/dist/printer/multiline-array-printer.d.ts +4 -0
- package/dist/printer/multiline-array-printer.js +42 -0
- package/dist/printer/original-printer.d.ts +3 -0
- package/dist/printer/original-printer.js +10 -0
- package/dist/printer/supported-node-types.d.ts +9 -0
- package/dist/printer/supported-node-types.js +16 -0
- package/dist/printer/trailing-comma.d.ts +6 -0
- package/dist/printer/trailing-comma.js +28 -0
- package/dist/readme-examples/formatted-with-comments.example.d.ts +3 -0
- package/dist/readme-examples/formatted-with-comments.example.js +16 -0
- package/dist/readme-examples/formatted.example.d.ts +2 -0
- package/dist/readme-examples/formatted.example.js +12 -0
- package/dist/readme-examples/not-formatted.example.d.ts +2 -0
- package/dist/readme-examples/not-formatted.example.js +6 -0
- package/dist/readme-examples/prettier-options.example.d.ts +4 -0
- package/dist/readme-examples/prettier-options.example.js +5 -0
- package/dist/test/babel-ts.test.d.ts +1 -0
- package/dist/test/babel-ts.test.js +10 -0
- package/dist/test/javascript.test.d.ts +1 -0
- package/dist/test/javascript.test.js +702 -0
- package/dist/test/json.test.d.ts +1 -0
- package/dist/test/json.test.js +403 -0
- package/dist/test/json5.test.d.ts +1 -0
- package/dist/test/json5.test.js +210 -0
- package/dist/test/prettier-config.d.ts +2 -0
- package/dist/test/prettier-config.js +12 -0
- package/dist/test/prettier-versions.mock.script.d.ts +1 -0
- package/dist/test/prettier-versions.mock.script.js +123 -0
- package/dist/test/run-tests.mock.d.ts +17 -0
- package/dist/test/run-tests.mock.js +95 -0
- package/dist/test/typescript-tests.mock.d.ts +2 -0
- package/dist/test/typescript-tests.mock.js +1575 -0
- package/dist/test/typescript.test.d.ts +1 -0
- package/dist/test/typescript.test.js +10 -0
- package/package.json +117 -0
|
@@ -0,0 +1,1575 @@
|
|
|
1
|
+
import { capitalizeFirst } from '../augments/string.js';
|
|
2
|
+
import { nextLinePatternComment, nextWrapThresholdComment, resetComment, setLinePatternComment, setWrapThresholdComment, } from '../options.js';
|
|
3
|
+
export const typescriptTests = [
|
|
4
|
+
{
|
|
5
|
+
it: 'comment at end of argument list with multiline array parser',
|
|
6
|
+
code: `
|
|
7
|
+
export function hasProperty<ObjectGeneric extends object, KeyGeneric extends PropertyKey>(
|
|
8
|
+
inputObject: ObjectGeneric,
|
|
9
|
+
inputKey: KeyGeneric,
|
|
10
|
+
// @ts-ignore this type signature is actually exactly what I want
|
|
11
|
+
): inputObject is ObjectGeneric extends Record<KeyGeneric, any>
|
|
12
|
+
? Extract<ObjectGeneric, {[SubProperty in KeyGeneric]: unknown}>
|
|
13
|
+
: Record<KeyGeneric, unknown> {
|
|
14
|
+
return inputKey in inputObject;
|
|
15
|
+
}
|
|
16
|
+
`,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
it: 'works with greater than or less than inside of an array in typescript',
|
|
20
|
+
code: `
|
|
21
|
+
const thingie = [
|
|
22
|
+
otherThingie < 5 ? 'owl' : 'goat',
|
|
23
|
+
];
|
|
24
|
+
`,
|
|
25
|
+
options: {
|
|
26
|
+
multilineArraysWrapThreshold: 0,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
it: 'works with type accessors',
|
|
31
|
+
code: `
|
|
32
|
+
export function doThing(
|
|
33
|
+
[
|
|
34
|
+
data,
|
|
35
|
+
]: Parameters<stuff['param']>,
|
|
36
|
+
thing: string,
|
|
37
|
+
) {}
|
|
38
|
+
`,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
it: 'works even if filepath is undefined GitHub Issue #18 (thank you farmerpaul)',
|
|
42
|
+
code: `
|
|
43
|
+
const thingie = [
|
|
44
|
+
otherThingie < 5 ? 'owl' : 'goat',
|
|
45
|
+
];
|
|
46
|
+
`,
|
|
47
|
+
options: {
|
|
48
|
+
multilineArraysWrapThreshold: 0,
|
|
49
|
+
filepath: undefined,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
it: 'works with multiple nested arrays',
|
|
54
|
+
code: `
|
|
55
|
+
const thingie = [
|
|
56
|
+
[
|
|
57
|
+
1,
|
|
58
|
+
2,
|
|
59
|
+
3,
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
4,
|
|
63
|
+
5,
|
|
64
|
+
6,
|
|
65
|
+
0,
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
7,
|
|
69
|
+
8,
|
|
70
|
+
9,
|
|
71
|
+
],
|
|
72
|
+
[10],
|
|
73
|
+
];
|
|
74
|
+
`,
|
|
75
|
+
expect: `
|
|
76
|
+
const thingie = [
|
|
77
|
+
[
|
|
78
|
+
1,
|
|
79
|
+
2,
|
|
80
|
+
3,
|
|
81
|
+
],
|
|
82
|
+
[
|
|
83
|
+
4,
|
|
84
|
+
5,
|
|
85
|
+
6,
|
|
86
|
+
0,
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
7,
|
|
90
|
+
8,
|
|
91
|
+
9,
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
10,
|
|
95
|
+
],
|
|
96
|
+
];
|
|
97
|
+
`,
|
|
98
|
+
options: {
|
|
99
|
+
multilineArraysWrapThreshold: 0,
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
it: 'forces array wrapping if a trailing comma is used',
|
|
104
|
+
code: `
|
|
105
|
+
const myArray = [1, 2, 3,];
|
|
106
|
+
`,
|
|
107
|
+
expect: `
|
|
108
|
+
const myArray = [
|
|
109
|
+
1,
|
|
110
|
+
2,
|
|
111
|
+
3,
|
|
112
|
+
];
|
|
113
|
+
`,
|
|
114
|
+
options: {
|
|
115
|
+
multilineArraysWrapThreshold: 10,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
it: 'forces array wrapping if a preceding new line is manually entered',
|
|
120
|
+
code: `
|
|
121
|
+
const myArray = [
|
|
122
|
+
1, 2, 3];
|
|
123
|
+
`,
|
|
124
|
+
expect: `
|
|
125
|
+
const myArray = [
|
|
126
|
+
1,
|
|
127
|
+
2,
|
|
128
|
+
3,
|
|
129
|
+
];
|
|
130
|
+
`,
|
|
131
|
+
options: {
|
|
132
|
+
multilineArraysWrapThreshold: 10,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
it: 'an array without wrapping should only take up one line',
|
|
137
|
+
code: `
|
|
138
|
+
// ${nextWrapThresholdComment} 8
|
|
139
|
+
const flatArray = [0, 0, 0, 1, 1];
|
|
140
|
+
`,
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
it: 'wrap comment overrides trailing comma',
|
|
144
|
+
code: `
|
|
145
|
+
// ${nextWrapThresholdComment} 8
|
|
146
|
+
const flatArray = [0, 0, 0, 1, 1,];
|
|
147
|
+
`,
|
|
148
|
+
expect: `
|
|
149
|
+
// ${nextWrapThresholdComment} 8
|
|
150
|
+
const flatArray = [0, 0, 0, 1, 1];
|
|
151
|
+
`,
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
it: 'a nested array without wrapping should only take up one line',
|
|
155
|
+
code: `
|
|
156
|
+
const flatNestedArray = [
|
|
157
|
+
// ${nextWrapThresholdComment} 8
|
|
158
|
+
[0, 0, 0, 1, 1],
|
|
159
|
+
// ${nextWrapThresholdComment} 8
|
|
160
|
+
[0, 0, 0, 1, 1],
|
|
161
|
+
// ${nextWrapThresholdComment} 8
|
|
162
|
+
[0, 0, 0, 1, 1],
|
|
163
|
+
// ${nextWrapThresholdComment} 8
|
|
164
|
+
[0, 0, 0, 1, 1],
|
|
165
|
+
// ${nextWrapThresholdComment} 8
|
|
166
|
+
[0, 0, 0, 1, 1],
|
|
167
|
+
];
|
|
168
|
+
`,
|
|
169
|
+
options: {
|
|
170
|
+
multilineArraysWrapThreshold: 0,
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
it: 'set wrap threshold should carry through',
|
|
175
|
+
code: `
|
|
176
|
+
const flatNestedArray = [
|
|
177
|
+
// ${setWrapThresholdComment} 8
|
|
178
|
+
[0, 0, 0, 1, 1],
|
|
179
|
+
[0, 0, 0, 1, 1],
|
|
180
|
+
[0, 0, 0, 1, 1],
|
|
181
|
+
[0, 0, 0, 1, 1],
|
|
182
|
+
[0, 0, 0, 1, 1],
|
|
183
|
+
];
|
|
184
|
+
`,
|
|
185
|
+
options: {
|
|
186
|
+
multilineArraysWrapThreshold: 0,
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
it: 'next line comments should override set comments and trailing commas',
|
|
191
|
+
code: `
|
|
192
|
+
const flatNestedArray = [
|
|
193
|
+
// ${setWrapThresholdComment} 8
|
|
194
|
+
[0, 0, 0, 1, 1],
|
|
195
|
+
[0, 0, 0, 1, 1],
|
|
196
|
+
// ${nextWrapThresholdComment} 2
|
|
197
|
+
[
|
|
198
|
+
0,
|
|
199
|
+
0,
|
|
200
|
+
0,
|
|
201
|
+
1,
|
|
202
|
+
1,
|
|
203
|
+
],
|
|
204
|
+
// has trailing comma
|
|
205
|
+
[0, 0, 0, 1, 1,],
|
|
206
|
+
[0, 0, 0, 1, 1],
|
|
207
|
+
[0, 0, 0, 1, 1, 0, 1, 1, 1],
|
|
208
|
+
];
|
|
209
|
+
`,
|
|
210
|
+
expect: `
|
|
211
|
+
const flatNestedArray = [
|
|
212
|
+
// ${setWrapThresholdComment} 8
|
|
213
|
+
[0, 0, 0, 1, 1],
|
|
214
|
+
[0, 0, 0, 1, 1],
|
|
215
|
+
// ${nextWrapThresholdComment} 2
|
|
216
|
+
[
|
|
217
|
+
0,
|
|
218
|
+
0,
|
|
219
|
+
0,
|
|
220
|
+
1,
|
|
221
|
+
1,
|
|
222
|
+
],
|
|
223
|
+
// has trailing comma
|
|
224
|
+
[0, 0, 0, 1, 1],
|
|
225
|
+
[0, 0, 0, 1, 1],
|
|
226
|
+
[
|
|
227
|
+
0,
|
|
228
|
+
0,
|
|
229
|
+
0,
|
|
230
|
+
1,
|
|
231
|
+
1,
|
|
232
|
+
0,
|
|
233
|
+
1,
|
|
234
|
+
1,
|
|
235
|
+
1,
|
|
236
|
+
],
|
|
237
|
+
];
|
|
238
|
+
`,
|
|
239
|
+
options: {
|
|
240
|
+
multilineArraysWrapThreshold: 0,
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
it: 'does not force array wrapping if a trailing comma is not used',
|
|
245
|
+
code: `
|
|
246
|
+
const myArray = [1, 2, 3];
|
|
247
|
+
`,
|
|
248
|
+
options: {
|
|
249
|
+
multilineArraysWrapThreshold: 10,
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
it: 'works with array expansion in function parameters',
|
|
254
|
+
code: `
|
|
255
|
+
export function update(
|
|
256
|
+
partInfo: PartInfo,
|
|
257
|
+
[
|
|
258
|
+
callback,
|
|
259
|
+
]: [
|
|
260
|
+
OnOsThemeChangeCallback,
|
|
261
|
+
],
|
|
262
|
+
) {}
|
|
263
|
+
`,
|
|
264
|
+
options: {
|
|
265
|
+
multilineArraysWrapThreshold: 10,
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
it: 'works with array expansion in function parameters with multiple entries',
|
|
270
|
+
code: `
|
|
271
|
+
export function update(
|
|
272
|
+
partInfo: PartInfo,
|
|
273
|
+
[
|
|
274
|
+
callback,
|
|
275
|
+
otherThing,
|
|
276
|
+
]: [
|
|
277
|
+
OnOsThemeChangeCallback,
|
|
278
|
+
OtherThingHereToo,
|
|
279
|
+
],
|
|
280
|
+
) {}
|
|
281
|
+
`,
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
it: 'basic wrap threshold comment',
|
|
285
|
+
code: `
|
|
286
|
+
// ${nextWrapThresholdComment} 3
|
|
287
|
+
const thingieArray = ['hello'];
|
|
288
|
+
`,
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
it: 'still wraps really long text below the threshold',
|
|
292
|
+
code: `
|
|
293
|
+
// ${nextWrapThresholdComment} 3
|
|
294
|
+
const thingieArray = ['HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello'];
|
|
295
|
+
`,
|
|
296
|
+
expect: `
|
|
297
|
+
// ${nextWrapThresholdComment} 3
|
|
298
|
+
const thingieArray = [
|
|
299
|
+
'HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello',
|
|
300
|
+
];
|
|
301
|
+
`,
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
it: 'does not wrap really long text when the line count prevents it',
|
|
305
|
+
code: `
|
|
306
|
+
// ${nextLinePatternComment} 1 3
|
|
307
|
+
const thingieArray = ['hello', 'hello', 'HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello', 'HelloHelloHelloHelloHelloHelloHelloHelloHelloHello'];
|
|
308
|
+
`,
|
|
309
|
+
expect: `
|
|
310
|
+
// ${nextLinePatternComment} 1 3
|
|
311
|
+
const thingieArray = [
|
|
312
|
+
'hello',
|
|
313
|
+
'hello', 'HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello', 'HelloHelloHelloHelloHelloHelloHelloHelloHelloHello',
|
|
314
|
+
];
|
|
315
|
+
`,
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
it: 'invalid wrap threshold triggers error',
|
|
319
|
+
code: `
|
|
320
|
+
const thingieArray = ['hello'];
|
|
321
|
+
`,
|
|
322
|
+
options: {
|
|
323
|
+
multilineArraysWrapThreshold: 'fifty two',
|
|
324
|
+
},
|
|
325
|
+
failureMessage: 'Invalid multilineArraysWrapThreshold value. Expected an integer, but received "fifty two".',
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
it: 'wrap threshold through options',
|
|
329
|
+
code: `
|
|
330
|
+
const thingieArray = ['hello'];
|
|
331
|
+
`,
|
|
332
|
+
options: {
|
|
333
|
+
multilineArraysWrapThreshold: 3,
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
it: 'line count through options',
|
|
338
|
+
code: `
|
|
339
|
+
const thingieArray = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
|
|
340
|
+
`,
|
|
341
|
+
expect: `
|
|
342
|
+
const thingieArray = [
|
|
343
|
+
'a',
|
|
344
|
+
'b', 'c',
|
|
345
|
+
'd', 'e', 'f',
|
|
346
|
+
'g',
|
|
347
|
+
'h',
|
|
348
|
+
];
|
|
349
|
+
`,
|
|
350
|
+
options: {
|
|
351
|
+
multilineArraysLinePattern: '1 2 3',
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
it: 'invalid elements per line reverts to default',
|
|
356
|
+
code: `
|
|
357
|
+
const thingieArray = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q'];
|
|
358
|
+
`,
|
|
359
|
+
expect: `
|
|
360
|
+
const thingieArray = [
|
|
361
|
+
'a',
|
|
362
|
+
'b',
|
|
363
|
+
'c',
|
|
364
|
+
'd',
|
|
365
|
+
'e',
|
|
366
|
+
'f',
|
|
367
|
+
'g',
|
|
368
|
+
'h',
|
|
369
|
+
'i',
|
|
370
|
+
'j',
|
|
371
|
+
'k',
|
|
372
|
+
'l',
|
|
373
|
+
'm',
|
|
374
|
+
'n',
|
|
375
|
+
'o',
|
|
376
|
+
'p',
|
|
377
|
+
'q',
|
|
378
|
+
];
|
|
379
|
+
`,
|
|
380
|
+
options: {
|
|
381
|
+
multilineArraysLinePattern: '1 2 3 fff',
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
it: 'line count overrides threshold',
|
|
386
|
+
code: `
|
|
387
|
+
const thingieArray = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
|
|
388
|
+
`,
|
|
389
|
+
expect: `
|
|
390
|
+
const thingieArray = [
|
|
391
|
+
'a',
|
|
392
|
+
'b', 'c',
|
|
393
|
+
'd', 'e', 'f',
|
|
394
|
+
'g',
|
|
395
|
+
'h',
|
|
396
|
+
];
|
|
397
|
+
`,
|
|
398
|
+
options: {
|
|
399
|
+
multilineArraysLinePattern: '1 2 3',
|
|
400
|
+
multilineArraysWrapThreshold: 20,
|
|
401
|
+
},
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
it: 'pointless wrap threshold comment',
|
|
405
|
+
code: `
|
|
406
|
+
// ${nextWrapThresholdComment} 0
|
|
407
|
+
const thingieArray = [
|
|
408
|
+
'hello',
|
|
409
|
+
];
|
|
410
|
+
`,
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
// this was causing an error on the closing "}" at one point
|
|
414
|
+
it: 'interpolated string example',
|
|
415
|
+
code: `
|
|
416
|
+
if (children.length) {
|
|
417
|
+
// ${nextWrapThresholdComment} 1
|
|
418
|
+
return [\`\${input.type}:\`];
|
|
419
|
+
}
|
|
420
|
+
`,
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
it: 'array elements with dots',
|
|
424
|
+
code: `
|
|
425
|
+
parentDoc[childIndex] = [
|
|
426
|
+
doc.builders.hardlineWithoutBreakParent,
|
|
427
|
+
doc.builders.breakParent,
|
|
428
|
+
];
|
|
429
|
+
`,
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
it: 'single line comment with just one line count',
|
|
433
|
+
code: `
|
|
434
|
+
// ${nextLinePatternComment} 2
|
|
435
|
+
const originalArray: Readonly<number[]> = [
|
|
436
|
+
0,
|
|
437
|
+
1,
|
|
438
|
+
2,
|
|
439
|
+
3,
|
|
440
|
+
4,
|
|
441
|
+
] as const;
|
|
442
|
+
`,
|
|
443
|
+
expect: `
|
|
444
|
+
// ${nextLinePatternComment} 2
|
|
445
|
+
const originalArray: Readonly<number[]> = [
|
|
446
|
+
0, 1,
|
|
447
|
+
2, 3,
|
|
448
|
+
4,
|
|
449
|
+
] as const;
|
|
450
|
+
`,
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
it: 'line pattern comment targets array inside next export declaration',
|
|
454
|
+
code: `
|
|
455
|
+
// ${nextLinePatternComment} 2 1
|
|
456
|
+
export const linePatternArray = [
|
|
457
|
+
'a',
|
|
458
|
+
'b',
|
|
459
|
+
'c',
|
|
460
|
+
'd',
|
|
461
|
+
'e',
|
|
462
|
+
];
|
|
463
|
+
`,
|
|
464
|
+
expect: `
|
|
465
|
+
// ${nextLinePatternComment} 2 1
|
|
466
|
+
export const linePatternArray = [
|
|
467
|
+
'a', 'b',
|
|
468
|
+
'c',
|
|
469
|
+
'd', 'e',
|
|
470
|
+
];
|
|
471
|
+
`,
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
it: 'line pattern comment targets array inside next new expression GitHub Issue #73',
|
|
475
|
+
code: `
|
|
476
|
+
// ${nextLinePatternComment} 4
|
|
477
|
+
const bytes = new Uint8Array(
|
|
478
|
+
[
|
|
479
|
+
255,
|
|
480
|
+
0,
|
|
481
|
+
255,
|
|
482
|
+
255,
|
|
483
|
+
0,
|
|
484
|
+
0,
|
|
485
|
+
0,
|
|
486
|
+
255,
|
|
487
|
+
0,
|
|
488
|
+
0,
|
|
489
|
+
0,
|
|
490
|
+
255,
|
|
491
|
+
255,
|
|
492
|
+
0,
|
|
493
|
+
255,
|
|
494
|
+
255,
|
|
495
|
+
],
|
|
496
|
+
);
|
|
497
|
+
`,
|
|
498
|
+
expect: `
|
|
499
|
+
// ${nextLinePatternComment} 4
|
|
500
|
+
const bytes = new Uint8Array([
|
|
501
|
+
255, 0, 255, 255,
|
|
502
|
+
0, 0, 0, 255,
|
|
503
|
+
0, 0, 0, 255,
|
|
504
|
+
255, 0, 255, 255,
|
|
505
|
+
]);
|
|
506
|
+
`,
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
it: 'wrap threshold comment targets array inside next call expression GitHub Issue #73',
|
|
510
|
+
code: `
|
|
511
|
+
// ${nextWrapThresholdComment} 10
|
|
512
|
+
const values = createValues(
|
|
513
|
+
[
|
|
514
|
+
1,
|
|
515
|
+
2,
|
|
516
|
+
3,
|
|
517
|
+
],
|
|
518
|
+
);
|
|
519
|
+
`,
|
|
520
|
+
expect: `
|
|
521
|
+
// ${nextWrapThresholdComment} 10
|
|
522
|
+
const values = createValues([1, 2, 3]);
|
|
523
|
+
`,
|
|
524
|
+
options: {
|
|
525
|
+
multilineArraysWrapThreshold: 0,
|
|
526
|
+
},
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
it: 'set line pattern comment should carry through',
|
|
530
|
+
code: `
|
|
531
|
+
// ${setLinePatternComment} 2
|
|
532
|
+
const originalArray: Readonly<number[]> = [
|
|
533
|
+
0,
|
|
534
|
+
1,
|
|
535
|
+
2,
|
|
536
|
+
3,
|
|
537
|
+
4,
|
|
538
|
+
] as const;
|
|
539
|
+
const originalArray2: Readonly<number[]> = [
|
|
540
|
+
0,
|
|
541
|
+
1,
|
|
542
|
+
2,
|
|
543
|
+
3,
|
|
544
|
+
4,
|
|
545
|
+
] as const;
|
|
546
|
+
`,
|
|
547
|
+
expect: `
|
|
548
|
+
// ${setLinePatternComment} 2
|
|
549
|
+
const originalArray: Readonly<number[]> = [
|
|
550
|
+
0, 1,
|
|
551
|
+
2, 3,
|
|
552
|
+
4,
|
|
553
|
+
] as const;
|
|
554
|
+
const originalArray2: Readonly<number[]> = [
|
|
555
|
+
0, 1,
|
|
556
|
+
2, 3,
|
|
557
|
+
4,
|
|
558
|
+
] as const;
|
|
559
|
+
`,
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
it: 'sets array threshold for all array elements',
|
|
563
|
+
code: `
|
|
564
|
+
// ${setWrapThresholdComment} 8
|
|
565
|
+
const thing = [
|
|
566
|
+
[
|
|
567
|
+
0,
|
|
568
|
+
0,
|
|
569
|
+
0,
|
|
570
|
+
1,
|
|
571
|
+
1,
|
|
572
|
+
],
|
|
573
|
+
[
|
|
574
|
+
0,
|
|
575
|
+
0,
|
|
576
|
+
1,
|
|
577
|
+
1,
|
|
578
|
+
0,
|
|
579
|
+
],
|
|
580
|
+
[
|
|
581
|
+
0,
|
|
582
|
+
1,
|
|
583
|
+
1,
|
|
584
|
+
0,
|
|
585
|
+
0,
|
|
586
|
+
],
|
|
587
|
+
[
|
|
588
|
+
1,
|
|
589
|
+
1,
|
|
590
|
+
0,
|
|
591
|
+
0,
|
|
592
|
+
0,
|
|
593
|
+
],
|
|
594
|
+
[
|
|
595
|
+
1,
|
|
596
|
+
1,
|
|
597
|
+
0,
|
|
598
|
+
0,
|
|
599
|
+
0,
|
|
600
|
+
],
|
|
601
|
+
[
|
|
602
|
+
0,
|
|
603
|
+
1,
|
|
604
|
+
1,
|
|
605
|
+
0,
|
|
606
|
+
0,
|
|
607
|
+
],
|
|
608
|
+
[
|
|
609
|
+
0,
|
|
610
|
+
0,
|
|
611
|
+
1,
|
|
612
|
+
1,
|
|
613
|
+
0,
|
|
614
|
+
],
|
|
615
|
+
[
|
|
616
|
+
0,
|
|
617
|
+
0,
|
|
618
|
+
0,
|
|
619
|
+
1,
|
|
620
|
+
1,
|
|
621
|
+
]
|
|
622
|
+
];
|
|
623
|
+
`,
|
|
624
|
+
expect: `
|
|
625
|
+
// ${setWrapThresholdComment} 8
|
|
626
|
+
const thing = [
|
|
627
|
+
[0, 0, 0, 1, 1],
|
|
628
|
+
[0, 0, 1, 1, 0],
|
|
629
|
+
[0, 1, 1, 0, 0],
|
|
630
|
+
[1, 1, 0, 0, 0],
|
|
631
|
+
[1, 1, 0, 0, 0],
|
|
632
|
+
[0, 1, 1, 0, 0],
|
|
633
|
+
[0, 0, 1, 1, 0],
|
|
634
|
+
[0, 0, 0, 1, 1],
|
|
635
|
+
];
|
|
636
|
+
`,
|
|
637
|
+
},
|
|
638
|
+
{
|
|
639
|
+
it: 'still properly wraps when lots of comments exist',
|
|
640
|
+
code: `
|
|
641
|
+
const thing = [
|
|
642
|
+
// comment here
|
|
643
|
+
[
|
|
644
|
+
0,
|
|
645
|
+
0,
|
|
646
|
+
0,
|
|
647
|
+
// comment here
|
|
648
|
+
1,
|
|
649
|
+
1,
|
|
650
|
+
],
|
|
651
|
+
// comment here
|
|
652
|
+
[
|
|
653
|
+
0,
|
|
654
|
+
0,
|
|
655
|
+
// comment here
|
|
656
|
+
1,
|
|
657
|
+
1,
|
|
658
|
+
0,
|
|
659
|
+
],
|
|
660
|
+
[
|
|
661
|
+
0,
|
|
662
|
+
1,
|
|
663
|
+
1,
|
|
664
|
+
// comment here
|
|
665
|
+
0,
|
|
666
|
+
0,
|
|
667
|
+
],
|
|
668
|
+
[
|
|
669
|
+
1,
|
|
670
|
+
1,
|
|
671
|
+
// comment here
|
|
672
|
+
0,
|
|
673
|
+
0,
|
|
674
|
+
0,
|
|
675
|
+
],
|
|
676
|
+
[
|
|
677
|
+
1,
|
|
678
|
+
1,
|
|
679
|
+
0,
|
|
680
|
+
0,
|
|
681
|
+
0,
|
|
682
|
+
],
|
|
683
|
+
[
|
|
684
|
+
0,
|
|
685
|
+
1,
|
|
686
|
+
1,
|
|
687
|
+
0,
|
|
688
|
+
0,
|
|
689
|
+
],
|
|
690
|
+
[
|
|
691
|
+
0,
|
|
692
|
+
0,
|
|
693
|
+
1,
|
|
694
|
+
1,
|
|
695
|
+
0,
|
|
696
|
+
// comment here
|
|
697
|
+
],
|
|
698
|
+
// comment here
|
|
699
|
+
[
|
|
700
|
+
0,
|
|
701
|
+
0,
|
|
702
|
+
0,
|
|
703
|
+
1,
|
|
704
|
+
1,
|
|
705
|
+
// comment here
|
|
706
|
+
],
|
|
707
|
+
// comment here
|
|
708
|
+
];
|
|
709
|
+
`,
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
it: 'wraps array with multiline comments',
|
|
713
|
+
code: `
|
|
714
|
+
/*
|
|
715
|
+
ANOTHER multiline comment
|
|
716
|
+
*/
|
|
717
|
+
const bigBoi = [
|
|
718
|
+
1,
|
|
719
|
+
2,
|
|
720
|
+
3,
|
|
721
|
+
4,
|
|
722
|
+
5,
|
|
723
|
+
/*
|
|
724
|
+
MULTILINE COMMENT HERE
|
|
725
|
+
*/
|
|
726
|
+
6,
|
|
727
|
+
7,
|
|
728
|
+
8,
|
|
729
|
+
9,
|
|
730
|
+
10,
|
|
731
|
+
[
|
|
732
|
+
/*
|
|
733
|
+
ANOTHER multiline comment
|
|
734
|
+
*/
|
|
735
|
+
101,
|
|
736
|
+
102,
|
|
737
|
+
103,
|
|
738
|
+
104,
|
|
739
|
+
/*
|
|
740
|
+
ANOTHER multiline comment
|
|
741
|
+
*/
|
|
742
|
+
],
|
|
743
|
+
11,
|
|
744
|
+
12,
|
|
745
|
+
13,
|
|
746
|
+
14,
|
|
747
|
+
15,
|
|
748
|
+
16,
|
|
749
|
+
17,
|
|
750
|
+
18,
|
|
751
|
+
19,
|
|
752
|
+
20,
|
|
753
|
+
21,
|
|
754
|
+
22,
|
|
755
|
+
23,
|
|
756
|
+
];
|
|
757
|
+
/*
|
|
758
|
+
ANOTHER multiline comment
|
|
759
|
+
*/
|
|
760
|
+
`,
|
|
761
|
+
},
|
|
762
|
+
{
|
|
763
|
+
it: 'handles block comment starting with a brace GitHub Issue #56',
|
|
764
|
+
code: `
|
|
765
|
+
const test = [
|
|
766
|
+
/*{
|
|
767
|
+
},*/
|
|
768
|
+
{},
|
|
769
|
+
];
|
|
770
|
+
`,
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
it: 'line pattern comments should override options property',
|
|
774
|
+
code: `
|
|
775
|
+
const pl = [
|
|
776
|
+
'prettier-plugin-sort-json', 'prettier-plugin-packagejson',
|
|
777
|
+
'prettier-plugin-multiline-arrays', 'prettier-plugin-organize-imports', 'prettier-plugin-jsdoc',
|
|
778
|
+
];
|
|
779
|
+
|
|
780
|
+
// ${nextLinePatternComment} 2 1
|
|
781
|
+
const availableTags = [
|
|
782
|
+
'a', 'aside', 'b', 'blockquote', 'br', 'code', 'em', 'figcaption', 'figure', 'h3', 'h4', 'hr', 'i', 'iframe', 'img', 'li', 'ol', 'p', 'pre', 's', 'strong', 'u', 'ul', 'video',
|
|
783
|
+
'table'
|
|
784
|
+
]
|
|
785
|
+
`,
|
|
786
|
+
expect: `
|
|
787
|
+
const pl = [
|
|
788
|
+
'prettier-plugin-sort-json', 'prettier-plugin-packagejson', 'prettier-plugin-multiline-arrays',
|
|
789
|
+
'prettier-plugin-organize-imports', 'prettier-plugin-jsdoc',
|
|
790
|
+
];
|
|
791
|
+
|
|
792
|
+
// ${nextLinePatternComment} 2 1
|
|
793
|
+
const availableTags = [
|
|
794
|
+
'a', 'aside',
|
|
795
|
+
'b',
|
|
796
|
+
'blockquote', 'br',
|
|
797
|
+
'code',
|
|
798
|
+
'em', 'figcaption',
|
|
799
|
+
'figure',
|
|
800
|
+
'h3', 'h4',
|
|
801
|
+
'hr',
|
|
802
|
+
'i', 'iframe',
|
|
803
|
+
'img',
|
|
804
|
+
'li', 'ol',
|
|
805
|
+
'p',
|
|
806
|
+
'pre', 's',
|
|
807
|
+
'strong',
|
|
808
|
+
'u', 'ul',
|
|
809
|
+
'video',
|
|
810
|
+
'table',
|
|
811
|
+
];
|
|
812
|
+
`,
|
|
813
|
+
options: {
|
|
814
|
+
multilineArraysLinePattern: '3',
|
|
815
|
+
},
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
it: 'reset should clear set comment',
|
|
819
|
+
code: `
|
|
820
|
+
// ${setLinePatternComment} 2
|
|
821
|
+
const originalArray: Readonly<number[]> = [
|
|
822
|
+
0,
|
|
823
|
+
1,
|
|
824
|
+
2,
|
|
825
|
+
3,
|
|
826
|
+
4,
|
|
827
|
+
] as const;
|
|
828
|
+
// ${resetComment}
|
|
829
|
+
const originalArray2: Readonly<number[]> = [
|
|
830
|
+
0,
|
|
831
|
+
1,
|
|
832
|
+
2,
|
|
833
|
+
3,
|
|
834
|
+
4,
|
|
835
|
+
] as const;
|
|
836
|
+
`,
|
|
837
|
+
expect: `
|
|
838
|
+
// ${setLinePatternComment} 2
|
|
839
|
+
const originalArray: Readonly<number[]> = [
|
|
840
|
+
0, 1,
|
|
841
|
+
2, 3,
|
|
842
|
+
4,
|
|
843
|
+
] as const;
|
|
844
|
+
// ${resetComment}
|
|
845
|
+
const originalArray2: Readonly<number[]> = [
|
|
846
|
+
0,
|
|
847
|
+
1,
|
|
848
|
+
2,
|
|
849
|
+
3,
|
|
850
|
+
4,
|
|
851
|
+
] as const;
|
|
852
|
+
`,
|
|
853
|
+
},
|
|
854
|
+
{
|
|
855
|
+
it: 'single line comment with just one line wrapped',
|
|
856
|
+
code: `
|
|
857
|
+
describe(filterMap.name, () => {
|
|
858
|
+
// ${nextLinePatternComment} 2
|
|
859
|
+
const originalArray: Readonly<number[]> = [
|
|
860
|
+
0,
|
|
861
|
+
1,
|
|
862
|
+
2,
|
|
863
|
+
3,
|
|
864
|
+
4,
|
|
865
|
+
] as const;
|
|
866
|
+
});
|
|
867
|
+
`,
|
|
868
|
+
expect: `
|
|
869
|
+
describe(filterMap.name, () => {
|
|
870
|
+
// ${nextLinePatternComment} 2
|
|
871
|
+
const originalArray: Readonly<number[]> = [
|
|
872
|
+
0, 1,
|
|
873
|
+
2, 3,
|
|
874
|
+
4,
|
|
875
|
+
] as const;
|
|
876
|
+
});
|
|
877
|
+
`,
|
|
878
|
+
},
|
|
879
|
+
{
|
|
880
|
+
it: 'TS array with just a comment',
|
|
881
|
+
code: `
|
|
882
|
+
const myObject = {
|
|
883
|
+
data: [
|
|
884
|
+
// comment
|
|
885
|
+
],
|
|
886
|
+
};
|
|
887
|
+
`,
|
|
888
|
+
},
|
|
889
|
+
{
|
|
890
|
+
it: 'TS array with a bunch of comments',
|
|
891
|
+
code: `
|
|
892
|
+
const myObject = {
|
|
893
|
+
data: [
|
|
894
|
+
// comment
|
|
895
|
+
// comment
|
|
896
|
+
// comment
|
|
897
|
+
// comment
|
|
898
|
+
// comment
|
|
899
|
+
// comment
|
|
900
|
+
// comment
|
|
901
|
+
// comment
|
|
902
|
+
// comment
|
|
903
|
+
// comment
|
|
904
|
+
// comment
|
|
905
|
+
// comment
|
|
906
|
+
],
|
|
907
|
+
};
|
|
908
|
+
`,
|
|
909
|
+
},
|
|
910
|
+
{
|
|
911
|
+
// caused a max call stack exceeded error once
|
|
912
|
+
it: 'single object element with multiline template',
|
|
913
|
+
code: `
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
const stuff = [
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
{
|
|
922
|
+
innerStuff: \`
|
|
923
|
+
const myVar: object = {a: 'where', b: 'everywhere'};
|
|
924
|
+
\`,
|
|
925
|
+
},
|
|
926
|
+
];
|
|
927
|
+
`,
|
|
928
|
+
expect: `
|
|
929
|
+
const stuff = [
|
|
930
|
+
{
|
|
931
|
+
innerStuff: \`
|
|
932
|
+
const myVar: object = {a: 'where', b: 'everywhere'};
|
|
933
|
+
\`,
|
|
934
|
+
},
|
|
935
|
+
];
|
|
936
|
+
`,
|
|
937
|
+
},
|
|
938
|
+
{
|
|
939
|
+
it: 'long function definition with multiline array parser',
|
|
940
|
+
code: `
|
|
941
|
+
export async function selectFiles(
|
|
942
|
+
inputProperties: OpenDialogProperty[] = [
|
|
943
|
+
OpenDialogProperty.multiSelections,
|
|
944
|
+
OpenDialogProperty.openFile,
|
|
945
|
+
OpenDialogProperty.openDirectory,
|
|
946
|
+
],
|
|
947
|
+
): Promise<undefined | string[]> {}
|
|
948
|
+
`,
|
|
949
|
+
},
|
|
950
|
+
{
|
|
951
|
+
it: 'comment after end of block with multiline array parser',
|
|
952
|
+
code: `
|
|
953
|
+
if (thing) {
|
|
954
|
+
}
|
|
955
|
+
// otherwise we are editing currently existing songs
|
|
956
|
+
else {
|
|
957
|
+
}
|
|
958
|
+
`,
|
|
959
|
+
},
|
|
960
|
+
{
|
|
961
|
+
it: 'still sorts imports with multiline parser',
|
|
962
|
+
code: `
|
|
963
|
+
import {notUsed} from 'blah';
|
|
964
|
+
const thingie = [
|
|
965
|
+
'a',
|
|
966
|
+
'b',
|
|
967
|
+
];
|
|
968
|
+
`,
|
|
969
|
+
expect: `
|
|
970
|
+
const thingie = [
|
|
971
|
+
'a',
|
|
972
|
+
'b',
|
|
973
|
+
];
|
|
974
|
+
`,
|
|
975
|
+
},
|
|
976
|
+
{
|
|
977
|
+
it: 'deep array call should include trailing comma still',
|
|
978
|
+
code: `
|
|
979
|
+
expect(createArrayValidator(typeofValidators.boolean)([3, 4])).toBe(false);
|
|
980
|
+
`,
|
|
981
|
+
expect: `
|
|
982
|
+
expect(
|
|
983
|
+
createArrayValidator(typeofValidators.boolean)([
|
|
984
|
+
3,
|
|
985
|
+
4,
|
|
986
|
+
]),
|
|
987
|
+
).toBe(false);
|
|
988
|
+
`,
|
|
989
|
+
options: {
|
|
990
|
+
multilineArraysWrapThreshold: 0,
|
|
991
|
+
},
|
|
992
|
+
},
|
|
993
|
+
{
|
|
994
|
+
it: 'does not wrap an empty array if threshold is 1',
|
|
995
|
+
code: `
|
|
996
|
+
const thing = [];
|
|
997
|
+
`,
|
|
998
|
+
options: {
|
|
999
|
+
multilineArraysWrapThreshold: 1,
|
|
1000
|
+
},
|
|
1001
|
+
},
|
|
1002
|
+
{
|
|
1003
|
+
it: 'handles a simple array',
|
|
1004
|
+
code: `
|
|
1005
|
+
const arr = [
|
|
1006
|
+
1,
|
|
1007
|
+
3,
|
|
1008
|
+
];
|
|
1009
|
+
`,
|
|
1010
|
+
},
|
|
1011
|
+
{
|
|
1012
|
+
it: 'handles a comment being inside of an array',
|
|
1013
|
+
code: `
|
|
1014
|
+
const arr = [
|
|
1015
|
+
1,
|
|
1016
|
+
// 2,
|
|
1017
|
+
3,
|
|
1018
|
+
];
|
|
1019
|
+
`,
|
|
1020
|
+
},
|
|
1021
|
+
{
|
|
1022
|
+
it: 'handles as const with trailing commas',
|
|
1023
|
+
code: `
|
|
1024
|
+
function derp() {
|
|
1025
|
+
return [
|
|
1026
|
+
{
|
|
1027
|
+
operation: 'update',
|
|
1028
|
+
content: 'text',
|
|
1029
|
+
} as const,
|
|
1030
|
+
];
|
|
1031
|
+
}
|
|
1032
|
+
`,
|
|
1033
|
+
},
|
|
1034
|
+
{
|
|
1035
|
+
it: 'handles as const without trailing commas',
|
|
1036
|
+
code: `
|
|
1037
|
+
function derp() {
|
|
1038
|
+
return [
|
|
1039
|
+
{
|
|
1040
|
+
operation: 'update',
|
|
1041
|
+
content: 'text'
|
|
1042
|
+
} as const
|
|
1043
|
+
];
|
|
1044
|
+
}
|
|
1045
|
+
`,
|
|
1046
|
+
options: {
|
|
1047
|
+
trailingComma: 'none',
|
|
1048
|
+
},
|
|
1049
|
+
},
|
|
1050
|
+
{
|
|
1051
|
+
it: 'handles array ending with trailing commas',
|
|
1052
|
+
code: `
|
|
1053
|
+
const derp = {
|
|
1054
|
+
files: [],
|
|
1055
|
+
references: [
|
|
1056
|
+
{path: './tsconfig.app.json'},
|
|
1057
|
+
{path: './tsconfig.node.json'},
|
|
1058
|
+
],
|
|
1059
|
+
};
|
|
1060
|
+
`,
|
|
1061
|
+
},
|
|
1062
|
+
{
|
|
1063
|
+
it: 'handles array ending without trailing commas',
|
|
1064
|
+
code: `
|
|
1065
|
+
const derp = {
|
|
1066
|
+
files: [],
|
|
1067
|
+
references: [
|
|
1068
|
+
{path: './tsconfig.app.json'},
|
|
1069
|
+
{path: './tsconfig.node.json'}
|
|
1070
|
+
]
|
|
1071
|
+
};
|
|
1072
|
+
`,
|
|
1073
|
+
options: {
|
|
1074
|
+
trailingComma: 'none',
|
|
1075
|
+
},
|
|
1076
|
+
},
|
|
1077
|
+
{
|
|
1078
|
+
it: 'formats a map correctly without commas',
|
|
1079
|
+
code: `
|
|
1080
|
+
const array = [
|
|
1081
|
+
1,
|
|
1082
|
+
otherArray.map((it) => !it)
|
|
1083
|
+
];
|
|
1084
|
+
`,
|
|
1085
|
+
options: {
|
|
1086
|
+
trailingComma: 'none',
|
|
1087
|
+
},
|
|
1088
|
+
},
|
|
1089
|
+
{
|
|
1090
|
+
it: 'does wrap an empty array if it contains comments',
|
|
1091
|
+
code: `
|
|
1092
|
+
const thing = [
|
|
1093
|
+
// comment here
|
|
1094
|
+
];
|
|
1095
|
+
`,
|
|
1096
|
+
},
|
|
1097
|
+
{
|
|
1098
|
+
it: 'not arrays but callbacks with multiline array parser',
|
|
1099
|
+
code: `
|
|
1100
|
+
expose({
|
|
1101
|
+
versions: process.versions,
|
|
1102
|
+
apiRequest: async (
|
|
1103
|
+
details: ApiRequestDetails<ApiRequestType>,
|
|
1104
|
+
): Promise<ApiFullResponse<ApiRequestType>> => {
|
|
1105
|
+
async function waitForResponse(): Promise<ApiFullResponse<ApiRequestType>> {
|
|
1106
|
+
return new Promise((resolve) => {
|
|
1107
|
+
ipcRenderer.once(
|
|
1108
|
+
getApiResponseEventName(details.type, requestId),
|
|
1109
|
+
(event, data) => {
|
|
1110
|
+
resolve(data);
|
|
1111
|
+
},
|
|
1112
|
+
);
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
},
|
|
1116
|
+
});
|
|
1117
|
+
`,
|
|
1118
|
+
},
|
|
1119
|
+
{
|
|
1120
|
+
it: 'keeps parentheses ending',
|
|
1121
|
+
code: `
|
|
1122
|
+
eat(
|
|
1123
|
+
derp
|
|
1124
|
+
.pleaseMakeThisMethodSuperLongSoItWraps()
|
|
1125
|
+
.pleaseMakeThisMethodSuperLongSoItWraps()
|
|
1126
|
+
.pleaseMakeThisMethodSuperLongSoItWraps()
|
|
1127
|
+
.pleaseMakeThisMethodSuperLongSoItWraps(),
|
|
1128
|
+
);
|
|
1129
|
+
`,
|
|
1130
|
+
},
|
|
1131
|
+
{
|
|
1132
|
+
it: 'keeps parentheses ending again',
|
|
1133
|
+
code: `
|
|
1134
|
+
Object.values(badPage.elementExamples).forEach((example) =>
|
|
1135
|
+
assert.isLengthExactly(example.errors, 1),
|
|
1136
|
+
);
|
|
1137
|
+
`,
|
|
1138
|
+
},
|
|
1139
|
+
{
|
|
1140
|
+
it: 'config object',
|
|
1141
|
+
code: `
|
|
1142
|
+
const config = {
|
|
1143
|
+
directories: {
|
|
1144
|
+
output: 'dist',
|
|
1145
|
+
buildResources: 'build-resources',
|
|
1146
|
+
},
|
|
1147
|
+
files: [
|
|
1148
|
+
'packages/**/dist/**',
|
|
1149
|
+
],
|
|
1150
|
+
extraMetadata: {
|
|
1151
|
+
version: viteVersion,
|
|
1152
|
+
},
|
|
1153
|
+
};
|
|
1154
|
+
`,
|
|
1155
|
+
options: {
|
|
1156
|
+
multilineArraysWrapThreshold: 1,
|
|
1157
|
+
},
|
|
1158
|
+
},
|
|
1159
|
+
{
|
|
1160
|
+
it: 'nested single-line objects on multiple lines',
|
|
1161
|
+
code: `
|
|
1162
|
+
const nested = [
|
|
1163
|
+
{success: true, filePath: ''},
|
|
1164
|
+
{success: false, error: 'hello there', filePath: ''},
|
|
1165
|
+
{success: false, error: '', filePath: ''},
|
|
1166
|
+
];
|
|
1167
|
+
`,
|
|
1168
|
+
},
|
|
1169
|
+
{
|
|
1170
|
+
it: 'nested single-line objects all on one line',
|
|
1171
|
+
code: `
|
|
1172
|
+
const nested = [{success: true, filePath: ''}, {success: false, error: 'hello there', filePath: ''}, {success: false, error: '', filePath: ''}];
|
|
1173
|
+
`,
|
|
1174
|
+
expect: `
|
|
1175
|
+
const nested = [
|
|
1176
|
+
{success: true, filePath: ''},
|
|
1177
|
+
{success: false, error: 'hello there', filePath: ''},
|
|
1178
|
+
{success: false, error: '', filePath: ''},
|
|
1179
|
+
];
|
|
1180
|
+
`,
|
|
1181
|
+
},
|
|
1182
|
+
{
|
|
1183
|
+
it: 'nested multi-line objects',
|
|
1184
|
+
code: `
|
|
1185
|
+
const nested = [{
|
|
1186
|
+
success: true, filePath: ''}, {
|
|
1187
|
+
success: false, error: 'hello there', filePath: ''}, {
|
|
1188
|
+
success: false, error: '', filePath: ''}];
|
|
1189
|
+
`,
|
|
1190
|
+
expect: `
|
|
1191
|
+
const nested = [
|
|
1192
|
+
{
|
|
1193
|
+
success: true,
|
|
1194
|
+
filePath: '',
|
|
1195
|
+
},
|
|
1196
|
+
{
|
|
1197
|
+
success: false,
|
|
1198
|
+
error: 'hello there',
|
|
1199
|
+
filePath: '',
|
|
1200
|
+
},
|
|
1201
|
+
{
|
|
1202
|
+
success: false,
|
|
1203
|
+
error: '',
|
|
1204
|
+
filePath: '',
|
|
1205
|
+
},
|
|
1206
|
+
];
|
|
1207
|
+
`,
|
|
1208
|
+
},
|
|
1209
|
+
{
|
|
1210
|
+
it: 'multiple arrays and even one with a trigger comment',
|
|
1211
|
+
code: `
|
|
1212
|
+
const varNoLine = ['a', 'b'];
|
|
1213
|
+
const varOneNewLine = [
|
|
1214
|
+
'a', 'b',
|
|
1215
|
+
];
|
|
1216
|
+
const nestedArray = [
|
|
1217
|
+
'q', 'r',
|
|
1218
|
+
['s', 't'],
|
|
1219
|
+
];
|
|
1220
|
+
// ${capitalizeFirst(nextLinePatternComment)} 2 1 3
|
|
1221
|
+
const setNumberPerLine = [
|
|
1222
|
+
'a', 'b',
|
|
1223
|
+
'c',
|
|
1224
|
+
'd',
|
|
1225
|
+
'e',
|
|
1226
|
+
];
|
|
1227
|
+
|
|
1228
|
+
`,
|
|
1229
|
+
expect: `
|
|
1230
|
+
const varNoLine = [
|
|
1231
|
+
'a',
|
|
1232
|
+
'b',
|
|
1233
|
+
];
|
|
1234
|
+
const varOneNewLine = [
|
|
1235
|
+
'a',
|
|
1236
|
+
'b',
|
|
1237
|
+
];
|
|
1238
|
+
const nestedArray = [
|
|
1239
|
+
'q',
|
|
1240
|
+
'r',
|
|
1241
|
+
[
|
|
1242
|
+
's',
|
|
1243
|
+
't',
|
|
1244
|
+
],
|
|
1245
|
+
];
|
|
1246
|
+
// ${capitalizeFirst(nextLinePatternComment)} 2 1 3
|
|
1247
|
+
const setNumberPerLine = [
|
|
1248
|
+
'a', 'b',
|
|
1249
|
+
'c',
|
|
1250
|
+
'd', 'e',
|
|
1251
|
+
];
|
|
1252
|
+
`,
|
|
1253
|
+
options: {
|
|
1254
|
+
multilineArraysWrapThreshold: 1,
|
|
1255
|
+
},
|
|
1256
|
+
},
|
|
1257
|
+
{
|
|
1258
|
+
it: 'no threshold set with multiple arrays, one having a trigger comment',
|
|
1259
|
+
code: `
|
|
1260
|
+
const varNoLine = ['a', 'b'];
|
|
1261
|
+
const varOneNewLine = [
|
|
1262
|
+
'a', 'b',
|
|
1263
|
+
];
|
|
1264
|
+
const nestedArray = [
|
|
1265
|
+
'q', 'r',
|
|
1266
|
+
['s', 't'],
|
|
1267
|
+
];
|
|
1268
|
+
// ${capitalizeFirst(nextLinePatternComment)} 2 1 3
|
|
1269
|
+
const setNumberPerLine = [
|
|
1270
|
+
'a', 'b',
|
|
1271
|
+
'c',
|
|
1272
|
+
'd',
|
|
1273
|
+
'e',
|
|
1274
|
+
];
|
|
1275
|
+
|
|
1276
|
+
`,
|
|
1277
|
+
expect: `
|
|
1278
|
+
const varNoLine = ['a', 'b'];
|
|
1279
|
+
const varOneNewLine = [
|
|
1280
|
+
'a',
|
|
1281
|
+
'b',
|
|
1282
|
+
];
|
|
1283
|
+
const nestedArray = [
|
|
1284
|
+
'q',
|
|
1285
|
+
'r',
|
|
1286
|
+
['s', 't'],
|
|
1287
|
+
];
|
|
1288
|
+
// ${capitalizeFirst(nextLinePatternComment)} 2 1 3
|
|
1289
|
+
const setNumberPerLine = [
|
|
1290
|
+
'a', 'b',
|
|
1291
|
+
'c',
|
|
1292
|
+
'd', 'e',
|
|
1293
|
+
];
|
|
1294
|
+
`,
|
|
1295
|
+
},
|
|
1296
|
+
{
|
|
1297
|
+
it: 'array with single line trigger comment',
|
|
1298
|
+
code: `
|
|
1299
|
+
// ${nextLinePatternComment} 2 1 3
|
|
1300
|
+
const setNumberPerLine = [
|
|
1301
|
+
'a', 'b',
|
|
1302
|
+
'c',
|
|
1303
|
+
'd',
|
|
1304
|
+
'e',
|
|
1305
|
+
'f',
|
|
1306
|
+
'g',
|
|
1307
|
+
'h',
|
|
1308
|
+
'i',
|
|
1309
|
+
'j',
|
|
1310
|
+
'k',
|
|
1311
|
+
];`,
|
|
1312
|
+
expect: `
|
|
1313
|
+
// ${nextLinePatternComment} 2 1 3
|
|
1314
|
+
const setNumberPerLine = [
|
|
1315
|
+
'a', 'b',
|
|
1316
|
+
'c',
|
|
1317
|
+
'd', 'e', 'f',
|
|
1318
|
+
'g', 'h',
|
|
1319
|
+
'i',
|
|
1320
|
+
'j', 'k',
|
|
1321
|
+
];
|
|
1322
|
+
`,
|
|
1323
|
+
},
|
|
1324
|
+
{
|
|
1325
|
+
it: 'array with line trigger comment using commas',
|
|
1326
|
+
code: `
|
|
1327
|
+
// ${nextLinePatternComment} 2, 1, 3
|
|
1328
|
+
const setNumberPerLine = [
|
|
1329
|
+
'a', 'b',
|
|
1330
|
+
'c',
|
|
1331
|
+
'd',
|
|
1332
|
+
'e',
|
|
1333
|
+
'f',
|
|
1334
|
+
'g',
|
|
1335
|
+
'h',
|
|
1336
|
+
'i',
|
|
1337
|
+
'j',
|
|
1338
|
+
'k',
|
|
1339
|
+
];`,
|
|
1340
|
+
expect: `
|
|
1341
|
+
// ${nextLinePatternComment} 2, 1, 3
|
|
1342
|
+
const setNumberPerLine = [
|
|
1343
|
+
'a', 'b',
|
|
1344
|
+
'c',
|
|
1345
|
+
'd', 'e', 'f',
|
|
1346
|
+
'g', 'h',
|
|
1347
|
+
'i',
|
|
1348
|
+
'j', 'k',
|
|
1349
|
+
];
|
|
1350
|
+
`,
|
|
1351
|
+
},
|
|
1352
|
+
{
|
|
1353
|
+
it: 'nested array',
|
|
1354
|
+
code: `
|
|
1355
|
+
const nestedArray = [
|
|
1356
|
+
'q', 'r',
|
|
1357
|
+
['s', 't'],
|
|
1358
|
+
];`,
|
|
1359
|
+
expect: `
|
|
1360
|
+
const nestedArray = [
|
|
1361
|
+
'q',
|
|
1362
|
+
'r',
|
|
1363
|
+
[
|
|
1364
|
+
's',
|
|
1365
|
+
't',
|
|
1366
|
+
],
|
|
1367
|
+
];
|
|
1368
|
+
`,
|
|
1369
|
+
options: {
|
|
1370
|
+
multilineArraysWrapThreshold: 1,
|
|
1371
|
+
},
|
|
1372
|
+
},
|
|
1373
|
+
{
|
|
1374
|
+
it: 'empty array',
|
|
1375
|
+
code: `
|
|
1376
|
+
const myVar1: string[] = [];
|
|
1377
|
+
`,
|
|
1378
|
+
},
|
|
1379
|
+
{
|
|
1380
|
+
it: 'single element array on one line',
|
|
1381
|
+
code: "let anotherThing: string[] = ['1 1'];",
|
|
1382
|
+
expect: `
|
|
1383
|
+
let anotherThing: string[] = [
|
|
1384
|
+
'1 1',
|
|
1385
|
+
];
|
|
1386
|
+
`,
|
|
1387
|
+
options: {
|
|
1388
|
+
multilineArraysWrapThreshold: 0,
|
|
1389
|
+
},
|
|
1390
|
+
},
|
|
1391
|
+
{
|
|
1392
|
+
it: 'single element array on multiple lines',
|
|
1393
|
+
code: `
|
|
1394
|
+
let anotherThing: string[] = ['1 1'
|
|
1395
|
+
];`,
|
|
1396
|
+
expect: `
|
|
1397
|
+
let anotherThing: string[] = [
|
|
1398
|
+
'1 1',
|
|
1399
|
+
];
|
|
1400
|
+
`,
|
|
1401
|
+
options: {
|
|
1402
|
+
multilineArraysWrapThreshold: 0,
|
|
1403
|
+
},
|
|
1404
|
+
},
|
|
1405
|
+
{
|
|
1406
|
+
it: 'multiple different styled arrays all together',
|
|
1407
|
+
code: `
|
|
1408
|
+
const myVar2: string[] = [];
|
|
1409
|
+
let anotherThing: string[] = ['1 1'];
|
|
1410
|
+
let anotherThing2: string[] = ['1 1'
|
|
1411
|
+
];
|
|
1412
|
+
const also: string[] = [
|
|
1413
|
+
'2, 1',
|
|
1414
|
+
'2, 2',
|
|
1415
|
+
];`,
|
|
1416
|
+
expect: `
|
|
1417
|
+
const myVar2: string[] = [];
|
|
1418
|
+
let anotherThing: string[] = [
|
|
1419
|
+
'1 1',
|
|
1420
|
+
];
|
|
1421
|
+
let anotherThing2: string[] = [
|
|
1422
|
+
'1 1',
|
|
1423
|
+
];
|
|
1424
|
+
const also: string[] = [
|
|
1425
|
+
'2, 1',
|
|
1426
|
+
'2, 2',
|
|
1427
|
+
];
|
|
1428
|
+
`,
|
|
1429
|
+
options: {
|
|
1430
|
+
multilineArraysWrapThreshold: 0,
|
|
1431
|
+
},
|
|
1432
|
+
},
|
|
1433
|
+
{
|
|
1434
|
+
it: 'single element string array with type definition',
|
|
1435
|
+
code: "const myVar: string[] = ['hello'];",
|
|
1436
|
+
expect: `
|
|
1437
|
+
const myVar: string[] = [
|
|
1438
|
+
'hello',
|
|
1439
|
+
];
|
|
1440
|
+
`,
|
|
1441
|
+
options: {
|
|
1442
|
+
multilineArraysWrapThreshold: 0,
|
|
1443
|
+
},
|
|
1444
|
+
},
|
|
1445
|
+
{
|
|
1446
|
+
it: 'double element string array with type definition',
|
|
1447
|
+
code: "const myVar: string[] = ['hello', 'there'];",
|
|
1448
|
+
expect: `
|
|
1449
|
+
const myVar: string[] = [
|
|
1450
|
+
'hello',
|
|
1451
|
+
'there',
|
|
1452
|
+
];
|
|
1453
|
+
`,
|
|
1454
|
+
options: {
|
|
1455
|
+
multilineArraysWrapThreshold: 1,
|
|
1456
|
+
},
|
|
1457
|
+
},
|
|
1458
|
+
{
|
|
1459
|
+
it: 'non-array string assignment',
|
|
1460
|
+
code: `
|
|
1461
|
+
const myVar:string=
|
|
1462
|
+
'hello';`,
|
|
1463
|
+
expect: `
|
|
1464
|
+
const myVar: string = 'hello';
|
|
1465
|
+
`,
|
|
1466
|
+
},
|
|
1467
|
+
{
|
|
1468
|
+
it: 'non-array single line object assignment',
|
|
1469
|
+
code: `
|
|
1470
|
+
const myVar: object = {a: 'here', b: 'there'};
|
|
1471
|
+
`,
|
|
1472
|
+
},
|
|
1473
|
+
{
|
|
1474
|
+
it: 'non-array multi-line object assignment',
|
|
1475
|
+
code: `
|
|
1476
|
+
const myVar: object = {
|
|
1477
|
+
a: 'here',
|
|
1478
|
+
b: 'there',
|
|
1479
|
+
};
|
|
1480
|
+
`,
|
|
1481
|
+
},
|
|
1482
|
+
// the following test caught that path.getValue() can return undefined.
|
|
1483
|
+
{
|
|
1484
|
+
it: 'array with an earlier function definition',
|
|
1485
|
+
code: `
|
|
1486
|
+
function doStuff() {}
|
|
1487
|
+
|
|
1488
|
+
const what = ['a', 'b'];
|
|
1489
|
+
|
|
1490
|
+
|
|
1491
|
+
|
|
1492
|
+
`,
|
|
1493
|
+
expect: `
|
|
1494
|
+
function doStuff() {}
|
|
1495
|
+
|
|
1496
|
+
const what = [
|
|
1497
|
+
'a',
|
|
1498
|
+
'b',
|
|
1499
|
+
];
|
|
1500
|
+
`,
|
|
1501
|
+
options: {
|
|
1502
|
+
multilineArraysWrapThreshold: 1,
|
|
1503
|
+
},
|
|
1504
|
+
},
|
|
1505
|
+
{
|
|
1506
|
+
it: 'array with function definition inside of it',
|
|
1507
|
+
code: `
|
|
1508
|
+
const what = ['a', function doStuff() {}];
|
|
1509
|
+
`,
|
|
1510
|
+
expect: `
|
|
1511
|
+
const what = [
|
|
1512
|
+
'a',
|
|
1513
|
+
function doStuff() {},
|
|
1514
|
+
];
|
|
1515
|
+
`,
|
|
1516
|
+
options: {
|
|
1517
|
+
multilineArraysWrapThreshold: 1,
|
|
1518
|
+
},
|
|
1519
|
+
},
|
|
1520
|
+
{
|
|
1521
|
+
it: 'does not wrap generic type arguments inside an array element GitHub Issue #69',
|
|
1522
|
+
code: `
|
|
1523
|
+
const array = [
|
|
1524
|
+
x as Omit<MyType, 'field'>,
|
|
1525
|
+
];
|
|
1526
|
+
`,
|
|
1527
|
+
},
|
|
1528
|
+
{
|
|
1529
|
+
it: 'does not wrap destructuring patterns or tuple type annotations GitHub Issue #69',
|
|
1530
|
+
code: `
|
|
1531
|
+
Object.entries(someObject).some(
|
|
1532
|
+
([key, value]: [string, unknown]) => console.log(key, value),
|
|
1533
|
+
);
|
|
1534
|
+
`,
|
|
1535
|
+
expect: `
|
|
1536
|
+
Object.entries(someObject).some(([key, value]: [string, unknown]) => console.log(key, value));
|
|
1537
|
+
`,
|
|
1538
|
+
},
|
|
1539
|
+
{
|
|
1540
|
+
it: 'leaves a union type alone inside a multi-line single-element tuple type GitHub Issue #71',
|
|
1541
|
+
code: `
|
|
1542
|
+
type ContainsScalar<Value> = [Value] extends [
|
|
1543
|
+
Date | RegExp | URL | Error | Map<unknown, unknown> | Set<unknown>,
|
|
1544
|
+
]
|
|
1545
|
+
? true
|
|
1546
|
+
: false;
|
|
1547
|
+
`,
|
|
1548
|
+
},
|
|
1549
|
+
{
|
|
1550
|
+
it: 'leaves union types alone inside a multi-line multi-element tuple type GitHub Issue #71',
|
|
1551
|
+
code: `
|
|
1552
|
+
type ComparePair<First, Second> = [First, Second] extends [
|
|
1553
|
+
Date | RegExp | URL | Error,
|
|
1554
|
+
Map<unknown, unknown> | Set<unknown> | WeakMap<object, unknown>,
|
|
1555
|
+
]
|
|
1556
|
+
? true
|
|
1557
|
+
: false;
|
|
1558
|
+
`,
|
|
1559
|
+
},
|
|
1560
|
+
{
|
|
1561
|
+
it: 'original parser with single line object assignment',
|
|
1562
|
+
code: `
|
|
1563
|
+
const myVar: object = {a: 'where', b: 'everywhere'};
|
|
1564
|
+
`,
|
|
1565
|
+
},
|
|
1566
|
+
{
|
|
1567
|
+
it: 'original parser with multi-line object assignment',
|
|
1568
|
+
code: `
|
|
1569
|
+
const myVar: object = {
|
|
1570
|
+
a: 'where',
|
|
1571
|
+
b: 'everywhere',
|
|
1572
|
+
};
|
|
1573
|
+
`,
|
|
1574
|
+
},
|
|
1575
|
+
];
|