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