]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/array-bracket-newline.js
90ee8213b7780d8c4c2c995d011df2d497d687d6
[pve-eslint.git] / eslint / tests / lib / rules / array-bracket-newline.js
1 /**
2 * @fileoverview Tests for array-bracket-newline rule.
3 * @author Jan Peer Stöcklmair <https://github.com/JPeer264>
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/array-bracket-newline");
13 const { RuleTester } = require("../../../lib/rule-tester");
14
15
16 //------------------------------------------------------------------------------
17 // Tests
18 //------------------------------------------------------------------------------
19
20 const ruleTester = new RuleTester();
21
22 ruleTester.run("array-bracket-newline", rule, {
23
24 valid: [
25
26 /*
27 * ArrayExpression
28 * "default" { multiline: true }
29 */
30 "var foo = [];",
31 "var foo = [1];",
32 "var foo = /* any comment */[1];",
33 "var foo = /* any comment */\n[1];",
34 "var foo = [1, 2];",
35 "var foo = [ // any comment\n1, 2\n];",
36 "var foo = [\n// any comment\n1, 2\n];",
37 "var foo = [\n1, 2\n// any comment\n];",
38 "var foo = [\n1,\n2\n];",
39 "var foo = [\nfunction foo() {\nreturn dosomething();\n}\n];",
40 "var foo = [/* \nany comment\n */];",
41 "var foo = [/* single line multiline comment for no real reason */];",
42 "var foo = [[1,2]]",
43
44 // "always"
45 { code: "var foo = [\n];", options: ["always"] },
46 { code: "var foo = [\n1\n];", options: ["always"] },
47 { code: "var foo = [\n// any\n1\n];", options: ["always"] },
48 { code: "var foo = [\n/* any */\n1\n];", options: ["always"] },
49 { code: "var foo = [\n1, 2\n];", options: ["always"] },
50 { code: "var foo = [\n1, 2 // any comment\n];", options: ["always"] },
51 {
52 code: "var foo = [\n1, 2 /* any comment */\n];",
53 options: ["always"]
54 },
55 { code: "var foo = [\n1,\n2\n];", options: ["always"] },
56 {
57 code: "var foo = [\nfunction foo() {\ndosomething();\n}\n];",
58 options: ["always"]
59 },
60 {
61 code: `
62 var foo = [
63 [
64 1,2
65 ]
66 ]
67 `,
68 options: ["always"]
69 },
70 {
71 code: `
72 var foo = [
73 0,
74 [
75 1,2
76 ],
77 3
78 ]
79 `,
80 options: ["always"]
81 },
82
83 // "never"
84 { code: "var foo = [];", options: ["never"] },
85 { code: "var foo = [1];", options: ["never"] },
86 { code: "var foo = [/* any comment */1];", options: ["never"] },
87 { code: "var foo = [1, 2];", options: ["never"] },
88 { code: "var foo = [1,\n2];", options: ["never"] },
89 { code: "var foo = [1,\n/* any comment */\n2];", options: ["never"] },
90 {
91 code: "var foo = [function foo() {\ndosomething();\n}];",
92 options: ["never"]
93 },
94 {
95 code: "var foo = [[1,2],3];",
96 options: ["never"]
97 },
98
99 // "consistent"
100 { code: "var a = []", options: ["consistent"] },
101 { code: "var a = [\n]", options: ["consistent"] },
102 { code: "var a = [1]", options: ["consistent"] },
103 { code: "var a = [\n1\n]", options: ["consistent"] },
104 { code: "var a = [//\n1\n]", options: ["consistent"] },
105 { code: "var a = [/**/\n1\n]", options: ["consistent"] },
106 { code: "var a = [/*\n*/1\n]", options: ["consistent"] },
107 { code: "var a = [//\n]", options: ["consistent"] },
108 {
109 code: `var a = [
110 [1,2]
111 ]`,
112 options: ["consistent"]
113 },
114 {
115 code: `var a = [
116 [[1,2]]
117 ]`,
118 options: ["consistent"]
119 },
120
121 // { multiline: true }
122 { code: "var foo = [];", options: [{ multiline: true }] },
123 { code: "var foo = [1];", options: [{ multiline: true }] },
124 {
125 code: "var foo = /* any comment */[1];",
126 options: [{ multiline: true }]
127 },
128 {
129 code: "var foo = /* any comment */\n[1];",
130 options: [{ multiline: true }]
131 },
132 { code: "var foo = [1, 2];", options: [{ multiline: true }] },
133 {
134 code: "var foo = [ // any comment\n1, 2\n];",
135 options: [{ multiline: true }]
136 },
137 {
138 code: "var foo = [\n// any comment\n1, 2\n];",
139 options: [{ multiline: true }]
140 },
141 {
142 code: "var foo = [\n1, 2\n// any comment\n];",
143 options: [{ multiline: true }]
144 },
145 { code: "var foo = [\n1,\n2\n];", options: [{ multiline: true }] },
146 {
147 code: "var foo = [\nfunction foo() {\nreturn dosomething();\n}\n];",
148 options: [{ multiline: true }]
149 },
150 {
151 code: "var foo = [/* \nany comment\n */];",
152 options: [{ multiline: true }]
153 },
154 {
155 code: "var foo = [\n1,\n2,\n[3,4],\n];",
156 options: [{ multiline: true }]
157 },
158 {
159 code: "var foo = [\n1,\n2,\n[\n3,\n4\n],\n];",
160 options: [{ multiline: true }]
161 },
162
163 // { multiline: false }
164 { code: "var foo = [];", options: [{ multiline: false }] },
165 { code: "var foo = [1];", options: [{ multiline: false }] },
166 {
167 code: "var foo = [1]/* any comment*/;",
168 options: [{ multiline: false }]
169 },
170 {
171 code: "var foo = [1]\n/* any comment*/\n;",
172 options: [{ multiline: false }]
173 },
174 { code: "var foo = [1, 2];", options: [{ multiline: false }] },
175 { code: "var foo = [1,\n2];", options: [{ multiline: false }] },
176 {
177 code: "var foo = [function foo() {\nreturn dosomething();\n}];",
178 options: [{ multiline: false }]
179 },
180 { code: "var foo = [1,\n2,[3,\n4]];", options: [{ multiline: false }] },
181
182 // { minItems: 2 }
183 { code: "var foo = [];", options: [{ minItems: 2 }] },
184 { code: "var foo = [1];", options: [{ minItems: 2 }] },
185 { code: "var foo = [\n1, 2\n];", options: [{ minItems: 2 }] },
186 { code: "var foo = [\n1,\n2\n];", options: [{ minItems: 2 }] },
187 {
188 code: "var foo = [function foo() {\ndosomething();\n}];",
189 options: [{ minItems: 2 }]
190 },
191 {
192 code: `var foo = [
193 1,[
194 2,3
195 ]
196 ];`,
197 options: [{ minItems: 2 }]
198 },
199 {
200 code: `var foo = [[
201 1,2
202 ]]`,
203 options: [{ minItems: 2 }]
204 },
205
206 // { minItems: 0 }
207 { code: "var foo = [\n];", options: [{ minItems: 0 }] },
208 { code: "var foo = [\n1\n];", options: [{ minItems: 0 }] },
209 { code: "var foo = [\n1, 2\n];", options: [{ minItems: 0 }] },
210 { code: "var foo = [\n1,\n2\n];", options: [{ minItems: 0 }] },
211 {
212 code: "var foo = [\nfunction foo() {\ndosomething();\n}\n];",
213 options: [{ minItems: 0 }]
214 },
215
216 // { minItems: null }
217 { code: "var foo = [];", options: [{ minItems: null }] },
218 { code: "var foo = [1];", options: [{ minItems: null }] },
219 { code: "var foo = [1, 2];", options: [{ minItems: null }] },
220 { code: "var foo = [1,\n2];", options: [{ minItems: null }] },
221 {
222 code: "var foo = [function foo() {\ndosomething();\n}];",
223 options: [{ minItems: null }]
224 },
225
226 // { multiline: true, minItems: null }
227 {
228 code: "var foo = [];",
229 options: [{ multiline: true, minItems: null }]
230 },
231 {
232 code: "var foo = [1];",
233 options: [{ multiline: true, minItems: null }]
234 },
235 {
236 code: "var foo = [1, 2];",
237 options: [{ multiline: true, minItems: null }]
238 },
239 {
240 code: "var foo = [\n1,\n2\n];",
241 options: [{ multiline: true, minItems: null }]
242 },
243 {
244 code: "var foo = [\nfunction foo() {\ndosomething();\n}\n];",
245 options: [{ multiline: true, minItems: null }]
246 },
247
248 // { multiline: true, minItems: 2 }
249 { code: "var a = [];", options: [{ multiline: true, minItems: 2 }] },
250 { code: "var b = [1];", options: [{ multiline: true, minItems: 2 }] },
251 {
252 code: "var b = [ // any comment\n1\n];",
253 options: [{ multiline: true, minItems: 2 }]
254 },
255 {
256 code: "var b = [ /* any comment */ 1];",
257 options: [{ multiline: true, minItems: 2 }]
258 },
259 {
260 code: "var c = [\n1, 2\n];",
261 options: [{ multiline: true, minItems: 2 }]
262 },
263 {
264 code: "var c = [\n/* any comment */1, 2\n];",
265 options: [{ multiline: true, minItems: 2 }]
266 },
267 {
268 code: "var c = [\n1, /* any comment */ 2\n];",
269 options: [{ multiline: true, minItems: 2 }]
270 },
271 {
272 code: "var d = [\n1,\n2\n];",
273 options: [{ multiline: true, minItems: 2 }]
274 },
275 {
276 code: "var e = [\nfunction foo() {\ndosomething();\n}\n];",
277 options: [{ multiline: true, minItems: 2 }]
278 },
279
280 /*
281 * ArrayPattern
282 * default { multiline: true }
283 */
284 { code: "var [] = foo", parserOptions: { ecmaVersion: 6 } },
285 { code: "var [a] = foo;", parserOptions: { ecmaVersion: 6 } },
286 {
287 code: "var /* any comment */[a] = foo;",
288 parserOptions: { ecmaVersion: 6 }
289 },
290 {
291 code: "var /* any comment */\n[a] = foo;",
292 parserOptions: { ecmaVersion: 6 }
293 },
294 { code: "var [a, b] = foo;", parserOptions: { ecmaVersion: 6 } },
295 {
296 code: "var [ // any comment\na, b\n] = foo;",
297 parserOptions: { ecmaVersion: 6 }
298 },
299 {
300 code: "var [\n// any comment\na, b\n] = foo;",
301 parserOptions: { ecmaVersion: 6 }
302 },
303 {
304 code: "var [\na, b\n// any comment\n] = foo;",
305 parserOptions: { ecmaVersion: 6 }
306 },
307 { code: "var [\na,\nb\n] = foo;", parserOptions: { ecmaVersion: 6 } },
308
309 // "always"
310 {
311 code: "var [\n] = foo;",
312 options: ["always"],
313 parserOptions: { ecmaVersion: 6 }
314 },
315 {
316 code: "var [\na\n] = foo;",
317 options: ["always"],
318 parserOptions: { ecmaVersion: 6 }
319 },
320 {
321 code: "var [\n// any\na\n] = foo;",
322 options: ["always"],
323 parserOptions: { ecmaVersion: 6 }
324 },
325 {
326 code: "var [\n/* any */\na\n] = foo;",
327 options: ["always"],
328 parserOptions: { ecmaVersion: 6 }
329 },
330 {
331 code: "var [\na, b\n] = foo;",
332 options: ["always"],
333 parserOptions: { ecmaVersion: 6 }
334 },
335 {
336 code: "var [\na, b // any comment\n] = foo;",
337 options: ["always"],
338 parserOptions: { ecmaVersion: 6 }
339 },
340 {
341 code: "var [\na, b /* any comment */\n] = foo;",
342 options: ["always"],
343 parserOptions: { ecmaVersion: 6 }
344 },
345 {
346 code: "var [\na,\nb\n] = foo;",
347 options: ["always"],
348 parserOptions: { ecmaVersion: 6 }
349 },
350
351 // "consistent"
352 {
353 code: "var [] = foo",
354 options: ["consistent"],
355 parserOptions: { ecmaVersion: 6 }
356 },
357 {
358 code: "var [\n] = foo",
359 options: ["consistent"],
360 parserOptions: { ecmaVersion: 6 }
361 },
362 {
363 code: "var [a] = foo",
364 options: ["consistent"],
365 parserOptions: { ecmaVersion: 6 }
366 },
367 {
368 code: "var [\na\n] = foo",
369 options: ["consistent"],
370 parserOptions: { ecmaVersion: 6 }
371 },
372 {
373 code: "var [//\na\n] = foo",
374 options: ["consistent"],
375 parserOptions: { ecmaVersion: 6 }
376 },
377 {
378 code: "var [/**/\na\n] = foo",
379 options: ["consistent"],
380 parserOptions: { ecmaVersion: 6 }
381 },
382 {
383 code: "var [/*\n*/a\n] = foo",
384 options: ["consistent"],
385 parserOptions: { ecmaVersion: 6 }
386 },
387 {
388 code: "var [//\n] = foo",
389 options: ["consistent"],
390 parserOptions: { ecmaVersion: 6 }
391 },
392
393 // { multiline: true }
394 {
395 code: "var [] = foo;",
396 options: [{ multiline: true }],
397 parserOptions: { ecmaVersion: 6 }
398 },
399 {
400 code: "var [a] = foo;",
401 options: [{ multiline: true }],
402 parserOptions: { ecmaVersion: 6 }
403 },
404 {
405 code: "var /* any comment */[a] = foo;",
406 options: [{ multiline: true }],
407 parserOptions: { ecmaVersion: 6 }
408 },
409 {
410 code: "var /* any comment */\n[a] = foo;",
411 options: [{ multiline: true }],
412 parserOptions: { ecmaVersion: 6 }
413 },
414 {
415 code: "var [a, b] = foo;",
416 options: [{ multiline: true }],
417 parserOptions: { ecmaVersion: 6 }
418 },
419 {
420 code: "var [ // any comment\na, b\n] = foo;",
421 options: [{ multiline: true }],
422 parserOptions: { ecmaVersion: 6 }
423 },
424 {
425 code: "var [\n// any comment\na, b\n] = foo;",
426 options: [{ multiline: true }],
427 parserOptions: { ecmaVersion: 6 }
428 },
429 {
430 code: "var [\na, b\n// any comment\n] = foo;",
431 options: [{ multiline: true }],
432 parserOptions: { ecmaVersion: 6 }
433 },
434 {
435 code: "var [\na,\nb\n] = foo;",
436 options: [{ multiline: true }],
437 parserOptions: { ecmaVersion: 6 }
438 }
439 ],
440
441 invalid: [
442
443 // default : { mutliline : true}
444 {
445 code: `var foo = [
446 [1,2]
447 ]`,
448 output: "var foo = [[1,2]]",
449 errors: [
450 {
451 messageId: "unexpectedOpeningLinebreak",
452 type: "ArrayExpression",
453 line: 1,
454 column: 11,
455 endLine: 1,
456 endColumn: 12
457 },
458 {
459 messageId: "unexpectedClosingLinebreak",
460 type: "ArrayExpression",
461 line: 3,
462 column: 13,
463 endLine: 3,
464 endColumn: 14
465 }
466 ]
467 },
468 {
469 code: "var foo = [[2,\n3]]",
470 output: "var foo = [\n[\n2,\n3\n]\n]",
471 errors: [
472 {
473 line: 1,
474 column: 11,
475 messageId: "missingOpeningLinebreak",
476 endLine: 1,
477 endColumn: 12
478 },
479 {
480 line: 1,
481 column: 12,
482 messageId: "missingOpeningLinebreak",
483 endLine: 1,
484 endColumn: 13
485 },
486 {
487 line: 2,
488 column: 2,
489 messageId: "missingClosingLinebreak",
490 endLine: 2,
491 endColumn: 3
492 },
493 {
494 line: 2,
495 column: 3,
496 messageId: "missingClosingLinebreak",
497 endLine: 2,
498 endColumn: 4
499 }
500 ]
501 },
502
503 /*
504 * ArrayExpression
505 * "always"
506 */
507 {
508 code: "var foo = [[1,2]]",
509 output: "var foo = [\n[\n1,2\n]\n]",
510 options: ["always"],
511 errors: [
512 {
513 line: 1,
514 column: 11,
515 messageId: "missingOpeningLinebreak",
516 endLine: 1,
517 endColumn: 12
518 },
519 {
520 line: 1,
521 column: 12,
522 messageId: "missingOpeningLinebreak",
523 endLine: 1,
524 endColumn: 13
525 },
526 {
527 line: 1,
528 column: 16,
529 messageId: "missingClosingLinebreak",
530 endLine: 1,
531 endColumn: 17
532 },
533 {
534 line: 1,
535 column: 17,
536 messageId: "missingClosingLinebreak",
537 endLine: 1,
538 endColumn: 18
539 }
540 ]
541 },
542 {
543 code: "var foo = [];",
544 output: "var foo = [\n];",
545 options: ["always"],
546 errors: [
547 {
548 messageId: "missingOpeningLinebreak",
549 type: "ArrayExpression",
550 line: 1,
551 column: 11,
552 endLine: 1,
553 endColumn: 12
554 },
555 {
556 messageId: "missingClosingLinebreak",
557 type: "ArrayExpression",
558 line: 1,
559 column: 12,
560 endLine: 1,
561 endColumn: 13
562 }
563 ]
564 },
565 {
566 code: "var foo = [1];",
567 output: "var foo = [\n1\n];",
568 options: ["always"],
569 errors: [
570 {
571 messageId: "missingOpeningLinebreak",
572 type: "ArrayExpression",
573 line: 1,
574 column: 11
575 },
576 {
577 messageId: "missingClosingLinebreak",
578 type: "ArrayExpression",
579 line: 1,
580 column: 13
581 }
582 ]
583 },
584 {
585 code: "var foo = [ // any comment\n1];",
586 output: "var foo = [ // any comment\n1\n];",
587 options: ["always"],
588 errors: [
589 {
590 messageId: "missingClosingLinebreak",
591 type: "ArrayExpression",
592 line: 2,
593 column: 2,
594 endLine: 2,
595 endColumn: 3
596 }
597 ]
598 },
599 {
600 code: "var foo = [ /* any comment */\n1];",
601 output: "var foo = [ /* any comment */\n1\n];",
602 options: ["always"],
603 errors: [
604 {
605 messageId: "missingClosingLinebreak",
606 type: "ArrayExpression",
607 line: 2,
608 column: 2
609 }
610 ]
611 },
612 {
613 code: "var foo = [1, 2];",
614 output: "var foo = [\n1, 2\n];",
615 options: ["always"],
616 errors: [
617 {
618 messageId: "missingOpeningLinebreak",
619 type: "ArrayExpression",
620 line: 1,
621 column: 11,
622 endLine: 1,
623 endColumn: 12
624 },
625 {
626 messageId: "missingClosingLinebreak",
627 type: "ArrayExpression",
628 line: 1,
629 column: 16,
630 endLine: 1,
631 endColumn: 17
632 }
633 ]
634 },
635 {
636 code: "var foo = [1, 2 // any comment\n];",
637 output: "var foo = [\n1, 2 // any comment\n];",
638 options: ["always"],
639 errors: [
640 {
641 messageId: "missingOpeningLinebreak",
642 type: "ArrayExpression",
643 line: 1,
644 column: 11
645 }
646 ]
647 },
648 {
649 code: "var foo = [1, 2 /* any comment */];",
650 output: "var foo = [\n1, 2 /* any comment */\n];",
651 options: ["always"],
652 errors: [
653 {
654 messageId: "missingOpeningLinebreak",
655 type: "ArrayExpression",
656 line: 1,
657 column: 11
658 },
659 {
660 messageId: "missingClosingLinebreak",
661 type: "ArrayExpression",
662 line: 1,
663 column: 34
664 }
665 ]
666 },
667 {
668 code: "var foo = [1,\n2];",
669 output: "var foo = [\n1,\n2\n];",
670 options: ["always"],
671 errors: [
672 {
673 messageId: "missingOpeningLinebreak",
674 type: "ArrayExpression",
675 line: 1,
676 column: 11
677 },
678 {
679 messageId: "missingClosingLinebreak",
680 type: "ArrayExpression",
681 line: 2,
682 column: 2
683 }
684 ]
685 },
686 {
687 code: "var foo = [function foo() {\ndosomething();\n}];",
688 output: "var foo = [\nfunction foo() {\ndosomething();\n}\n];",
689 options: ["always"],
690 errors: [
691 {
692 messageId: "missingOpeningLinebreak",
693 type: "ArrayExpression",
694 line: 1,
695 column: 11
696 },
697 {
698 messageId: "missingClosingLinebreak",
699 type: "ArrayExpression",
700 line: 3,
701 column: 2
702 }
703 ]
704 },
705
706 // "never"
707 {
708 code: `var foo = [[
709 1,2],3];`,
710 output: "var foo = [[1,2],3];",
711 options: ["never"],
712 errors: [
713 {
714 line: 1,
715 column: 12,
716 messageId: "unexpectedOpeningLinebreak",
717 endLine: 1,
718 endColumn: 13
719 }
720 ]
721 },
722 {
723 code: "var foo = [\n];",
724 output: "var foo = [];",
725 options: ["never"],
726 errors: [
727 {
728 messageId: "unexpectedOpeningLinebreak",
729 type: "ArrayExpression",
730 line: 1,
731 column: 11
732 },
733 {
734 messageId: "unexpectedClosingLinebreak",
735 type: "ArrayExpression",
736 line: 2,
737 column: 1
738 }
739 ]
740 },
741 {
742 code: "var foo = [\n1\n];",
743 output: "var foo = [1];",
744 options: ["never"],
745 errors: [
746 {
747 messageId: "unexpectedOpeningLinebreak",
748 type: "ArrayExpression",
749 line: 1,
750 column: 11,
751 endLine: 1,
752 endColumn: 12
753 },
754 {
755 messageId: "unexpectedClosingLinebreak",
756 type: "ArrayExpression",
757 line: 3,
758 column: 1,
759 endLine: 3,
760 endColumn: 2
761 }
762 ]
763 },
764 {
765 code: "var foo = [\n1\n];",
766 output: "var foo = [1];",
767 options: ["never"],
768 errors: [
769 {
770 messageId: "unexpectedOpeningLinebreak",
771 type: "ArrayExpression",
772 line: 1,
773 column: 11
774 },
775 {
776 messageId: "unexpectedClosingLinebreak",
777 type: "ArrayExpression",
778 line: 3,
779 column: 1
780 }
781 ]
782 },
783 {
784 code: "var foo = [ /* any comment */\n1, 2\n];",
785 output: "var foo = [ /* any comment */\n1, 2];",
786 options: ["never"],
787 errors: [
788 {
789 messageId: "unexpectedOpeningLinebreak",
790 type: "ArrayExpression",
791 line: 1,
792 column: 11
793 },
794 {
795 messageId: "unexpectedClosingLinebreak",
796 type: "ArrayExpression",
797 line: 3,
798 column: 1
799 }
800 ]
801 },
802 {
803 code: "var foo = [\n1, 2\n/* any comment */];",
804 output: "var foo = [1, 2\n/* any comment */];",
805 options: ["never"],
806 errors: [
807 {
808 messageId: "unexpectedOpeningLinebreak",
809 type: "ArrayExpression",
810 line: 1,
811 column: 11
812 },
813 {
814 messageId: "unexpectedClosingLinebreak",
815 type: "ArrayExpression",
816 line: 3,
817 column: 18
818 }
819 ]
820 },
821 {
822 code: "var foo = [ // any comment\n1, 2\n];",
823 output: "var foo = [ // any comment\n1, 2];",
824 options: ["never"],
825 errors: [
826 {
827 messageId: "unexpectedOpeningLinebreak",
828 type: "ArrayExpression",
829 line: 1,
830 column: 11
831 },
832 {
833 messageId: "unexpectedClosingLinebreak",
834 type: "ArrayExpression",
835 line: 3,
836 column: 1
837 }
838 ]
839 },
840 {
841 code: "var foo = [\n1,\n2\n];",
842 output: "var foo = [1,\n2];",
843 options: ["never"],
844 errors: [
845 {
846 messageId: "unexpectedOpeningLinebreak",
847 type: "ArrayExpression",
848 line: 1,
849 column: 11
850 },
851 {
852 messageId: "unexpectedClosingLinebreak",
853 type: "ArrayExpression",
854 line: 4,
855 column: 1
856 }
857 ]
858 },
859 {
860 code: "var foo = [\nfunction foo() {\ndosomething();\n}\n];",
861 output: "var foo = [function foo() {\ndosomething();\n}];",
862 options: ["never"],
863 errors: [
864 {
865 messageId: "unexpectedOpeningLinebreak",
866 type: "ArrayExpression",
867 line: 1,
868 column: 11
869 },
870 {
871 messageId: "unexpectedClosingLinebreak",
872 type: "ArrayExpression",
873 line: 5,
874 column: 1
875 }
876 ]
877 },
878
879 // "consistent"
880 {
881 code: `var a = [[1,2]
882 ]`,
883 output: "var a = [[1,2]]",
884 options: ["consistent"],
885 errors: [
886 {
887 line: 2,
888 column: 13,
889 messageId: "unexpectedClosingLinebreak",
890 endLine: 2,
891 endColumn: 14
892 }
893 ]
894 },
895 {
896 code: "var a = [\n[\n[1,2]]\n]",
897 output: "var a = [\n[\n[1,2]\n]\n]",
898 options: ["consistent"],
899 errors: [
900 {
901 line: 3,
902 column: 6,
903 messageId: "missingClosingLinebreak",
904 endLine: 3,
905 endColumn: 7
906 }
907 ]
908 },
909 {
910 code: "var foo = [\n1]",
911 output: "var foo = [\n1\n]",
912 options: ["consistent"],
913 errors: [
914 {
915 messageId: "missingClosingLinebreak",
916 type: "ArrayExpression",
917 line: 2,
918 column: 2,
919 endLine: 2,
920 endColumn: 3
921 }
922 ]
923 },
924 {
925 code: "var foo = [1\n]",
926 output: "var foo = [1]",
927 options: ["consistent"],
928 errors: [
929 {
930 messageId: "unexpectedClosingLinebreak",
931 type: "ArrayExpression",
932 line: 2,
933 column: 1,
934 endLine: 2,
935 endColumn: 2
936 }
937 ]
938 },
939 {
940 code: "var foo = [//\n1]",
941 output: "var foo = [//\n1\n]",
942 options: ["consistent"],
943 errors: [
944 {
945 messageId: "missingClosingLinebreak",
946 type: "ArrayExpression",
947 line: 2,
948 column: 2,
949 endLine: 2,
950 endColumn: 3
951 }
952 ]
953 },
954
955 // { multiline: true }
956 {
957 code: "var foo = [\n];",
958 output: "var foo = [];",
959 options: [{ multiline: true }],
960 errors: [
961 {
962 messageId: "unexpectedOpeningLinebreak",
963 type: "ArrayExpression",
964 line: 1,
965 column: 11
966 },
967 {
968 messageId: "unexpectedClosingLinebreak",
969 type: "ArrayExpression",
970 line: 2,
971 column: 1
972 }
973 ]
974 },
975 {
976 code: "var foo = [\n// any comment\n];",
977 output: null,
978 options: [{ multiline: true }],
979 errors: [
980 {
981 messageId: "unexpectedOpeningLinebreak",
982 type: "ArrayExpression",
983 line: 1,
984 column: 11
985 },
986 {
987 messageId: "unexpectedClosingLinebreak",
988 type: "ArrayExpression",
989 line: 3,
990 column: 1
991 }
992 ]
993 },
994 {
995 code: "var foo = [\n1\n];",
996 output: "var foo = [1];",
997 options: [{ multiline: true }],
998 errors: [
999 {
1000 messageId: "unexpectedOpeningLinebreak",
1001 type: "ArrayExpression",
1002 line: 1,
1003 column: 11
1004 },
1005 {
1006 messageId: "unexpectedClosingLinebreak",
1007 type: "ArrayExpression",
1008 line: 3,
1009 column: 1
1010 }
1011 ]
1012 },
1013 {
1014 code: "var foo = [\n1, 2\n];",
1015 output: "var foo = [1, 2];",
1016 options: [{ multiline: true }],
1017 errors: [
1018 {
1019 messageId: "unexpectedOpeningLinebreak",
1020 type: "ArrayExpression",
1021 line: 1,
1022 column: 11
1023 },
1024 {
1025 messageId: "unexpectedClosingLinebreak",
1026 type: "ArrayExpression",
1027 line: 3,
1028 column: 1
1029 }
1030 ]
1031 },
1032 {
1033 code: "var foo = [1,\n2];",
1034 output: "var foo = [\n1,\n2\n];",
1035 options: [{ multiline: true }],
1036 errors: [
1037 {
1038 messageId: "missingOpeningLinebreak",
1039 type: "ArrayExpression",
1040 line: 1,
1041 column: 11
1042 },
1043 {
1044 messageId: "missingClosingLinebreak",
1045 type: "ArrayExpression",
1046 line: 2,
1047 column: 2
1048 }
1049 ]
1050 },
1051 {
1052 code: "var foo = [function foo() {\ndosomething();\n}];",
1053 output: "var foo = [\nfunction foo() {\ndosomething();\n}\n];",
1054 options: [{ multiline: true }],
1055 errors: [
1056 {
1057 messageId: "missingOpeningLinebreak",
1058 type: "ArrayExpression",
1059 line: 1,
1060 column: 11
1061 },
1062 {
1063 messageId: "missingClosingLinebreak",
1064 type: "ArrayExpression",
1065 line: 3,
1066 column: 2
1067 }
1068 ]
1069 },
1070
1071 // { minItems: 2 }
1072 {
1073 code: "var foo = [1,[\n2,3\n]\n];",
1074 output: "var foo = [\n1,[\n2,3\n]\n];",
1075 options: [{ minItems: 2 }],
1076 errors: [
1077 {
1078 line: 1,
1079 column: 11,
1080 messageId: "missingOpeningLinebreak",
1081 endLine: 1,
1082 endColumn: 12
1083 }
1084 ]
1085 },
1086 {
1087 code: "var foo = [[1,2\n]]",
1088 output: "var foo = [[\n1,2\n]]",
1089 options: [{ minItems: 2 }],
1090 errors: [
1091 {
1092 line: 1,
1093 column: 12,
1094 messageId: "missingOpeningLinebreak",
1095 endLine: 1,
1096 endColumn: 13
1097 }
1098 ]
1099 },
1100 {
1101 code: "var foo = [\n];",
1102 output: "var foo = [];",
1103 options: [{ minItems: 2 }],
1104 errors: [
1105 {
1106 messageId: "unexpectedOpeningLinebreak",
1107 type: "ArrayExpression",
1108 line: 1,
1109 column: 11
1110 },
1111 {
1112 messageId: "unexpectedClosingLinebreak",
1113 type: "ArrayExpression",
1114 line: 2,
1115 column: 1
1116 }
1117 ]
1118 },
1119 {
1120 code: "var foo = [\n1\n];",
1121 output: "var foo = [1];",
1122 options: [{ minItems: 2 }],
1123 errors: [
1124 {
1125 messageId: "unexpectedOpeningLinebreak",
1126 type: "ArrayExpression",
1127 line: 1,
1128 column: 11
1129 },
1130 {
1131 messageId: "unexpectedClosingLinebreak",
1132 type: "ArrayExpression",
1133 line: 3,
1134 column: 1
1135 }
1136 ]
1137 },
1138 {
1139 code: "var foo = [1, 2];",
1140 output: "var foo = [\n1, 2\n];",
1141 options: [{ minItems: 2 }],
1142 errors: [
1143 {
1144 messageId: "missingOpeningLinebreak",
1145 type: "ArrayExpression",
1146 line: 1,
1147 column: 11
1148 },
1149 {
1150 messageId: "missingClosingLinebreak",
1151 type: "ArrayExpression",
1152 line: 1,
1153 column: 16
1154 }
1155 ]
1156 },
1157 {
1158 code: "var foo = [1,\n2];",
1159 output: "var foo = [\n1,\n2\n];",
1160 options: [{ minItems: 2 }],
1161 errors: [
1162 {
1163 messageId: "missingOpeningLinebreak",
1164 type: "ArrayExpression",
1165 line: 1,
1166 column: 11
1167 },
1168 {
1169 messageId: "missingClosingLinebreak",
1170 type: "ArrayExpression",
1171 line: 2,
1172 column: 2
1173 }
1174 ]
1175 },
1176 {
1177 code: "var foo = [\nfunction foo() {\ndosomething();\n}\n];",
1178 output: "var foo = [function foo() {\ndosomething();\n}];",
1179 options: [{ minItems: 2 }],
1180 errors: [
1181 {
1182 messageId: "unexpectedOpeningLinebreak",
1183 type: "ArrayExpression",
1184 line: 1,
1185 column: 11
1186 },
1187 {
1188 messageId: "unexpectedClosingLinebreak",
1189 type: "ArrayExpression",
1190 line: 5,
1191 column: 1
1192 }
1193 ]
1194 },
1195
1196 // { minItems: 0 }
1197 {
1198 code: "var foo = [];",
1199 output: "var foo = [\n];",
1200 options: [{ minItems: 0 }],
1201 errors: [
1202 {
1203 messageId: "missingOpeningLinebreak",
1204 type: "ArrayExpression",
1205 line: 1,
1206 column: 11
1207 },
1208 {
1209 messageId: "missingClosingLinebreak",
1210 type: "ArrayExpression",
1211 line: 1,
1212 column: 12
1213 }
1214 ]
1215 },
1216 {
1217 code: "var foo = [1];",
1218 output: "var foo = [\n1\n];",
1219 options: [{ minItems: 0 }],
1220 errors: [
1221 {
1222 messageId: "missingOpeningLinebreak",
1223 type: "ArrayExpression",
1224 line: 1,
1225 column: 11
1226 },
1227 {
1228 messageId: "missingClosingLinebreak",
1229 type: "ArrayExpression",
1230 line: 1,
1231 column: 13
1232 }
1233 ]
1234 },
1235 {
1236 code: "var foo = [1, 2];",
1237 output: "var foo = [\n1, 2\n];",
1238 options: [{ minItems: 0 }],
1239 errors: [
1240 {
1241 messageId: "missingOpeningLinebreak",
1242 type: "ArrayExpression",
1243 line: 1,
1244 column: 11
1245 },
1246 {
1247 messageId: "missingClosingLinebreak",
1248 type: "ArrayExpression",
1249 line: 1,
1250 column: 16
1251 }
1252 ]
1253 },
1254 {
1255 code: "var foo = [1,\n2];",
1256 output: "var foo = [\n1,\n2\n];",
1257 options: [{ minItems: 0 }],
1258 errors: [
1259 {
1260 messageId: "missingOpeningLinebreak",
1261 type: "ArrayExpression",
1262 line: 1,
1263 column: 11
1264 },
1265 {
1266 messageId: "missingClosingLinebreak",
1267 type: "ArrayExpression",
1268 line: 2,
1269 column: 2
1270 }
1271 ]
1272 },
1273 {
1274 code: "var foo = [function foo() {\ndosomething();\n}];",
1275 output: "var foo = [\nfunction foo() {\ndosomething();\n}\n];",
1276 options: [{ minItems: 0 }],
1277 errors: [
1278 {
1279 messageId: "missingOpeningLinebreak",
1280 type: "ArrayExpression",
1281 line: 1,
1282 column: 11
1283 },
1284 {
1285 messageId: "missingClosingLinebreak",
1286 type: "ArrayExpression",
1287 line: 3,
1288 column: 2
1289 }
1290 ]
1291 },
1292
1293 // { minItems: null }
1294 {
1295 code: "var foo = [\n];",
1296 output: "var foo = [];",
1297 options: [{ minItems: null }],
1298 errors: [
1299 {
1300 messageId: "unexpectedOpeningLinebreak",
1301 type: "ArrayExpression",
1302 line: 1,
1303 column: 11
1304 },
1305 {
1306 messageId: "unexpectedClosingLinebreak",
1307 type: "ArrayExpression",
1308 line: 2,
1309 column: 1
1310 }
1311 ]
1312 },
1313 {
1314 code: "var foo = [\n1\n];",
1315 output: "var foo = [1];",
1316 options: [{ minItems: null }],
1317 errors: [
1318 {
1319 messageId: "unexpectedOpeningLinebreak",
1320 type: "ArrayExpression",
1321 line: 1,
1322 column: 11
1323 },
1324 {
1325 messageId: "unexpectedClosingLinebreak",
1326 type: "ArrayExpression",
1327 line: 3,
1328 column: 1
1329 }
1330 ]
1331 },
1332 {
1333 code: "var foo = [\n1, 2\n];",
1334 output: "var foo = [1, 2];",
1335 options: [{ minItems: null }],
1336 errors: [
1337 {
1338 messageId: "unexpectedOpeningLinebreak",
1339 type: "ArrayExpression",
1340 line: 1,
1341 column: 11
1342 },
1343 {
1344 messageId: "unexpectedClosingLinebreak",
1345 type: "ArrayExpression",
1346 line: 3,
1347 column: 1
1348 }
1349 ]
1350 },
1351 {
1352 code: "var foo = [\n1,\n2\n];",
1353 output: "var foo = [1,\n2];",
1354 options: [{ minItems: null }],
1355 errors: [
1356 {
1357 messageId: "unexpectedOpeningLinebreak",
1358 type: "ArrayExpression",
1359 line: 1,
1360 column: 11
1361 },
1362 {
1363 messageId: "unexpectedClosingLinebreak",
1364 type: "ArrayExpression",
1365 line: 4,
1366 column: 1
1367 }
1368 ]
1369 },
1370 {
1371 code: "var foo = [\nfunction foo() {\ndosomething();\n}\n];",
1372 output: "var foo = [function foo() {\ndosomething();\n}];",
1373 options: [{ minItems: null }],
1374 errors: [
1375 {
1376 messageId: "unexpectedOpeningLinebreak",
1377 type: "ArrayExpression",
1378 line: 1,
1379 column: 11
1380 },
1381 {
1382 messageId: "unexpectedClosingLinebreak",
1383 type: "ArrayExpression",
1384 line: 5,
1385 column: 1
1386 }
1387 ]
1388 },
1389
1390 // { multiline: true, minItems: null }
1391 {
1392 code: "var foo = [\n];",
1393 output: "var foo = [];",
1394 options: [{ multiline: true, minItems: null }],
1395 errors: [
1396 {
1397 messageId: "unexpectedOpeningLinebreak",
1398 type: "ArrayExpression",
1399 line: 1,
1400 column: 11
1401 },
1402 {
1403 messageId: "unexpectedClosingLinebreak",
1404 type: "ArrayExpression",
1405 line: 2,
1406 column: 1
1407 }
1408 ]
1409 },
1410 {
1411 code: "var foo = [\n1\n];",
1412 output: "var foo = [1];",
1413 options: [{ multiline: true, minItems: null }],
1414 errors: [
1415 {
1416 messageId: "unexpectedOpeningLinebreak",
1417 type: "ArrayExpression",
1418 line: 1,
1419 column: 11
1420 },
1421 {
1422 messageId: "unexpectedClosingLinebreak",
1423 type: "ArrayExpression",
1424 line: 3,
1425 column: 1
1426 }
1427 ]
1428 },
1429 {
1430 code: "var foo = [\n1, 2\n];",
1431 output: "var foo = [1, 2];",
1432 options: [{ multiline: true, minItems: null }],
1433 errors: [
1434 {
1435 messageId: "unexpectedOpeningLinebreak",
1436 type: "ArrayExpression",
1437 line: 1,
1438 column: 11
1439 },
1440 {
1441 messageId: "unexpectedClosingLinebreak",
1442 type: "ArrayExpression",
1443 line: 3,
1444 column: 1
1445 }
1446 ]
1447 },
1448 {
1449 code: "var foo = [1,\n2];",
1450 output: "var foo = [\n1,\n2\n];",
1451 options: [{ multiline: true, minItems: null }],
1452 errors: [
1453 {
1454 messageId: "missingOpeningLinebreak",
1455 type: "ArrayExpression",
1456 line: 1,
1457 column: 11
1458 },
1459 {
1460 messageId: "missingClosingLinebreak",
1461 type: "ArrayExpression",
1462 line: 2,
1463 column: 2
1464 }
1465 ]
1466 },
1467 {
1468 code: "var foo = [function foo() {\ndosomething();\n}];",
1469 output: "var foo = [\nfunction foo() {\ndosomething();\n}\n];",
1470 options: [{ multiline: true, minItems: null }],
1471 errors: [
1472 {
1473 messageId: "missingOpeningLinebreak",
1474 type: "ArrayExpression",
1475 line: 1,
1476 column: 11
1477 },
1478 {
1479 messageId: "missingClosingLinebreak",
1480 type: "ArrayExpression",
1481 line: 3,
1482 column: 2
1483 }
1484 ]
1485 },
1486
1487 // { multiline: true, minItems: 2 }
1488 {
1489 code: "var foo = [\n];",
1490 output: "var foo = [];",
1491 options: [{ multiline: true, minItems: 2 }],
1492 errors: [
1493 {
1494 messageId: "unexpectedOpeningLinebreak",
1495 type: "ArrayExpression",
1496 line: 1,
1497 column: 11
1498 },
1499 {
1500 messageId: "unexpectedClosingLinebreak",
1501 type: "ArrayExpression",
1502 line: 2,
1503 column: 1
1504 }
1505 ]
1506 },
1507 {
1508 code: "var foo = [\n1\n];",
1509 output: "var foo = [1];",
1510 options: [{ multiline: true, minItems: 2 }],
1511 errors: [
1512 {
1513 messageId: "unexpectedOpeningLinebreak",
1514 type: "ArrayExpression",
1515 line: 1,
1516 column: 11
1517 },
1518 {
1519 messageId: "unexpectedClosingLinebreak",
1520 type: "ArrayExpression",
1521 line: 3,
1522 column: 1
1523 }
1524 ]
1525 },
1526 {
1527 code: "var foo = [1, 2];",
1528 output: "var foo = [\n1, 2\n];",
1529 options: [{ multiline: true, minItems: 2 }],
1530 errors: [
1531 {
1532 messageId: "missingOpeningLinebreak",
1533 type: "ArrayExpression",
1534 line: 1,
1535 column: 11
1536 },
1537 {
1538 messageId: "missingClosingLinebreak",
1539 type: "ArrayExpression",
1540 line: 1,
1541 column: 16
1542 }
1543 ]
1544 },
1545 {
1546 code: "var foo = [1,\n2];",
1547 output: "var foo = [\n1,\n2\n];",
1548 options: [{ multiline: true, minItems: 2 }],
1549 errors: [
1550 {
1551 messageId: "missingOpeningLinebreak",
1552 type: "ArrayExpression",
1553 line: 1,
1554 column: 11
1555 },
1556 {
1557 messageId: "missingClosingLinebreak",
1558 type: "ArrayExpression",
1559 line: 2,
1560 column: 2
1561 }
1562 ]
1563 },
1564 {
1565 code: "var foo = [function foo() {\ndosomething();\n}];",
1566 output: "var foo = [\nfunction foo() {\ndosomething();\n}\n];",
1567 options: [{ multiline: true, minItems: 2 }],
1568 errors: [
1569 {
1570 messageId: "missingOpeningLinebreak",
1571 type: "ArrayExpression",
1572 line: 1,
1573 column: 11
1574 },
1575 {
1576 messageId: "missingClosingLinebreak",
1577 type: "ArrayExpression",
1578 line: 3,
1579 column: 2
1580 }
1581 ]
1582 },
1583
1584 /*
1585 * extra test cases
1586 * "always"
1587 */
1588 {
1589 code: "var foo = [\n1, 2];",
1590 output: "var foo = [\n1, 2\n];",
1591 options: ["always"],
1592 errors: [
1593 {
1594 messageId: "missingClosingLinebreak",
1595 type: "ArrayExpression",
1596 line: 2,
1597 column: 5
1598 }
1599 ]
1600 },
1601 {
1602 code: "var foo = [\t1, 2];",
1603 output: "var foo = [\n\t1, 2\n];",
1604 options: ["always"],
1605 errors: [
1606 {
1607 messageId: "missingOpeningLinebreak",
1608 type: "ArrayExpression",
1609 line: 1,
1610 column: 11
1611 },
1612 {
1613 messageId: "missingClosingLinebreak",
1614 type: "ArrayExpression",
1615 line: 1,
1616 column: 17
1617 }
1618 ]
1619 },
1620 {
1621 code: "var foo = [1,\n2\n];",
1622 output: "var foo = [\n1,\n2\n];",
1623 options: ["always"],
1624 errors: [
1625 {
1626 messageId: "missingOpeningLinebreak",
1627 type: "ArrayExpression",
1628 line: 1,
1629 column: 11
1630 }
1631 ]
1632 },
1633
1634 // { multiline: false }
1635 {
1636 code: "var foo = [\n];",
1637 output: "var foo = [];",
1638 options: [{ multiline: false }],
1639 errors: [
1640 {
1641 messageId: "unexpectedOpeningLinebreak",
1642 type: "ArrayExpression",
1643 line: 1,
1644 column: 11
1645 },
1646 {
1647 messageId: "unexpectedClosingLinebreak",
1648 type: "ArrayExpression",
1649 line: 2,
1650 column: 1
1651 }
1652 ]
1653 },
1654 {
1655 code: "var foo = [\n1\n];",
1656 output: "var foo = [1];",
1657 options: [{ multiline: false }],
1658 errors: [
1659 {
1660 messageId: "unexpectedOpeningLinebreak",
1661 type: "ArrayExpression",
1662 line: 1,
1663 column: 11
1664 },
1665 {
1666 messageId: "unexpectedClosingLinebreak",
1667 type: "ArrayExpression",
1668 line: 3,
1669 column: 1
1670 }
1671 ]
1672 },
1673 {
1674 code: "var foo = [\n1, 2\n];",
1675 output: "var foo = [1, 2];",
1676 options: [{ multiline: false }],
1677 errors: [
1678 {
1679 messageId: "unexpectedOpeningLinebreak",
1680 type: "ArrayExpression",
1681 line: 1,
1682 column: 11
1683 },
1684 {
1685 messageId: "unexpectedClosingLinebreak",
1686 type: "ArrayExpression",
1687 line: 3,
1688 column: 1
1689 }
1690 ]
1691 },
1692 {
1693 code: "var foo = [\n1,\n2\n];",
1694 output: "var foo = [1,\n2];",
1695 options: [{ multiline: false }],
1696 errors: [
1697 {
1698 messageId: "unexpectedOpeningLinebreak",
1699 type: "ArrayExpression",
1700 line: 1,
1701 column: 11
1702 },
1703 {
1704 messageId: "unexpectedClosingLinebreak",
1705 type: "ArrayExpression",
1706 line: 4,
1707 column: 1
1708 }
1709 ]
1710 },
1711 {
1712 code: "var foo = [\nfunction foo() {\ndosomething();\n}\n];",
1713 output: "var foo = [function foo() {\ndosomething();\n}];",
1714 options: [{ multiline: false }],
1715 errors: [
1716 {
1717 messageId: "unexpectedOpeningLinebreak",
1718 type: "ArrayExpression",
1719 line: 1,
1720 column: 11
1721 },
1722 {
1723 messageId: "unexpectedClosingLinebreak",
1724 type: "ArrayExpression",
1725 line: 5,
1726 column: 1
1727 }
1728 ]
1729 },
1730
1731 /*
1732 * ArrayPattern
1733 * "always"
1734 */
1735 {
1736 code: "var [] = foo;",
1737 output: "var [\n] = foo;",
1738 options: ["always"],
1739 parserOptions: { ecmaVersion: 6 },
1740 errors: [
1741 {
1742 messageId: "missingOpeningLinebreak",
1743 type: "ArrayPattern",
1744 line: 1,
1745 column: 5
1746 },
1747 {
1748 messageId: "missingClosingLinebreak",
1749 type: "ArrayPattern",
1750 line: 1,
1751 column: 6
1752 }
1753 ]
1754 },
1755 {
1756 code: "var [a] = foo;",
1757 output: "var [\na\n] = foo;",
1758 options: ["always"],
1759 parserOptions: { ecmaVersion: 6 },
1760 errors: [
1761 {
1762 messageId: "missingOpeningLinebreak",
1763 type: "ArrayPattern",
1764 line: 1,
1765 column: 5
1766 },
1767 {
1768 messageId: "missingClosingLinebreak",
1769 type: "ArrayPattern",
1770 line: 1,
1771 column: 7
1772 }
1773 ]
1774 },
1775 {
1776 code: "var [ // any comment\na] = foo;",
1777 output: "var [ // any comment\na\n] = foo;",
1778 options: ["always"],
1779 parserOptions: { ecmaVersion: 6 },
1780 errors: [
1781 {
1782 messageId: "missingClosingLinebreak",
1783 type: "ArrayPattern",
1784 line: 2,
1785 column: 2
1786 }
1787 ]
1788 },
1789 {
1790 code: "var [ /* any comment */\na] = foo;",
1791 output: "var [ /* any comment */\na\n] = foo;",
1792 options: ["always"],
1793 parserOptions: { ecmaVersion: 6 },
1794 errors: [
1795 {
1796 messageId: "missingClosingLinebreak",
1797 type: "ArrayPattern",
1798 line: 2,
1799 column: 2
1800 }
1801 ]
1802 },
1803 {
1804 code: "var [a, b] = foo;",
1805 output: "var [\na, b\n] = foo;",
1806 options: ["always"],
1807 parserOptions: { ecmaVersion: 6 },
1808 errors: [
1809 {
1810 messageId: "missingOpeningLinebreak",
1811 type: "ArrayPattern",
1812 line: 1,
1813 column: 5
1814 },
1815 {
1816 messageId: "missingClosingLinebreak",
1817 type: "ArrayPattern",
1818 line: 1,
1819 column: 10
1820 }
1821 ]
1822 },
1823 {
1824 code: "var [a, b // any comment\n] = foo;",
1825 output: "var [\na, b // any comment\n] = foo;",
1826 options: ["always"],
1827 parserOptions: { ecmaVersion: 6 },
1828 errors: [
1829 {
1830 messageId: "missingOpeningLinebreak",
1831 type: "ArrayPattern",
1832 line: 1,
1833 column: 5
1834 }
1835 ]
1836 },
1837 {
1838 code: "var [a, b /* any comment */] = foo;",
1839 output: "var [\na, b /* any comment */\n] = foo;",
1840 options: ["always"],
1841 parserOptions: { ecmaVersion: 6 },
1842 errors: [
1843 {
1844 messageId: "missingOpeningLinebreak",
1845 type: "ArrayPattern",
1846 line: 1,
1847 column: 5
1848 },
1849 {
1850 messageId: "missingClosingLinebreak",
1851 type: "ArrayPattern",
1852 line: 1,
1853 column: 28
1854 }
1855 ]
1856 },
1857 {
1858 code: "var [a,\nb] = foo;",
1859 output: "var [\na,\nb\n] = foo;",
1860 options: ["always"],
1861 parserOptions: { ecmaVersion: 6 },
1862 errors: [
1863 {
1864 messageId: "missingOpeningLinebreak",
1865 type: "ArrayPattern",
1866 line: 1,
1867 column: 5
1868 },
1869 {
1870 messageId: "missingClosingLinebreak",
1871 type: "ArrayPattern",
1872 line: 2,
1873 column: 2
1874 }
1875 ]
1876 },
1877
1878 // "consistent"
1879 {
1880 code: "var [\na] = foo",
1881 output: "var [\na\n] = foo",
1882 options: ["consistent"],
1883 parserOptions: { ecmaVersion: 6 },
1884 errors: [
1885 {
1886 messageId: "missingClosingLinebreak",
1887 type: "ArrayPattern",
1888 line: 2,
1889 column: 2,
1890 endLine: 2,
1891 endColumn: 3
1892 }
1893 ]
1894 },
1895 {
1896 code: "var [a\n] = foo",
1897 output: "var [a] = foo",
1898 options: ["consistent"],
1899 parserOptions: { ecmaVersion: 6 },
1900 errors: [
1901 {
1902 messageId: "unexpectedClosingLinebreak",
1903 type: "ArrayPattern",
1904 line: 2,
1905 column: 1,
1906 endLine: 2,
1907 endColumn: 2
1908 }
1909 ]
1910 },
1911 {
1912 code: "var [//\na] = foo",
1913 output: "var [//\na\n] = foo",
1914 options: ["consistent"],
1915 parserOptions: { ecmaVersion: 6 },
1916 errors: [
1917 {
1918 messageId: "missingClosingLinebreak",
1919 type: "ArrayPattern",
1920 line: 2,
1921 column: 2,
1922 endLine: 2,
1923 endColumn: 3
1924 }
1925 ]
1926 },
1927
1928 // { minItems: 2 }
1929 {
1930 code: "var [\n] = foo;",
1931 output: "var [] = foo;",
1932 options: [{ minItems: 2 }],
1933 parserOptions: { ecmaVersion: 6 },
1934 errors: [
1935 {
1936 messageId: "unexpectedOpeningLinebreak",
1937 type: "ArrayPattern",
1938 line: 1,
1939 column: 5
1940 },
1941 {
1942 messageId: "unexpectedClosingLinebreak",
1943 type: "ArrayPattern",
1944 line: 2,
1945 column: 1
1946 }
1947 ]
1948 },
1949 {
1950 code: "var [\na\n] = foo;",
1951 output: "var [a] = foo;",
1952 options: [{ minItems: 2 }],
1953 parserOptions: { ecmaVersion: 6 },
1954 errors: [
1955 {
1956 messageId: "unexpectedOpeningLinebreak",
1957 type: "ArrayPattern",
1958 line: 1,
1959 column: 5
1960 },
1961 {
1962 messageId: "unexpectedClosingLinebreak",
1963 type: "ArrayPattern",
1964 line: 3,
1965 column: 1
1966 }
1967 ]
1968 },
1969 {
1970 code: "var [a, b] = foo;",
1971 output: "var [\na, b\n] = foo;",
1972 options: [{ minItems: 2 }],
1973 parserOptions: { ecmaVersion: 6 },
1974 errors: [
1975 {
1976 messageId: "missingOpeningLinebreak",
1977 type: "ArrayPattern",
1978 line: 1,
1979 column: 5
1980 },
1981 {
1982 messageId: "missingClosingLinebreak",
1983 type: "ArrayPattern",
1984 line: 1,
1985 column: 10
1986 }
1987 ]
1988 },
1989 {
1990 code: "var [a,\nb] = foo;",
1991 output: "var [\na,\nb\n] = foo;",
1992 options: [{ minItems: 2 }],
1993 parserOptions: { ecmaVersion: 6 },
1994 errors: [
1995 {
1996 messageId: "missingOpeningLinebreak",
1997 type: "ArrayPattern",
1998 line: 1,
1999 column: 5
2000 },
2001 {
2002 messageId: "missingClosingLinebreak",
2003 type: "ArrayPattern",
2004 line: 2,
2005 column: 2
2006 }
2007 ]
2008 }
2009 ]
2010 });