]> git.proxmox.com Git - pve-eslint.git/blame - eslint/tests/lib/rules/array-element-newline.js
upgrade to v7.0.0
[pve-eslint.git] / eslint / tests / lib / rules / array-element-newline.js
CommitLineData
eb39fafa
DC
1/**
2 * @fileoverview Tests for array-element-newline rule.
3 * @author Jan Peer Stöcklmair <https://github.com/JPeer264>
4 */
5
6"use strict";
7
8//------------------------------------------------------------------------------
9// Requirements
10//------------------------------------------------------------------------------
11
12const rule = require("../../../lib/rules/array-element-newline");
13const { RuleTester } = require("../../../lib/rule-tester");
14
15
16//------------------------------------------------------------------------------
17// Tests
18//------------------------------------------------------------------------------
19
20const ruleTester = new RuleTester();
21
22ruleTester.run("array-element-newline", rule, {
23
24 valid: [
25
26 /*
27 * ArrayExpression
28 * "always"
29 */
30 "var foo = [];",
31 "var foo = [1];",
32 "var foo = [1,\n2];",
33 "var foo = [1, // any comment\n2];",
34 "var foo = [// any comment \n1,\n2];",
35 "var foo = [1,\n2 // any comment\n];",
36 "var foo = [1,\n2,\n3];",
37 "var foo = [1\n, (2\n, 3)];",
38 "var foo = [1,\n( 2 ),\n3];",
39 "var foo = [1,\n((((2)))),\n3];",
40 "var foo = [1,\n(\n2\n),\n3];",
41 "var foo = [1,\n(2),\n3];",
42 "var foo = [1,\n(2)\n, 3];",
43 "var foo = [1\n, 2\n, 3];",
44 "var foo = [1,\n2,\n,\n3];",
45 "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\nosomething();\n}\n];",
56c4a2cb
DC
46 "var foo = [1,\n[2,\n3],\n4]",
47 "var foo = [[],\n[\n[]]]",
eb39fafa
DC
48
49 { code: "var foo = [];", options: ["always"] },
50 { code: "var foo = [1];", options: ["always"] },
51 { code: "var foo = [1,\n2];", options: ["always"] },
52 { code: "var foo = [1,\n(2)];", options: ["always"] },
53 { code: "var foo = [1\n, (2)];", options: ["always"] },
54 { code: "var foo = [1, // any comment\n2];", options: ["always"] },
55 { code: "var foo = [// any comment \n1,\n2];", options: ["always"] },
56 { code: "var foo = [1,\n2 // any comment\n];", options: ["always"] },
57 { code: "var foo = [1,\n2,\n3];", options: ["always"] },
58 { code: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];", options: ["always"] },
56c4a2cb 59 { code: "var foo = [\n[1,\n2],\n3,\n[\n4]]", options: ["always"] },
eb39fafa
DC
60
61 // "never"
62 { code: "var foo = [];", options: ["never"] },
63 { code: "var foo = [1];", options: ["never"] },
64 { code: "var foo = [1, 2];", options: ["never"] },
65 { code: "var foo = [1, /* any comment */ 2];", options: ["never"] },
66 { code: "var foo = [/* any comment */ 1, 2];", options: ["never"] },
67 { code: "var foo = /* any comment */ [1, 2];", options: ["never"] },
68 { code: "var foo = [1, 2, 3];", options: ["never"] },
69 { code: "var foo = [1, (\n2\n), 3];", options: ["never"] },
70 { code: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];", options: ["never"] },
56c4a2cb
DC
71 { code: "var foo = [\n[1,2],3,[4]\n]", options: ["never"] },
72 { code: "var foo = [[1,2\n],3,[4\n]\n]", options: ["never"] },
eb39fafa
DC
73
74 // "consistent"
75 { code: "var foo = [];", options: ["consistent"] },
76 { code: "var foo = [1];", options: ["consistent"] },
77 { code: "var foo = [1, 2];", options: ["consistent"] },
78 { code: "var foo = [1,\n2];", options: ["consistent"] },
79 { code: "var foo = [1, 2, 3];", options: ["consistent"] },
80 { code: "var foo = [1,\n2,\n3];", options: ["consistent"] },
81 { code: "var foo = [1,\n2,\n,\n3];", options: ["consistent"] },
82 { code: "var foo = [1, // any comment\n2];", options: ["consistent"] },
83 { code: "var foo = [/* any comment */ 1, 2];", options: ["consistent"] },
84 { code: "var foo = [1, (\n2\n), 3];", options: ["consistent"] },
85 { code: "var foo = [1,\n(2)\n, 3];", options: ["consistent"] },
86 { code: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];", options: ["consistent"] },
87 { code: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];", options: ["consistent"] },
88 { code: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}];", options: ["consistent"] },
89 { code: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}, function bar() {\ndosomething();\n}];", options: ["consistent"] },
56c4a2cb
DC
90 { code: "var foo = [1,\n[\n2,3,\n]\n];", options: ["consistent"] },
91 { code: "var foo = [\n1,\n[2\n,3\n,]\n];", options: ["consistent"] },
92 { code: "var foo = [\n1,[2,\n3]];", options: ["consistent"] },
eb39fafa
DC
93
94 // { multiline: true }
95 { code: "var foo = [];", options: [{ multiline: true }] },
96 { code: "var foo = [1];", options: [{ multiline: true }] },
97 { code: "var foo = [1, 2];", options: [{ multiline: true }] },
98 { code: "var foo = [1, 2, 3];", options: [{ multiline: true }] },
99 { code: "var f = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];", options: [{ multiline: true }] },
56c4a2cb 100 { code: "var foo = [\n1,\n2,\n3,\n[\n]\n];", options: [{ multiline: true }] },
eb39fafa
DC
101
102 // { minItems: null }
103 { code: "var foo = [];", options: [{ minItems: null }] },
104 { code: "var foo = [1];", options: [{ minItems: null }] },
105 { code: "var foo = [1, 2];", options: [{ minItems: null }] },
106 { code: "var foo = [1, 2, 3];", options: [{ minItems: null }] },
107 { code: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];", options: [{ minItems: null }] },
56c4a2cb 108 { code: "var foo = [1, 2, 3, [[],1,[[]]]];", options: [{ minItems: null }] },
eb39fafa
DC
109
110 // { minItems: 0 }
111 { code: "var foo = [];", options: [{ minItems: 0 }] },
112 { code: "var foo = [1];", options: [{ minItems: 0 }] },
113 { code: "var foo = [1,\n2];", options: [{ minItems: 0 }] },
114 { code: "var foo = [1,\n2,\n3];", options: [{ minItems: 0 }] },
115 { code: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];", options: [{ minItems: 0 }] },
56c4a2cb 116 { code: "var foo = [\n1, \n2, \n3,\n[\n[],\n[]],\n[]];", options: [{ minItems: 0 }] },
eb39fafa
DC
117
118 // { minItems: 3 }
119 { code: "var foo = [];", options: [{ minItems: 3 }] },
120 { code: "var foo = [1];", options: [{ minItems: 3 }] },
121 { code: "var foo = [1, 2];", options: [{ minItems: 3 }] },
122 { code: "var foo = [1,\n2,\n3];", options: [{ minItems: 3 }] },
123 { code: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];", options: [{ minItems: 3 }] },
56c4a2cb 124 { code: "var foo = [[1,2],[[\n1,\n2,\n3]]];", options: [{ minItems: 3 }] },
eb39fafa
DC
125
126 // { multiline: true, minItems: 3 }
127 { code: "var foo = [];", options: [{ multiline: true, minItems: 3 }] },
128 { code: "var foo = [1];", options: [{ multiline: true, minItems: 3 }] },
129 { code: "var foo = [1, 2];", options: [{ multiline: true, minItems: 3 }] },
130 { code: "var foo = [1, // any comment\n2,\n, 3];", options: [{ multiline: true, minItems: 3 }] },
131 { code: "var foo = [1,\n2,\n// any comment\n, 3];", options: [{ multiline: true, minItems: 3 }] },
132 { code: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];", options: [{ multiline: true, minItems: 3 }] },
133
134 /*
135 * ArrayPattern
136 * "always"
137 */
138 { code: "var [] = foo;", parserOptions: { ecmaVersion: 6 } },
139 { code: "var [a] = foo;", parserOptions: { ecmaVersion: 6 } },
140 { code: "var [a,\nb] = foo;", parserOptions: { ecmaVersion: 6 } },
141 { code: "var [a, // any comment\nb] = foo;", parserOptions: { ecmaVersion: 6 } },
142 { code: "var [// any comment \na,\nb] = foo;", parserOptions: { ecmaVersion: 6 } },
143 { code: "var [a,\nb // any comment\n] = foo;", parserOptions: { ecmaVersion: 6 } },
144 { code: "var [a,\nb,\nb] = foo;", parserOptions: { ecmaVersion: 6 } },
56c4a2cb
DC
145 { code: "var [\na,\n[\nb,\nc]] = foo;", parserOptions: { ecmaVersion: 6 } },
146
147 // "never"
148 { code: "var [a,[b,c]] = foo;", options: ["never"], parserOptions: { ecmaVersion: 6 } },
eb39fafa
DC
149
150 // { minItems: 3 }
151 { code: "var [] = foo;", options: [{ minItems: 3 }], parserOptions: { ecmaVersion: 6 } },
152 { code: "var [a] = foo;", options: [{ minItems: 3 }], parserOptions: { ecmaVersion: 6 } },
153 { code: "var [a, b] = foo;", options: [{ minItems: 3 }], parserOptions: { ecmaVersion: 6 } },
154 { code: "var [a,\nb,\nc] = foo;", options: [{ minItems: 3 }], parserOptions: { ecmaVersion: 6 } },
155
156 /*
157 * ArrayExpression & ArrayPattern
158 * { ArrayExpression: "always", ArrayPattern: "never" }
159 */
160 { code: "var [a, b] = [1,\n2]", options: [{ ArrayExpression: "always", ArrayPattern: "never" }], parserOptions: { ecmaVersion: 6 } }],
161
162 invalid: [
56c4a2cb
DC
163 {
164 code: "var foo = [\n1,[2,\n3]]",
165 output: "var foo = [\n1,\n[2,\n3]]",
166 errors: [
167 {
168 line: 2,
169 column: 3,
170 messageId: "missingLineBreak",
171 endLine: 2,
172 endColumn: 3
173 }
174 ]
175 },
eb39fafa
DC
176
177 /*
178 * ArrayExpression
179 * "always"
180 */
181 {
182 code: "var foo = [1, 2];",
183 output: "var foo = [1,\n2];",
184 options: ["always"],
185 errors: [
186 {
187 messageId: "missingLineBreak",
188 line: 1,
189 column: 14,
190 endLine: 1,
191 endColumn: 15
192 }
193 ]
194 },
195 {
196 code: "var foo = [1, 2, 3];",
197 output: "var foo = [1,\n2,\n3];",
198 options: ["always"],
199 errors: [
200 {
201 messageId: "missingLineBreak",
202 line: 1,
203 column: 14,
204 endLine: 1,
205 endColumn: 15
206 },
207 {
208 messageId: "missingLineBreak",
209 line: 1,
210 column: 17,
211 endLine: 1,
212 endColumn: 18
213 }
214 ]
215 },
216 {
217 code: "var foo = [1,2, 3];",
218 output: "var foo = [1,\n2,\n3];",
219 options: ["always"],
220 errors: [
221 {
222 messageId: "missingLineBreak",
223 line: 1,
224 column: 14,
225 endLine: 1,
226 endColumn: 14
227 },
228 {
229 messageId: "missingLineBreak",
230 line: 1,
231 column: 16,
232 endLine: 1,
233 endColumn: 17
234 }
235 ]
236 },
237 {
238 code: "var foo = [1, (2), 3];",
239 output: "var foo = [1,\n(2),\n3];",
240 options: ["always"],
241 errors: [
242 {
243 messageId: "missingLineBreak",
244 line: 1,
245 column: 14,
246 endLine: 1,
247 endColumn: 15
248 },
249 {
250 messageId: "missingLineBreak",
251 line: 1,
252 column: 19,
253 endLine: 1,
254 endColumn: 20
255 }
256 ]
257 },
258 {
259 code: "var foo = [1,(\n2\n), 3];",
260 output: "var foo = [1,\n(\n2\n),\n3];",
261 options: ["always"],
262 errors: [
263 {
264 messageId: "missingLineBreak",
265 line: 1,
266 column: 14
267 },
268 {
269 messageId: "missingLineBreak",
270 line: 3,
271 column: 3
272 }
273 ]
274 },
275 {
276 code: "var foo = [1, \t (\n2\n),\n3];",
277 output: "var foo = [1,\n(\n2\n),\n3];",
278 options: ["always"],
279 errors: [
280 {
281 messageId: "missingLineBreak",
282 line: 1,
283 column: 14
284 }
285 ]
286 },
287 {
288 code: "var foo = [1, ((((2)))), 3];",
289 output: "var foo = [1,\n((((2)))),\n3];",
290 options: ["always"],
291 errors: [
292 {
293 messageId: "missingLineBreak",
294 line: 1,
295 column: 14,
296 endLine: 1,
297 endColumn: 15
298 },
299 {
300 messageId: "missingLineBreak",
301 line: 1,
302 column: 25,
303 endLine: 1,
304 endColumn: 26
305 }
306 ]
307 },
308 {
309 code: "var foo = [1,/* any comment */(2), 3];",
310 output: "var foo = [1,/* any comment */\n(2),\n3];",
311 options: ["always"],
312 errors: [
313 {
314 messageId: "missingLineBreak",
315 line: 1,
316 column: 31,
317 endLine: 1,
318 endColumn: 31
319 },
320 {
321 messageId: "missingLineBreak",
322 line: 1,
323 column: 35,
324 endLine: 1,
325 endColumn: 36
326 }
327 ]
328 },
329 {
330 code: "var foo = [1,( 2), 3];",
331 output: "var foo = [1,\n( 2),\n3];",
332 options: ["always"],
333 errors: [
334 {
335 messageId: "missingLineBreak",
336 line: 1,
337 column: 14,
338 endLine: 1,
339 endColumn: 14
340 },
341 {
342 messageId: "missingLineBreak",
343 line: 1,
344 column: 20,
345 endLine: 1,
346 endColumn: 21
347 }
348 ]
349 },
350 {
351 code: "var foo = [1, [2], 3];",
352 output: "var foo = [1,\n[2],\n3];",
353 options: ["always"],
354 errors: [
355 {
356 messageId: "missingLineBreak",
357 line: 1,
358 column: 14,
359 endLine: 1,
360 endColumn: 15
361 },
362 {
363 messageId: "missingLineBreak",
364 line: 1,
365 column: 19,
366 endLine: 1,
367 endColumn: 20
368 }
369 ]
370 },
371 {
372 code: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];",
373 output: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];",
374 options: ["always"],
375 errors: [
376 {
377 messageId: "missingLineBreak",
378 line: 4,
379 column: 3
380 }
381 ]
382 },
383 {
384 code: "var foo = [\n(function foo() {\ndosomething();\n}), function bar() {\ndosomething();\n}\n];",
385 output: "var foo = [\n(function foo() {\ndosomething();\n}),\nfunction bar() {\ndosomething();\n}\n];",
386 options: ["always"],
387 errors: [
388 {
389 messageId: "missingLineBreak",
390 line: 4,
391 column: 4
392 }
393 ]
394 },
56c4a2cb
DC
395 {
396 code: "var foo = [\n[1,\n2],\n3,[\n4]]",
397 output: "var foo = [\n[1,\n2],\n3,\n[\n4]]",
398 options: ["always"],
399 errors: [
400 {
401 line: 4,
402 column: 3,
403 messageId: "missingLineBreak"
404 }
405 ]
406 },
eb39fafa
DC
407
408 // "never"
409 {
410 code: "var foo = [\n1,\n2\n];",
411 output: "var foo = [\n1, 2\n];",
412 options: ["never"],
413 errors: [
414 {
415 messageId: "unexpectedLineBreak",
416 line: 2,
417 column: 3
418 }
419 ]
420 },
421 {
422 code: "var foo = [\n1\n, 2\n];",
423 output: "var foo = [\n1, 2\n];",
424 options: ["never"],
425 errors: [
426 {
427 messageId: "unexpectedLineBreak",
428 line: 3,
429 column: 2
430 }
431 ]
432 },
433 {
434 code: "var foo = [\n1 // any comment\n, 2\n];",
435 output: null,
436 options: ["never"],
437 errors: [
438 {
439 messageId: "unexpectedLineBreak",
440 line: 3,
441 column: 2
442 }
443 ]
444 },
445 {
446 code: "var foo = [\n1, // any comment\n2\n];",
447 output: null,
448 options: ["never"],
449 errors: [
450 {
451 messageId: "unexpectedLineBreak",
452 line: 2,
453 column: 18
454 }
455 ]
456 },
457 {
458 code: "var foo = [\n1,\n2 // any comment\n];",
459 output: "var foo = [\n1, 2 // any comment\n];",
460 options: ["never"],
461 errors: [
462 {
463 messageId: "unexpectedLineBreak",
464 line: 2,
465 column: 3
466 }
467 ]
468 },
469 {
470 code: "var foo = [\n1,\n2,\n3\n];",
471 output: "var foo = [\n1, 2, 3\n];",
472 options: ["never"],
473 errors: [
474 {
475 messageId: "unexpectedLineBreak",
476 line: 2,
477 column: 3,
478 endLine: 3,
479 endColumn: 1
480 },
481 {
482 messageId: "unexpectedLineBreak",
483 line: 3,
484 column: 3,
485 endLine: 4,
486 endColumn: 1
487 }
488 ]
489 },
490 {
491 code: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];",
492 output: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];",
493 options: ["never"],
494 errors: [
495 {
496 messageId: "unexpectedLineBreak",
497 line: 4,
498 column: 3
499 }
500 ]
501 },
502 {
503 code: "var foo = [\nfunction foo() {\ndosomething();\n}, /* any comment */\nfunction bar() {\ndosomething();\n}\n];",
504 output: null,
505 options: ["never"],
506 errors: [
507 {
508 messageId: "unexpectedLineBreak",
509 line: 4,
510 column: 21
511 }
512 ]
513 },
514
56c4a2cb
DC
515 {
516 code: "var foo = [[1,\n2\n],3,[4\n]\n]",
517 output: "var foo = [[1, 2\n],3,[4\n]\n]",
518 options: ["never"],
519 errors: [
520 {
521 line: 1,
522 column: 15,
523 messageId: "unexpectedLineBreak"
524 }
525 ]
526 },
527
eb39fafa
DC
528 // "consistent"
529 {
530 code: "var foo = [1,\n2, 3];",
531 output: "var foo = [1,\n2,\n3];",
532 options: ["consistent"],
533 errors: [
534 {
535 messageId: "missingLineBreak",
536 line: 2,
537 column: 3,
538 endLine: 2,
539 endColumn: 4
540 }
541 ]
542 },
543 {
544 code: "var foo = [1, 2,\n3];",
545 output: "var foo = [1,\n2,\n3];",
546 options: ["consistent"],
547 errors: [
548 {
549 messageId: "missingLineBreak",
550 line: 1,
551 column: 14,
552 endLine: 1,
553 endColumn: 15
554 }
555 ]
556 },
557 {
558 code: "var foo = [1,\n(\n2), 3];",
559 output: "var foo = [1,\n(\n2),\n3];",
560 options: ["consistent"],
561 errors: [
562 {
563 messageId: "missingLineBreak",
564 line: 3,
565 column: 4,
566 endLine: 3,
567 endColumn: 5
568 }
569 ]
570 },
571 {
572 code: "var foo = [1, \t (\n2\n),\n3];",
573 output: "var foo = [1,\n(\n2\n),\n3];",
574 options: ["consistent"],
575 errors: [
576 {
577 messageId: "missingLineBreak",
578 line: 1,
579 column: 14,
580 endLine: 1,
581 endColumn: 29
582 }
583 ]
584 },
585 {
586 code: "var foo = [1, /* any comment */(2),\n3];",
587 output: "var foo = [1, /* any comment */\n(2),\n3];",
588 options: ["consistent"],
589 errors: [
590 {
591 messageId: "missingLineBreak",
592 line: 1,
593 column: 32
594 }
595 ]
596 },
597 {
598 code: "var foo = [\nfunction foo() {\ndosomething();\n},function bar() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}];",
599 output: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}];",
600 options: ["consistent"],
601 errors: [
602 {
603 messageId: "missingLineBreak",
604 line: 4,
605 column: 3
606 }
607 ]
608 },
56c4a2cb
DC
609 {
610 code: "var foo = [\n1,[2,3,\n[]],\n[]\n];",
611 output: "var foo = [\n1,\n[2,\n3,\n[]],\n[]\n];",
612 options: ["consistent"],
613 errors: [
614 {
615 line: 2,
616 column: 3,
617 messageId: "missingLineBreak"
618 },
619 {
620 line: 2,
621 column: 6,
622 messageId: "missingLineBreak"
623 }
624 ]
625 },
eb39fafa
DC
626
627 // { multiline: true }
628 {
629 code: "var foo = [1,\n2, 3];",
630 output: "var foo = [1, 2, 3];",
631 options: [{ multiline: true }],
632 errors: [
633 {
634 messageId: "unexpectedLineBreak",
635 line: 1,
636 column: 14
637 }
638 ]
639 },
640 {
641 code: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];",
642 output: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];",
643 options: [{ multiline: true }],
644 errors: [
645 {
646 messageId: "missingLineBreak",
647 line: 4,
648 column: 3
649 }
650 ]
651 },
652 {
653 code: "var foo = [\nfunction foo() {\ndosomething();\n}, /* any comment */ function bar() {\ndosomething();\n}\n];",
654 output: "var foo = [\nfunction foo() {\ndosomething();\n}, /* any comment */\nfunction bar() {\ndosomething();\n}\n];",
655 options: [{ multiline: true }],
656 errors: [
657 {
658 messageId: "missingLineBreak",
659 line: 4,
660 column: 21
661 }
662 ]
663 },
56c4a2cb
DC
664 {
665 code: "var foo = [\n1,2,3,\n[\n]\n];",
666 output: "var foo = [\n1,\n2,\n3,\n[\n]\n];",
667 options: [{ multiline: true }],
668 errors: [
669 {
670 line: 2,
671 column: 3,
672 messageId: "missingLineBreak"
673 },
674 {
675 line: 2,
676 column: 5,
677 messageId: "missingLineBreak"
678 }
679 ]
680 },
eb39fafa
DC
681
682 // { minItems: null }
683 {
684 code: "var foo = [1,\n2];",
685 output: "var foo = [1, 2];",
686 options: [{ minItems: null }],
687 errors: [
688 {
689 messageId: "unexpectedLineBreak",
690 line: 1,
691 column: 14
692 }
693 ]
694 },
695 {
696 code: "var foo = [1,\n2,\n3];",
697 output: "var foo = [1, 2, 3];",
698 options: [{ minItems: null }],
699 errors: [
700 {
701 messageId: "unexpectedLineBreak",
702 line: 1,
703 column: 14
704 },
705 {
706 messageId: "unexpectedLineBreak",
707 line: 2,
708 column: 3
709 }
710 ]
711 },
712 {
713 code: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];",
714 output: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];",
715 options: [{ minItems: null }],
716 errors: [
717 {
718 messageId: "unexpectedLineBreak",
719 line: 4,
720 column: 3
721 }
722 ]
723 },
724
725 // { minItems: 0 }
726 {
727 code: "var foo = [1, 2];",
728 output: "var foo = [1,\n2];",
729 options: [{ minItems: 0 }],
730 errors: [
731 {
732 messageId: "missingLineBreak",
733 line: 1,
734 column: 14
735 }
736 ]
737 },
738 {
739 code: "var foo = [1, 2, 3];",
740 output: "var foo = [1,\n2,\n3];",
741 options: [{ minItems: 0 }],
742 errors: [
743 {
744 messageId: "missingLineBreak",
745 line: 1,
746 column: 14
747 },
748 {
749 messageId: "missingLineBreak",
750 line: 1,
751 column: 17
752 }
753 ]
754 },
755 {
756 code: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];",
757 output: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];",
758 options: [{ minItems: 0 }],
759 errors: [
760 {
761 messageId: "missingLineBreak",
762 line: 4,
763 column: 3
764 }
765 ]
766 },
767
768 // { minItems: 3 }
769 {
770 code: "var foo = [1,\n2];",
771 output: "var foo = [1, 2];",
772 options: [{ minItems: 3 }],
773 errors: [
774 {
775 messageId: "unexpectedLineBreak",
776 line: 1,
777 column: 14
778 }
779 ]
780 },
781 {
782 code: "var foo = [1, 2, 3];",
783 output: "var foo = [1,\n2,\n3];",
784 options: [{ minItems: 3 }],
785 errors: [
786 {
787 messageId: "missingLineBreak",
788 line: 1,
789 column: 14
790 },
791 {
792 messageId: "missingLineBreak",
793 line: 1,
794 column: 17
795 }
796 ]
797 },
798 {
799 code: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];",
800 output: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];",
801 options: [{ minItems: 3 }],
802 errors: [
803 {
804 messageId: "unexpectedLineBreak",
805 line: 4,
806 column: 3
807 }
808 ]
809 },
810
811 // { multiline: true, minItems: 3 }
812 {
813 code: "var foo = [1, 2, 3];",
814 output: "var foo = [1,\n2,\n3];",
815 options: [{ multiline: true, minItems: 3 }],
816 errors: [
817 {
818 messageId: "missingLineBreak",
819 line: 1,
820 column: 14
821 },
822 {
823 messageId: "missingLineBreak",
824 line: 1,
825 column: 17
826 }
827 ]
828 },
829 {
830 code: "var foo = [1,\n2];",
831 output: "var foo = [1, 2];",
832 options: [{ multiline: true, minItems: 3 }],
833 errors: [
834 {
835 messageId: "unexpectedLineBreak",
836 line: 1,
837 column: 14
838 }
839 ]
840 },
841 {
842 code: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];",
843 output: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];",
844 options: [{ multiline: true, minItems: 3 }],
845 errors: [
846 {
847 messageId: "missingLineBreak",
848 line: 4,
849 column: 3
850 }
851 ]
852 },
853
854 /*
855 * ArrayPattern
856 * "always"
857 */
858 {
859 code: "var [a, b] = foo;",
860 output: "var [a,\nb] = foo;",
861 options: ["always"],
862 parserOptions: { ecmaVersion: 6 },
863 errors: [
864 {
865 messageId: "missingLineBreak",
866 line: 1,
867 column: 8
868 }
869 ]
870 },
871 {
872 code: "var [a, b, c] = foo;",
873 output: "var [a,\nb,\nc] = foo;",
874 options: ["always"],
875 parserOptions: { ecmaVersion: 6 },
876 errors: [
877 {
878 messageId: "missingLineBreak",
879 line: 1,
880 column: 8
881 },
882 {
883 messageId: "missingLineBreak",
884 line: 1,
885 column: 11
886 }
887 ]
888 },
889
890 // { minItems: 3 }
891 {
892 code: "var [a,\nb] = foo;",
893 output: "var [a, b] = foo;",
894 options: [{ minItems: 3 }],
895 parserOptions: { ecmaVersion: 6 },
896 errors: [
897 {
898 messageId: "unexpectedLineBreak",
899 line: 1,
900 column: 8
901 }
902 ]
903 },
904 {
905 code: "var [a, b, c] = foo;",
906 output: "var [a,\nb,\nc] = foo;",
907 options: [{ minItems: 3 }],
908 parserOptions: { ecmaVersion: 6 },
909 errors: [
910 {
911 messageId: "missingLineBreak",
912 line: 1,
913 column: 8
914 },
915 {
916 messageId: "missingLineBreak",
917 line: 1,
918 column: 11
919 }
920 ]
921 },
922
923 /*
924 * ArrayExpression & ArrayPattern
925 * { ArrayExpression: "always", ArrayPattern: "never" }
926 */
927 {
928 code: "var [a,\nb] = [1, 2]",
929 output: "var [a, b] = [1,\n2]",
930 options: [{ ArrayExpression: "always", ArrayPattern: "never" }],
931 parserOptions: { ecmaVersion: 6 },
932 errors: [
933 {
934 messageId: "unexpectedLineBreak",
935 line: 1,
936 column: 8
937 },
938 {
939 messageId: "missingLineBreak",
940 line: 2,
941 column: 9
942 }
943 ]
944 },
945 {
946 code: "var [a, b] = [1, 2]",
947 output: "var [a, b] = [1,\n2]",
948 options: [{ ArrayExpression: "always", ArrayPattern: "never" }],
949 parserOptions: { ecmaVersion: 6 },
950 errors: [
951 {
952 messageId: "missingLineBreak",
953 line: 1,
954 column: 17
955 }
956 ]
957 },
958 {
959 code: "var [a,\nb] = [1,\n2]",
960 output: "var [a, b] = [1,\n2]",
961 options: [{ ArrayExpression: "always", ArrayPattern: "never" }],
962 parserOptions: { ecmaVersion: 6 },
963 errors: [
964 {
965 messageId: "unexpectedLineBreak",
966 line: 1,
967 column: 8
968 }
969 ]
970 }
971 ]
972
973});