prettier-plugin-multiline-arrays-2 1.0.0 → 5.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/README.md +5 -19
- package/dist/augments/array.d.ts +8 -2
- package/dist/augments/array.js +11 -5
- package/dist/augments/doc.d.ts +2 -2
- package/dist/augments/doc.js +12 -9
- package/dist/augments/string.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +42 -20
- package/dist/options.d.ts +6 -9
- package/dist/options.js +20 -25
- package/dist/plugin-marker.js +1 -1
- package/dist/preprocessing.d.ts +1 -1
- package/dist/preprocessing.js +60 -30
- package/dist/printer/child-docs.d.ts +9 -7
- package/dist/printer/child-docs.js +89 -63
- package/dist/printer/comment-triggers.d.ts +5 -7
- package/dist/printer/comment-triggers.js +104 -134
- package/dist/printer/comments.d.ts +1 -1
- package/dist/printer/comments.js +15 -16
- package/dist/printer/insert-new-lines.d.ts +10 -6
- package/dist/printer/insert-new-lines.js +260 -277
- package/dist/printer/leading-new-line.d.ts +2 -2
- package/dist/printer/leading-new-line.js +2 -1
- package/dist/printer/multiline-array-printer.js +4 -2
- package/dist/printer/original-printer.js +6 -4
- package/dist/printer/supported-node-types.d.ts +1 -1
- package/dist/printer/supported-node-types.js +6 -5
- package/dist/printer/trailing-comma.d.ts +1 -1
- package/dist/printer/trailing-comma.js +1 -1
- package/package.json +56 -29
- package/dist/augments/array.test.d.ts +0 -1
- package/dist/augments/array.test.js +0 -34
- package/dist/options.test.d.ts +0 -1
- package/dist/options.test.js +0 -48
- package/dist/printer/insert-new-lines.test.d.ts +0 -1
- package/dist/printer/insert-new-lines.test.js +0 -36
- package/dist/readme-examples/formatted-with-comments.example.d.ts +0 -3
- package/dist/readme-examples/formatted-with-comments.example.js +0 -16
- package/dist/readme-examples/formatted.example.d.ts +0 -2
- package/dist/readme-examples/formatted.example.js +0 -12
- package/dist/readme-examples/not-formatted.example.d.ts +0 -2
- package/dist/readme-examples/not-formatted.example.js +0 -6
- package/dist/readme-examples/prettier-options.example.d.ts +0 -4
- package/dist/readme-examples/prettier-options.example.js +0 -5
- package/dist/test/babel-ts.test.d.ts +0 -1
- package/dist/test/babel-ts.test.js +0 -10
- package/dist/test/javascript.test.d.ts +0 -1
- package/dist/test/javascript.test.js +0 -702
- package/dist/test/json.test.d.ts +0 -1
- package/dist/test/json.test.js +0 -403
- package/dist/test/json5.test.d.ts +0 -1
- package/dist/test/json5.test.js +0 -210
- package/dist/test/prettier-config.d.ts +0 -2
- package/dist/test/prettier-config.js +0 -12
- package/dist/test/prettier-versions.mock.script.d.ts +0 -1
- package/dist/test/prettier-versions.mock.script.js +0 -123
- package/dist/test/run-tests.mock.d.ts +0 -17
- package/dist/test/run-tests.mock.js +0 -95
- package/dist/test/typescript-tests.mock.d.ts +0 -2
- package/dist/test/typescript-tests.mock.js +0 -1575
- package/dist/test/typescript.test.d.ts +0 -1
- package/dist/test/typescript.test.js +0 -10
|
@@ -1,702 +0,0 @@
|
|
|
1
|
-
import { describe } from '@augment-vir/test';
|
|
2
|
-
import { capitalizeFirst } from '../augments/string.js';
|
|
3
|
-
import { nextLinePatternComment, nextWrapThresholdComment } from '../options.js';
|
|
4
|
-
import { runTests } from './run-tests.mock.js';
|
|
5
|
-
const javascriptTests = [
|
|
6
|
-
{
|
|
7
|
-
it: 'comment at end of argument list with multiline array parser',
|
|
8
|
-
code: `
|
|
9
|
-
export function hasProperty(
|
|
10
|
-
inputObject,
|
|
11
|
-
inputKey,
|
|
12
|
-
// this comment shouldn't get moved
|
|
13
|
-
) {
|
|
14
|
-
return inputKey in inputObject;
|
|
15
|
-
}
|
|
16
|
-
`,
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
it: 'basic wrap threshold comment',
|
|
20
|
-
code: `
|
|
21
|
-
// ${nextWrapThresholdComment} 3
|
|
22
|
-
const thingieArray = ['hello'];
|
|
23
|
-
`,
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
it: 'works with greater than or less than inside of an array in javascript',
|
|
27
|
-
code: `
|
|
28
|
-
const thingie = [
|
|
29
|
-
otherThingie < 5 ? 'owl' : 'goat',
|
|
30
|
-
];
|
|
31
|
-
`,
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
it: 'invalid wrap threshold triggers error',
|
|
35
|
-
code: `
|
|
36
|
-
const thingieArray = ['hello'];
|
|
37
|
-
`,
|
|
38
|
-
options: {
|
|
39
|
-
multilineArraysWrapThreshold: 'fifty two',
|
|
40
|
-
},
|
|
41
|
-
failureMessage: 'Invalid multilineArraysWrapThreshold value. Expected an integer, but received "fifty two".',
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
it: 'wrap threshold through options',
|
|
45
|
-
code: `
|
|
46
|
-
const thingieArray = ['hello'];
|
|
47
|
-
`,
|
|
48
|
-
options: {
|
|
49
|
-
multilineArraysWrapThreshold: 3,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
it: 'line count through options',
|
|
54
|
-
code: `
|
|
55
|
-
const thingieArray = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
|
|
56
|
-
`,
|
|
57
|
-
expect: `
|
|
58
|
-
const thingieArray = [
|
|
59
|
-
'a',
|
|
60
|
-
'b', 'c',
|
|
61
|
-
'd', 'e', 'f',
|
|
62
|
-
'g',
|
|
63
|
-
'h',
|
|
64
|
-
];
|
|
65
|
-
`,
|
|
66
|
-
options: {
|
|
67
|
-
multilineArraysLinePattern: '1 2 3',
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
it: 'line count overrides threshold',
|
|
72
|
-
code: `
|
|
73
|
-
const thingieArray = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
|
|
74
|
-
`,
|
|
75
|
-
expect: `
|
|
76
|
-
const thingieArray = [
|
|
77
|
-
'a',
|
|
78
|
-
'b', 'c',
|
|
79
|
-
'd', 'e', 'f',
|
|
80
|
-
'g',
|
|
81
|
-
'h',
|
|
82
|
-
];
|
|
83
|
-
`,
|
|
84
|
-
options: {
|
|
85
|
-
multilineArraysLinePattern: '1 2 3',
|
|
86
|
-
multilineArraysWrapThreshold: 20,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
it: 'pointless wrap threshold comment',
|
|
91
|
-
code: `
|
|
92
|
-
// ${nextWrapThresholdComment} 0
|
|
93
|
-
const thingieArray = [
|
|
94
|
-
'hello',
|
|
95
|
-
];
|
|
96
|
-
`,
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
// this was causing an error on the closing "}" at one point
|
|
100
|
-
it: 'interpolated string example',
|
|
101
|
-
code: `
|
|
102
|
-
if (children.length) {
|
|
103
|
-
// ${nextWrapThresholdComment} 1
|
|
104
|
-
return [\`\${input.type}:\`];
|
|
105
|
-
}
|
|
106
|
-
`,
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
it: 'array elements with dots',
|
|
110
|
-
code: `
|
|
111
|
-
parentDoc[childIndex] = [
|
|
112
|
-
doc.builders.hardlineWithoutBreakParent,
|
|
113
|
-
doc.builders.breakParent,
|
|
114
|
-
];
|
|
115
|
-
`,
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
it: 'single line comment with just one line count',
|
|
119
|
-
code: `
|
|
120
|
-
// ${nextLinePatternComment} 2
|
|
121
|
-
const originalArray = [
|
|
122
|
-
0,
|
|
123
|
-
1,
|
|
124
|
-
2,
|
|
125
|
-
3,
|
|
126
|
-
4,
|
|
127
|
-
];
|
|
128
|
-
`,
|
|
129
|
-
expect: `
|
|
130
|
-
// ${nextLinePatternComment} 2
|
|
131
|
-
const originalArray = [
|
|
132
|
-
0, 1,
|
|
133
|
-
2, 3,
|
|
134
|
-
4,
|
|
135
|
-
];
|
|
136
|
-
`,
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
it: 'single line comment with just one line wrapped',
|
|
140
|
-
code: `
|
|
141
|
-
describe(filterMap.name, () => {
|
|
142
|
-
// ${nextLinePatternComment} 2
|
|
143
|
-
const originalArray = [
|
|
144
|
-
0,
|
|
145
|
-
1,
|
|
146
|
-
2,
|
|
147
|
-
3,
|
|
148
|
-
4,
|
|
149
|
-
];
|
|
150
|
-
});
|
|
151
|
-
`,
|
|
152
|
-
expect: `
|
|
153
|
-
describe(filterMap.name, () => {
|
|
154
|
-
// ${nextLinePatternComment} 2
|
|
155
|
-
const originalArray = [
|
|
156
|
-
0, 1,
|
|
157
|
-
2, 3,
|
|
158
|
-
4,
|
|
159
|
-
];
|
|
160
|
-
});
|
|
161
|
-
`,
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
// caused a max call stack exceeded error once
|
|
165
|
-
it: 'single object element with multiline template',
|
|
166
|
-
code: `
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const stuff = [
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
{
|
|
175
|
-
innerStuff: \`
|
|
176
|
-
const myVar = {a: 'where', b: 'everywhere'};
|
|
177
|
-
\`,
|
|
178
|
-
},
|
|
179
|
-
];
|
|
180
|
-
`,
|
|
181
|
-
expect: `
|
|
182
|
-
const stuff = [
|
|
183
|
-
{
|
|
184
|
-
innerStuff: \`
|
|
185
|
-
const myVar = {a: 'where', b: 'everywhere'};
|
|
186
|
-
\`,
|
|
187
|
-
},
|
|
188
|
-
];
|
|
189
|
-
`,
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
it: 'long function definition with multiline array parser',
|
|
193
|
-
code: `
|
|
194
|
-
export async function selectFiles(
|
|
195
|
-
inputProperties = [
|
|
196
|
-
OpenDialogProperty.multiSelections,
|
|
197
|
-
OpenDialogProperty.openFile,
|
|
198
|
-
OpenDialogProperty.openDirectory,
|
|
199
|
-
],
|
|
200
|
-
) {}
|
|
201
|
-
`,
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
it: 'comment after end of block with multiline array parser',
|
|
205
|
-
code: `
|
|
206
|
-
if (thing) {
|
|
207
|
-
}
|
|
208
|
-
// otherwise we are editing currently existing songs
|
|
209
|
-
else {
|
|
210
|
-
}
|
|
211
|
-
`,
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
it: 'still sorts imports with multiline parser',
|
|
215
|
-
code: `
|
|
216
|
-
import {notUsed} from 'blah';
|
|
217
|
-
const thingie = [
|
|
218
|
-
'a',
|
|
219
|
-
'b',
|
|
220
|
-
];
|
|
221
|
-
`,
|
|
222
|
-
expect: `
|
|
223
|
-
const thingie = [
|
|
224
|
-
'a',
|
|
225
|
-
'b',
|
|
226
|
-
];
|
|
227
|
-
`,
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
it: 'deep array call should include trailing comma still',
|
|
231
|
-
code: `
|
|
232
|
-
expect(createArrayValidator(typeofValidators.boolean)([3, 4])).toBe(false);
|
|
233
|
-
`,
|
|
234
|
-
expect: `
|
|
235
|
-
expect(
|
|
236
|
-
createArrayValidator(typeofValidators.boolean)([
|
|
237
|
-
3,
|
|
238
|
-
4,
|
|
239
|
-
]),
|
|
240
|
-
).toBe(false);
|
|
241
|
-
`,
|
|
242
|
-
options: {
|
|
243
|
-
multilineArraysWrapThreshold: 1,
|
|
244
|
-
},
|
|
245
|
-
},
|
|
246
|
-
{
|
|
247
|
-
it: 'not arrays but callbacks with multiline array parser',
|
|
248
|
-
code: `
|
|
249
|
-
expose({
|
|
250
|
-
versions,
|
|
251
|
-
apiRequest: async (details) => {
|
|
252
|
-
async function waitForResponse() {
|
|
253
|
-
return new Promise((resolve) => {
|
|
254
|
-
ipcRenderer.once(
|
|
255
|
-
getApiResponseEventName(details.type, requestId),
|
|
256
|
-
(event, data) => {
|
|
257
|
-
resolve(data);
|
|
258
|
-
},
|
|
259
|
-
);
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
});
|
|
264
|
-
`,
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
it: 'function parameters',
|
|
268
|
-
code: `
|
|
269
|
-
doTheThing('a', 'b', 'c');
|
|
270
|
-
`,
|
|
271
|
-
},
|
|
272
|
-
{
|
|
273
|
-
it: 'config object',
|
|
274
|
-
code: `
|
|
275
|
-
const config = {
|
|
276
|
-
directories: {
|
|
277
|
-
output: 'dist',
|
|
278
|
-
buildResources: 'build-resources',
|
|
279
|
-
},
|
|
280
|
-
files: [
|
|
281
|
-
'packages/**/dist/**',
|
|
282
|
-
],
|
|
283
|
-
extraMetadata: {
|
|
284
|
-
version: viteVersion,
|
|
285
|
-
},
|
|
286
|
-
};
|
|
287
|
-
`,
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
it: 'nested single-line objects on multiple lines',
|
|
291
|
-
code: `
|
|
292
|
-
const nested = [
|
|
293
|
-
{success: true, filePath: ''},
|
|
294
|
-
{success: false, error: 'hello there', filePath: ''},
|
|
295
|
-
{success: false, error: '', filePath: ''},
|
|
296
|
-
];
|
|
297
|
-
`,
|
|
298
|
-
},
|
|
299
|
-
{
|
|
300
|
-
it: 'nested single-line objects all on one line',
|
|
301
|
-
code: `
|
|
302
|
-
const nested = [{success: true, filePath: ''}, {success: false, error: 'hello there', filePath: ''}, {success: false, error: '', filePath: ''}];
|
|
303
|
-
`,
|
|
304
|
-
expect: `
|
|
305
|
-
const nested = [
|
|
306
|
-
{success: true, filePath: ''},
|
|
307
|
-
{success: false, error: 'hello there', filePath: ''},
|
|
308
|
-
{success: false, error: '', filePath: ''},
|
|
309
|
-
];
|
|
310
|
-
`,
|
|
311
|
-
},
|
|
312
|
-
{
|
|
313
|
-
it: 'nested multi-line objects',
|
|
314
|
-
code: `
|
|
315
|
-
const nested = [{
|
|
316
|
-
success: true, filePath: ''}, {
|
|
317
|
-
success: false, error: 'hello there', filePath: ''}, {
|
|
318
|
-
success: false, error: '', filePath: ''}];
|
|
319
|
-
`,
|
|
320
|
-
expect: `
|
|
321
|
-
const nested = [
|
|
322
|
-
{
|
|
323
|
-
success: true,
|
|
324
|
-
filePath: '',
|
|
325
|
-
},
|
|
326
|
-
{
|
|
327
|
-
success: false,
|
|
328
|
-
error: 'hello there',
|
|
329
|
-
filePath: '',
|
|
330
|
-
},
|
|
331
|
-
{
|
|
332
|
-
success: false,
|
|
333
|
-
error: '',
|
|
334
|
-
filePath: '',
|
|
335
|
-
},
|
|
336
|
-
];
|
|
337
|
-
`,
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
it: 'multiple arrays and even one with a trigger comment',
|
|
341
|
-
code: `
|
|
342
|
-
const varNoLine = ['a', 'b'];
|
|
343
|
-
const varOneNewLine = [
|
|
344
|
-
'a', 'b',
|
|
345
|
-
];
|
|
346
|
-
const nestedArray = [
|
|
347
|
-
'q', 'r',
|
|
348
|
-
['s', 't'],
|
|
349
|
-
];
|
|
350
|
-
// ${capitalizeFirst(nextLinePatternComment)} 2 1 3
|
|
351
|
-
const setNumberPerLine = [
|
|
352
|
-
'a', 'b',
|
|
353
|
-
'c',
|
|
354
|
-
'd',
|
|
355
|
-
'e',
|
|
356
|
-
];
|
|
357
|
-
|
|
358
|
-
`,
|
|
359
|
-
expect: `
|
|
360
|
-
const varNoLine = [
|
|
361
|
-
'a',
|
|
362
|
-
'b',
|
|
363
|
-
];
|
|
364
|
-
const varOneNewLine = [
|
|
365
|
-
'a',
|
|
366
|
-
'b',
|
|
367
|
-
];
|
|
368
|
-
const nestedArray = [
|
|
369
|
-
'q',
|
|
370
|
-
'r',
|
|
371
|
-
[
|
|
372
|
-
's',
|
|
373
|
-
't',
|
|
374
|
-
],
|
|
375
|
-
];
|
|
376
|
-
// ${capitalizeFirst(nextLinePatternComment)} 2 1 3
|
|
377
|
-
const setNumberPerLine = [
|
|
378
|
-
'a', 'b',
|
|
379
|
-
'c',
|
|
380
|
-
'd', 'e',
|
|
381
|
-
];
|
|
382
|
-
`,
|
|
383
|
-
options: {
|
|
384
|
-
multilineArraysWrapThreshold: 1,
|
|
385
|
-
},
|
|
386
|
-
},
|
|
387
|
-
{
|
|
388
|
-
it: 'no threshold set with multiple arrays, one having a trigger comment',
|
|
389
|
-
code: `
|
|
390
|
-
const varNoLine = ['a', 'b'];
|
|
391
|
-
const varOneNewLine = [
|
|
392
|
-
'a', 'b',
|
|
393
|
-
];
|
|
394
|
-
const nestedArray = [
|
|
395
|
-
'q', 'r',
|
|
396
|
-
['s', 't'],
|
|
397
|
-
];
|
|
398
|
-
// ${capitalizeFirst(nextLinePatternComment)} 2 1 3
|
|
399
|
-
const setNumberPerLine = [
|
|
400
|
-
'a', 'b',
|
|
401
|
-
'c',
|
|
402
|
-
'd',
|
|
403
|
-
'e',
|
|
404
|
-
];
|
|
405
|
-
|
|
406
|
-
`,
|
|
407
|
-
expect: `
|
|
408
|
-
const varNoLine = ['a', 'b'];
|
|
409
|
-
const varOneNewLine = [
|
|
410
|
-
'a',
|
|
411
|
-
'b',
|
|
412
|
-
];
|
|
413
|
-
const nestedArray = [
|
|
414
|
-
'q',
|
|
415
|
-
'r',
|
|
416
|
-
['s', 't'],
|
|
417
|
-
];
|
|
418
|
-
// ${capitalizeFirst(nextLinePatternComment)} 2 1 3
|
|
419
|
-
const setNumberPerLine = [
|
|
420
|
-
'a', 'b',
|
|
421
|
-
'c',
|
|
422
|
-
'd', 'e',
|
|
423
|
-
];
|
|
424
|
-
`,
|
|
425
|
-
},
|
|
426
|
-
{
|
|
427
|
-
it: 'array with single line trigger comment',
|
|
428
|
-
code: `
|
|
429
|
-
// ${nextLinePatternComment} 2 1 3
|
|
430
|
-
const setNumberPerLine = [
|
|
431
|
-
'a', 'b',
|
|
432
|
-
'c',
|
|
433
|
-
'd',
|
|
434
|
-
'e',
|
|
435
|
-
'f',
|
|
436
|
-
'g',
|
|
437
|
-
'h',
|
|
438
|
-
'i',
|
|
439
|
-
'j',
|
|
440
|
-
'k',
|
|
441
|
-
];`,
|
|
442
|
-
expect: `
|
|
443
|
-
// ${nextLinePatternComment} 2 1 3
|
|
444
|
-
const setNumberPerLine = [
|
|
445
|
-
'a', 'b',
|
|
446
|
-
'c',
|
|
447
|
-
'd', 'e', 'f',
|
|
448
|
-
'g', 'h',
|
|
449
|
-
'i',
|
|
450
|
-
'j', 'k',
|
|
451
|
-
];
|
|
452
|
-
`,
|
|
453
|
-
},
|
|
454
|
-
{
|
|
455
|
-
it: 'array with line trigger comment using commas',
|
|
456
|
-
code: `
|
|
457
|
-
// ${nextLinePatternComment} 2, 1, 3
|
|
458
|
-
const setNumberPerLine = [
|
|
459
|
-
'a', 'b',
|
|
460
|
-
'c',
|
|
461
|
-
'd',
|
|
462
|
-
'e',
|
|
463
|
-
'f',
|
|
464
|
-
'g',
|
|
465
|
-
'h',
|
|
466
|
-
'i',
|
|
467
|
-
'j',
|
|
468
|
-
'k',
|
|
469
|
-
];`,
|
|
470
|
-
expect: `
|
|
471
|
-
// ${nextLinePatternComment} 2, 1, 3
|
|
472
|
-
const setNumberPerLine = [
|
|
473
|
-
'a', 'b',
|
|
474
|
-
'c',
|
|
475
|
-
'd', 'e', 'f',
|
|
476
|
-
'g', 'h',
|
|
477
|
-
'i',
|
|
478
|
-
'j', 'k',
|
|
479
|
-
];
|
|
480
|
-
`,
|
|
481
|
-
},
|
|
482
|
-
{
|
|
483
|
-
it: 'JS array with just a comment',
|
|
484
|
-
code: `
|
|
485
|
-
const myObject = {
|
|
486
|
-
data: [
|
|
487
|
-
// comment
|
|
488
|
-
],
|
|
489
|
-
};
|
|
490
|
-
`,
|
|
491
|
-
},
|
|
492
|
-
{
|
|
493
|
-
it: 'basic array with a comment',
|
|
494
|
-
code: `
|
|
495
|
-
const data = [
|
|
496
|
-
'one',
|
|
497
|
-
// comment
|
|
498
|
-
'two',
|
|
499
|
-
];
|
|
500
|
-
`,
|
|
501
|
-
},
|
|
502
|
-
{
|
|
503
|
-
it: 'basic array with a leading comment',
|
|
504
|
-
code: `
|
|
505
|
-
const data = [
|
|
506
|
-
// comment
|
|
507
|
-
'one',
|
|
508
|
-
'two',
|
|
509
|
-
];
|
|
510
|
-
`,
|
|
511
|
-
},
|
|
512
|
-
{
|
|
513
|
-
it: 'nested array',
|
|
514
|
-
code: `
|
|
515
|
-
const nestedArray = [
|
|
516
|
-
'q', 'r',
|
|
517
|
-
['s', 't'],
|
|
518
|
-
];`,
|
|
519
|
-
expect: `
|
|
520
|
-
const nestedArray = [
|
|
521
|
-
'q',
|
|
522
|
-
'r',
|
|
523
|
-
[
|
|
524
|
-
's',
|
|
525
|
-
't',
|
|
526
|
-
],
|
|
527
|
-
];
|
|
528
|
-
`,
|
|
529
|
-
options: {
|
|
530
|
-
multilineArraysWrapThreshold: 1,
|
|
531
|
-
},
|
|
532
|
-
},
|
|
533
|
-
{
|
|
534
|
-
it: 'empty array',
|
|
535
|
-
code: `
|
|
536
|
-
const myVar1 = [];
|
|
537
|
-
`,
|
|
538
|
-
},
|
|
539
|
-
{
|
|
540
|
-
it: 'single element array on one line',
|
|
541
|
-
code: "let anotherThing = ['1 1'];",
|
|
542
|
-
expect: `
|
|
543
|
-
let anotherThing = [
|
|
544
|
-
'1 1',
|
|
545
|
-
];
|
|
546
|
-
`,
|
|
547
|
-
options: {
|
|
548
|
-
multilineArraysWrapThreshold: 0,
|
|
549
|
-
},
|
|
550
|
-
},
|
|
551
|
-
{
|
|
552
|
-
it: 'single element array on multiple lines',
|
|
553
|
-
code: `
|
|
554
|
-
let anotherThing = ['1 1'
|
|
555
|
-
];`,
|
|
556
|
-
expect: `
|
|
557
|
-
let anotherThing = [
|
|
558
|
-
'1 1',
|
|
559
|
-
];
|
|
560
|
-
`,
|
|
561
|
-
options: {
|
|
562
|
-
multilineArraysWrapThreshold: 0,
|
|
563
|
-
},
|
|
564
|
-
},
|
|
565
|
-
{
|
|
566
|
-
it: 'multiple different styled arrays all together',
|
|
567
|
-
code: `
|
|
568
|
-
const myVar2 = [];
|
|
569
|
-
let anotherThing = ['1 1'];
|
|
570
|
-
let anotherThing2 = ['1 1'
|
|
571
|
-
];
|
|
572
|
-
const also = [
|
|
573
|
-
'2, 1',
|
|
574
|
-
'2, 2',
|
|
575
|
-
];`,
|
|
576
|
-
expect: `
|
|
577
|
-
const myVar2 = [];
|
|
578
|
-
let anotherThing = [
|
|
579
|
-
'1 1',
|
|
580
|
-
];
|
|
581
|
-
let anotherThing2 = [
|
|
582
|
-
'1 1',
|
|
583
|
-
];
|
|
584
|
-
const also = [
|
|
585
|
-
'2, 1',
|
|
586
|
-
'2, 2',
|
|
587
|
-
];
|
|
588
|
-
`,
|
|
589
|
-
options: {
|
|
590
|
-
multilineArraysWrapThreshold: 0,
|
|
591
|
-
},
|
|
592
|
-
},
|
|
593
|
-
{
|
|
594
|
-
it: 'single element string array with type definition',
|
|
595
|
-
code: "const myVar = ['hello'];",
|
|
596
|
-
expect: `
|
|
597
|
-
const myVar = [
|
|
598
|
-
'hello',
|
|
599
|
-
];
|
|
600
|
-
`,
|
|
601
|
-
options: {
|
|
602
|
-
multilineArraysWrapThreshold: 0,
|
|
603
|
-
},
|
|
604
|
-
},
|
|
605
|
-
{
|
|
606
|
-
it: 'double element string array with type definition',
|
|
607
|
-
code: "const myVar = ['hello', 'there'];",
|
|
608
|
-
expect: `
|
|
609
|
-
const myVar = [
|
|
610
|
-
'hello',
|
|
611
|
-
'there',
|
|
612
|
-
];
|
|
613
|
-
`,
|
|
614
|
-
options: {
|
|
615
|
-
multilineArraysWrapThreshold: 1,
|
|
616
|
-
},
|
|
617
|
-
},
|
|
618
|
-
{
|
|
619
|
-
it: 'non-array string assignment',
|
|
620
|
-
code: `
|
|
621
|
-
const myVar=
|
|
622
|
-
'hello';`,
|
|
623
|
-
expect: `
|
|
624
|
-
const myVar = 'hello';
|
|
625
|
-
`,
|
|
626
|
-
},
|
|
627
|
-
{
|
|
628
|
-
it: 'non-array single line object assignment',
|
|
629
|
-
code: `
|
|
630
|
-
const myVar = {a: 'here', b: 'there'};
|
|
631
|
-
`,
|
|
632
|
-
},
|
|
633
|
-
{
|
|
634
|
-
it: 'non-array multi-line object assignment',
|
|
635
|
-
code: `
|
|
636
|
-
const myVar = {
|
|
637
|
-
a: 'here',
|
|
638
|
-
b: 'there',
|
|
639
|
-
};
|
|
640
|
-
`,
|
|
641
|
-
},
|
|
642
|
-
// the following test caught that path.getValue() can return undefined.
|
|
643
|
-
{
|
|
644
|
-
it: 'array with an earlier function definition',
|
|
645
|
-
code: `
|
|
646
|
-
function doStuff() {}
|
|
647
|
-
|
|
648
|
-
const what = ['a', 'b'];
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
`,
|
|
653
|
-
expect: `
|
|
654
|
-
function doStuff() {}
|
|
655
|
-
|
|
656
|
-
const what = [
|
|
657
|
-
'a',
|
|
658
|
-
'b',
|
|
659
|
-
];
|
|
660
|
-
`,
|
|
661
|
-
options: {
|
|
662
|
-
multilineArraysWrapThreshold: 1,
|
|
663
|
-
},
|
|
664
|
-
},
|
|
665
|
-
{
|
|
666
|
-
it: 'array with function definition inside of it',
|
|
667
|
-
code: `
|
|
668
|
-
const what = ['a', function doStuff() {}];
|
|
669
|
-
`,
|
|
670
|
-
expect: `
|
|
671
|
-
const what = [
|
|
672
|
-
'a',
|
|
673
|
-
function doStuff() {},
|
|
674
|
-
];
|
|
675
|
-
`,
|
|
676
|
-
options: {
|
|
677
|
-
multilineArraysWrapThreshold: 1,
|
|
678
|
-
},
|
|
679
|
-
},
|
|
680
|
-
{
|
|
681
|
-
it: 'original parser with single line object assignment',
|
|
682
|
-
code: `
|
|
683
|
-
const myVar = {a: 'where', b: 'everywhere'};
|
|
684
|
-
`,
|
|
685
|
-
},
|
|
686
|
-
{
|
|
687
|
-
it: 'original parser with multi-line object assignment',
|
|
688
|
-
code: `
|
|
689
|
-
const myVar = {
|
|
690
|
-
a: 'where',
|
|
691
|
-
b: 'everywhere',
|
|
692
|
-
};
|
|
693
|
-
`,
|
|
694
|
-
},
|
|
695
|
-
];
|
|
696
|
-
describe('javascript multiline array formatting', () => {
|
|
697
|
-
runTests({
|
|
698
|
-
extension: '.js',
|
|
699
|
-
tests: javascriptTests,
|
|
700
|
-
parser: 'babel',
|
|
701
|
-
});
|
|
702
|
-
});
|
package/dist/test/json.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|