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.
Files changed (69) hide show
  1. package/LICENSE +3 -0
  2. package/LICENSE-CC0 +121 -0
  3. package/LICENSE-MIT +21 -0
  4. package/README.md +91 -0
  5. package/dist/augments/array.d.ts +3 -0
  6. package/dist/augments/array.js +21 -0
  7. package/dist/augments/array.test.d.ts +1 -0
  8. package/dist/augments/array.test.js +34 -0
  9. package/dist/augments/doc.d.ts +5 -0
  10. package/dist/augments/doc.js +30 -0
  11. package/dist/augments/string.d.ts +1 -0
  12. package/dist/augments/string.js +6 -0
  13. package/dist/index.d.ts +11 -0
  14. package/dist/index.js +46 -0
  15. package/dist/options.d.ts +32 -0
  16. package/dist/options.js +71 -0
  17. package/dist/options.test.d.ts +1 -0
  18. package/dist/options.test.js +48 -0
  19. package/dist/plugin-marker.d.ts +1 -0
  20. package/dist/plugin-marker.js +2 -0
  21. package/dist/preprocessing.d.ts +2 -0
  22. package/dist/preprocessing.js +94 -0
  23. package/dist/printer/child-docs.d.ts +18 -0
  24. package/dist/printer/child-docs.js +89 -0
  25. package/dist/printer/comment-triggers.d.ts +25 -0
  26. package/dist/printer/comment-triggers.js +327 -0
  27. package/dist/printer/comments.d.ts +2 -0
  28. package/dist/printer/comments.js +34 -0
  29. package/dist/printer/insert-new-lines.d.ts +15 -0
  30. package/dist/printer/insert-new-lines.js +580 -0
  31. package/dist/printer/insert-new-lines.test.d.ts +1 -0
  32. package/dist/printer/insert-new-lines.test.js +36 -0
  33. package/dist/printer/leading-new-line.d.ts +7 -0
  34. package/dist/printer/leading-new-line.js +31 -0
  35. package/dist/printer/multiline-array-printer.d.ts +4 -0
  36. package/dist/printer/multiline-array-printer.js +42 -0
  37. package/dist/printer/original-printer.d.ts +3 -0
  38. package/dist/printer/original-printer.js +10 -0
  39. package/dist/printer/supported-node-types.d.ts +9 -0
  40. package/dist/printer/supported-node-types.js +16 -0
  41. package/dist/printer/trailing-comma.d.ts +6 -0
  42. package/dist/printer/trailing-comma.js +28 -0
  43. package/dist/readme-examples/formatted-with-comments.example.d.ts +3 -0
  44. package/dist/readme-examples/formatted-with-comments.example.js +16 -0
  45. package/dist/readme-examples/formatted.example.d.ts +2 -0
  46. package/dist/readme-examples/formatted.example.js +12 -0
  47. package/dist/readme-examples/not-formatted.example.d.ts +2 -0
  48. package/dist/readme-examples/not-formatted.example.js +6 -0
  49. package/dist/readme-examples/prettier-options.example.d.ts +4 -0
  50. package/dist/readme-examples/prettier-options.example.js +5 -0
  51. package/dist/test/babel-ts.test.d.ts +1 -0
  52. package/dist/test/babel-ts.test.js +10 -0
  53. package/dist/test/javascript.test.d.ts +1 -0
  54. package/dist/test/javascript.test.js +702 -0
  55. package/dist/test/json.test.d.ts +1 -0
  56. package/dist/test/json.test.js +403 -0
  57. package/dist/test/json5.test.d.ts +1 -0
  58. package/dist/test/json5.test.js +210 -0
  59. package/dist/test/prettier-config.d.ts +2 -0
  60. package/dist/test/prettier-config.js +12 -0
  61. package/dist/test/prettier-versions.mock.script.d.ts +1 -0
  62. package/dist/test/prettier-versions.mock.script.js +123 -0
  63. package/dist/test/run-tests.mock.d.ts +17 -0
  64. package/dist/test/run-tests.mock.js +95 -0
  65. package/dist/test/typescript-tests.mock.d.ts +2 -0
  66. package/dist/test/typescript-tests.mock.js +1575 -0
  67. package/dist/test/typescript.test.d.ts +1 -0
  68. package/dist/test/typescript.test.js +10 -0
  69. package/package.json +117 -0
@@ -0,0 +1,403 @@
1
+ import { describe } from '@augment-vir/test';
2
+ import { nextWrapThresholdComment } from '../options.js';
3
+ import { runTests } from './run-tests.mock.js';
4
+ const jsonTests = [
5
+ {
6
+ it: 'formats ending array correctly',
7
+ code: `
8
+ {
9
+ "files": [],
10
+ "references": [
11
+ {"path": "./tsconfig.app.json"},
12
+ {"path": "./tsconfig.node.json"}
13
+ ]
14
+ }
15
+ `,
16
+ },
17
+ {
18
+ it: 'basic JSON format',
19
+ code: `
20
+ {
21
+ "hello": "there",
22
+ "stuff": ["a", "b", "c", "d", "e"],
23
+ "object": {"example": "instance"}
24
+ }
25
+ `,
26
+ expect: `
27
+ {
28
+ "hello": "there",
29
+ "object": {"example": "instance"},
30
+ "stuff": [
31
+ "a",
32
+ "b",
33
+ "c",
34
+ "d",
35
+ "e"
36
+ ]
37
+ }
38
+ `,
39
+ options: {
40
+ multilineArraysWrapThreshold: 0,
41
+ },
42
+ },
43
+ {
44
+ it: 'still formats tsconfig.json keys',
45
+ code: `
46
+ {
47
+ "exclude": [
48
+ "./configs",
49
+ "./coverage",
50
+ "./dist",
51
+ "./node_modules",
52
+ "./test-files"
53
+ ],
54
+ "compilerOptions": {
55
+ "outDir": "./dist",
56
+ "rootDir": "./src"
57
+ }
58
+ }
59
+ `,
60
+ expect: `
61
+ {
62
+ "compilerOptions": {
63
+ "outDir": "./dist",
64
+ "rootDir": "./src"
65
+ },
66
+ "exclude": [
67
+ "./configs",
68
+ "./coverage",
69
+ "./dist",
70
+ "./node_modules",
71
+ "./test-files"
72
+ ]
73
+ }
74
+ `,
75
+ },
76
+ {
77
+ it: 'basic wrap threshold comment',
78
+ code: `
79
+ // ${nextWrapThresholdComment} 3
80
+ ["hello"]
81
+ `,
82
+ },
83
+ {
84
+ it: 'invalid wrap threshold triggers error',
85
+ code: `
86
+ ["hello"]
87
+ `,
88
+ options: {
89
+ multilineArraysWrapThreshold: 'fifty two',
90
+ },
91
+ failureMessage: 'Invalid multilineArraysWrapThreshold value. Expected an integer, but received "fifty two".',
92
+ },
93
+ {
94
+ it: 'exact code desired by Robinfr',
95
+ code: `
96
+ [
97
+ ["thing1"],
98
+ ["thing2"]
99
+ ]
100
+ `,
101
+ options: {
102
+ multilineArraysWrapThreshold: 1,
103
+ },
104
+ },
105
+ {
106
+ it: 'wrap threshold through options',
107
+ code: `
108
+ ["hello"]
109
+ `,
110
+ options: {
111
+ multilineArraysWrapThreshold: 3,
112
+ },
113
+ },
114
+ {
115
+ it: 'line count through options',
116
+ code: `
117
+ ["a", "b", "c", "d", "e", "f", "g", "h"]
118
+ `,
119
+ expect: `
120
+ [
121
+ "a",
122
+ "b", "c",
123
+ "d", "e", "f",
124
+ "g",
125
+ "h"
126
+ ]
127
+ `,
128
+ options: {
129
+ multilineArraysLinePattern: '1 2 3',
130
+ },
131
+ },
132
+ {
133
+ it: 'line count overrides threshold',
134
+ code: `
135
+ ["a", "b", "c", "d", "e", "f", "g", "h"]
136
+ `,
137
+ expect: `
138
+ [
139
+ "a",
140
+ "b", "c",
141
+ "d", "e", "f",
142
+ "g",
143
+ "h"
144
+ ]
145
+ `,
146
+ options: {
147
+ multilineArraysLinePattern: '1 2 3',
148
+ multilineArraysWrapThreshold: 20,
149
+ },
150
+ },
151
+ {
152
+ it: 'pointless wrap threshold comment',
153
+ code: `
154
+ // ${nextWrapThresholdComment} 0
155
+ [
156
+ "hello"
157
+ ]
158
+ `,
159
+ },
160
+ {
161
+ it: 'leaves trailing newline',
162
+ code: `
163
+ {
164
+ "import": ".cspell-base.json",
165
+ "words": [
166
+ "estree",
167
+ "hardline",
168
+ "jsplugin",
169
+ "mmultiline",
170
+ "vite"
171
+ ]
172
+ }
173
+ `,
174
+ },
175
+ {
176
+ /** This test is weird, it won't work if the newline before "example" isn't there. */
177
+ it: 'with object array element',
178
+ code: `
179
+ {
180
+ "hello": "there",
181
+ "stuff": ["a", "b", "c", "d", "e", {
182
+ "example": "instance"}],
183
+ "object": {"example": "instance"}
184
+ }
185
+ `,
186
+ expect: `
187
+ {
188
+ "hello": "there",
189
+ "object": {"example": "instance"},
190
+ "stuff": [
191
+ "a",
192
+ "b",
193
+ "c",
194
+ "d",
195
+ "e",
196
+ {
197
+ "example": "instance"
198
+ }
199
+ ]
200
+ }
201
+ `,
202
+ },
203
+ {
204
+ it: 'with nested array',
205
+ code: `
206
+ {
207
+ "hello": "there",
208
+ "stuff": ["a", "b", "c", "d", "e", ["f", "g", "h", "i", "j"]],
209
+ "object": {"example": "instance"}
210
+ }
211
+ `,
212
+ expect: `
213
+ {
214
+ "hello": "there",
215
+ "object": {"example": "instance"},
216
+ "stuff": [
217
+ "a",
218
+ "b",
219
+ "c",
220
+ "d",
221
+ "e",
222
+ [
223
+ "f",
224
+ "g",
225
+ "h",
226
+ "i",
227
+ "j"
228
+ ]
229
+ ]
230
+ }
231
+ `,
232
+ options: {
233
+ multilineArraysWrapThreshold: 0,
234
+ },
235
+ },
236
+ {
237
+ it: 'with multiple nested arrays',
238
+ code: `
239
+ {
240
+ "hello": "there",
241
+ "stuff": ["a", "b", ["f", "g", "h", "i", "j"], "c", "d", "e", ["f", "g", "h", "i", "j"]],
242
+ "object": {"example": "instance"}
243
+ }
244
+ `,
245
+ expect: `
246
+ {
247
+ "hello": "there",
248
+ "object": {"example": "instance"},
249
+ "stuff": [
250
+ "a",
251
+ "b",
252
+ [
253
+ "f",
254
+ "g",
255
+ "h",
256
+ "i",
257
+ "j"
258
+ ],
259
+ "c",
260
+ "d",
261
+ "e",
262
+ [
263
+ "f",
264
+ "g",
265
+ "h",
266
+ "i",
267
+ "j"
268
+ ]
269
+ ]
270
+ }
271
+ `,
272
+ options: {
273
+ multilineArraysWrapThreshold: 0,
274
+ },
275
+ },
276
+ {
277
+ it: 'basic JSON array with a comment',
278
+ code: `
279
+ {
280
+ "data": [
281
+ "one",
282
+ // comment
283
+ "two"
284
+ ]
285
+ }
286
+ `,
287
+ },
288
+ {
289
+ it: 'basic JSON array with multiple comments',
290
+ code: `
291
+ {
292
+ // comment
293
+ "data": [
294
+ // comment
295
+ "one",
296
+ // comment
297
+ "two"
298
+ // comment
299
+ ]
300
+ // comment
301
+ }
302
+ // comment
303
+ `,
304
+ },
305
+ {
306
+ it: 'basic JSON array with multiline comments',
307
+ code: `
308
+ {
309
+ /*
310
+ comment
311
+ comment
312
+ comment
313
+ */
314
+ "data": [
315
+ /*
316
+ comment
317
+ comment
318
+ comment
319
+ */
320
+ "one",
321
+ /*
322
+ comment
323
+ comment
324
+ comment
325
+ */
326
+ "two"
327
+ /*
328
+ comment
329
+ comment
330
+ comment
331
+ */
332
+ ]
333
+ /*
334
+ comment
335
+ comment
336
+ comment
337
+ */
338
+ }
339
+ /*
340
+ comment
341
+ comment
342
+ comment
343
+ */
344
+ `,
345
+ },
346
+ {
347
+ it: 'handles array with only comments GitHub Issue #75',
348
+ code: `
349
+ {
350
+ "editor.codeActionsOnSave": [
351
+ // "hello",
352
+ // "source.fixAll.eslint",
353
+ // "source.fixAll.prettier",
354
+ ]
355
+ }
356
+ `,
357
+ },
358
+ {
359
+ it: 'basic JSON array',
360
+ code: `
361
+ {
362
+ "data": [
363
+ "one",
364
+ "two"
365
+ ]
366
+ }
367
+ `,
368
+ },
369
+ {
370
+ it: 'basic lone element JSON array',
371
+ code: `
372
+ {
373
+ "data": [
374
+ "one one one one one one one one one one one one one one one one one one one one",
375
+ "two two two two two two two two two two two two two two two two two two two two"
376
+ ]
377
+ }
378
+ `,
379
+ },
380
+ {
381
+ it: 'keeps closing bracket on its own line for array of objects with bracketSpacing GitHub Issue #70',
382
+ code: `
383
+ {
384
+ "test": [
385
+ { "foo": 1 },
386
+ { "bar": 2 },
387
+ { "baz": 3 }
388
+ ]
389
+ }
390
+ `,
391
+ options: {
392
+ bracketSpacing: true,
393
+ multilineArraysWrapThreshold: 1,
394
+ },
395
+ },
396
+ ];
397
+ describe('json multiline array formatting', () => {
398
+ runTests({
399
+ extension: '.json',
400
+ tests: jsonTests,
401
+ parser: 'json',
402
+ });
403
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,210 @@
1
+ import { describe } from '@augment-vir/test';
2
+ import { nextWrapThresholdComment } from '../options.js';
3
+ import { runTests } from './run-tests.mock.js';
4
+ const json5Tests = [
5
+ {
6
+ it: 'basic JSON format',
7
+ code: `
8
+ {
9
+ hello: 'there',
10
+ stuff: ['a', 'b', 'c', 'd', 'e'],
11
+ object: {example: 'instance'}
12
+ }
13
+ `,
14
+ expect: `
15
+ {
16
+ hello: 'there',
17
+ stuff: [
18
+ 'a',
19
+ 'b',
20
+ 'c',
21
+ 'd',
22
+ 'e',
23
+ ],
24
+ object: {example: 'instance'},
25
+ }
26
+ `,
27
+ options: {
28
+ multilineArraysWrapThreshold: 0,
29
+ },
30
+ },
31
+ {
32
+ it: 'basic wrap threshold comment',
33
+ code: `
34
+ // ${nextWrapThresholdComment} 3
35
+ ['hello']
36
+ `,
37
+ },
38
+ {
39
+ it: 'invalid wrap threshold triggers error',
40
+ code: `
41
+ ['hello']
42
+ `,
43
+ options: {
44
+ multilineArraysWrapThreshold: 'fifty two',
45
+ },
46
+ failureMessage: 'Invalid multilineArraysWrapThreshold value. Expected an integer, but received "fifty two".',
47
+ },
48
+ {
49
+ it: 'wrap threshold through options',
50
+ code: `
51
+ ['hello']
52
+ `,
53
+ options: {
54
+ multilineArraysWrapThreshold: 3,
55
+ },
56
+ },
57
+ {
58
+ it: 'line count through options',
59
+ code: `
60
+ ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
61
+ `,
62
+ expect: `
63
+ [
64
+ 'a',
65
+ 'b', 'c',
66
+ 'd', 'e', 'f',
67
+ 'g',
68
+ 'h',
69
+ ]
70
+ `,
71
+ options: {
72
+ multilineArraysLinePattern: '1 2 3',
73
+ },
74
+ },
75
+ {
76
+ it: 'line count overrides threshold',
77
+ code: `
78
+ ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
79
+ `,
80
+ expect: `
81
+ [
82
+ 'a',
83
+ 'b', 'c',
84
+ 'd', 'e', 'f',
85
+ 'g',
86
+ 'h',
87
+ ]
88
+ `,
89
+ options: {
90
+ multilineArraysLinePattern: '1 2 3',
91
+ multilineArraysWrapThreshold: 20,
92
+ },
93
+ },
94
+ {
95
+ it: 'pointless wrap threshold comment',
96
+ code: `
97
+ // ${nextWrapThresholdComment} 0
98
+ [
99
+ 'hello',
100
+ ]
101
+ `,
102
+ },
103
+ {
104
+ it: 'with object array element',
105
+ code: `
106
+ {
107
+ hello: 'there',
108
+ stuff: ['a', 'b', 'c', 'd', 'e', {example: 'instance'}],
109
+ object: {example: 'instance'}
110
+ }
111
+ `,
112
+ expect: `
113
+ {
114
+ hello: 'there',
115
+ stuff: [
116
+ 'a',
117
+ 'b',
118
+ 'c',
119
+ 'd',
120
+ 'e',
121
+ {example: 'instance'},
122
+ ],
123
+ object: {example: 'instance'},
124
+ }
125
+ `,
126
+ options: {
127
+ multilineArraysWrapThreshold: 0,
128
+ },
129
+ },
130
+ {
131
+ it: 'with nested array',
132
+ code: `
133
+ {
134
+ hello: 'there',
135
+ stuff: ['a', 'b', 'c', 'd', 'e', ['f', 'g', 'h', 'i', 'j']],
136
+ object: {example: 'instance'}
137
+ }
138
+ `,
139
+ expect: `
140
+ {
141
+ hello: 'there',
142
+ stuff: [
143
+ 'a',
144
+ 'b',
145
+ 'c',
146
+ 'd',
147
+ 'e',
148
+ [
149
+ 'f',
150
+ 'g',
151
+ 'h',
152
+ 'i',
153
+ 'j',
154
+ ],
155
+ ],
156
+ object: {example: 'instance'},
157
+ }
158
+ `,
159
+ options: {
160
+ multilineArraysWrapThreshold: 0,
161
+ },
162
+ },
163
+ {
164
+ it: 'with multiple nested arrays',
165
+ code: `
166
+ {
167
+ hello: 'there',
168
+ stuff: ['a', 'b', ['f', 'g', 'h', 'i', 'j'], 'c', 'd', 'e', ['f', 'g', 'h', 'i', 'j']],
169
+ object: {example: 'instance'}
170
+ }
171
+ `,
172
+ expect: `
173
+ {
174
+ hello: 'there',
175
+ stuff: [
176
+ 'a',
177
+ 'b',
178
+ [
179
+ 'f',
180
+ 'g',
181
+ 'h',
182
+ 'i',
183
+ 'j',
184
+ ],
185
+ 'c',
186
+ 'd',
187
+ 'e',
188
+ [
189
+ 'f',
190
+ 'g',
191
+ 'h',
192
+ 'i',
193
+ 'j',
194
+ ],
195
+ ],
196
+ object: {example: 'instance'},
197
+ }
198
+ `,
199
+ options: {
200
+ multilineArraysWrapThreshold: 0,
201
+ },
202
+ },
203
+ ];
204
+ describe('json5 multiline array formatting', () => {
205
+ runTests({
206
+ extension: '.json',
207
+ tests: json5Tests,
208
+ parser: 'json5',
209
+ });
210
+ });
@@ -0,0 +1,2 @@
1
+ import type { Options } from "prettier";
2
+ export declare const repoConfig: Options;
@@ -0,0 +1,12 @@
1
+ // @ts-expect-error: ignore this import cause it's not typed. This file itself is manually typing it.
2
+ import importedRepoConfig from "../../prettier.config.mjs";
3
+ export const repoConfig = importedRepoConfig;
4
+ Object.assign(repoConfig, {
5
+ bracketSpacing: false,
6
+ jsonRecursiveSort: false,
7
+ plugins: (repoConfig.plugins ?? []).filter((plugin) => plugin !== "prettier-plugin-sort-json"),
8
+ printWidth: 100,
9
+ singleQuote: true,
10
+ tabWidth: 4,
11
+ trailingComma: "all",
12
+ });
@@ -0,0 +1 @@
1
+ export {};