]> git.proxmox.com Git - pve-eslint.git/blame - eslint/tests/lib/rules/function-paren-newline.js
import 8.23.1 source
[pve-eslint.git] / eslint / tests / lib / rules / function-paren-newline.js
CommitLineData
eb39fafa
DC
1/**
2 * @fileoverview enforce consistent line breaks inside function parentheses
3 * @author Teddy Katz
4 */
5"use strict";
6
7//------------------------------------------------------------------------------
8// Requirements
9//------------------------------------------------------------------------------
10
11const rule = require("../../../lib/rules/function-paren-newline");
12const { RuleTester } = require("../../../lib/rule-tester");
13
8f9d1d4d
DC
14const { unIndent } = require("../../_utils");
15const fixtureParser = require("../../fixtures/fixture-parser");
16
eb39fafa
DC
17
18//------------------------------------------------------------------------------
19// Tests
20//------------------------------------------------------------------------------
21
22const LEFT_MISSING_ERROR = { messageId: "expectedAfter", type: "Punctuator" };
23const LEFT_UNEXPECTED_ERROR = { messageId: "unexpectedAfter", type: "Punctuator" };
24const RIGHT_MISSING_ERROR = { messageId: "expectedBefore", type: "Punctuator" };
25const RIGHT_UNEXPECTED_ERROR = { messageId: "unexpectedBefore", type: "Punctuator" };
26const EXPECTED_BETWEEN = { messageId: "expectedBetween", type: "Identifier" };
27
28const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
29
30ruleTester.run("function-paren-newline", rule, {
31
32 valid: [
8f9d1d4d 33 "new new Foo();",
eb39fafa
DC
34
35 // multiline option (default)
36 "function baz(foo, bar) {}",
37 "(function(foo, bar) {});",
38 "(function baz(foo, bar) {});",
39 "(foo, bar) => {};",
40 "foo => {};",
41 "baz(foo, bar);",
42 "function baz() {}",
43 `
44 function baz(
45 foo,
46 bar
47 ) {}
48 `,
49 `
50 (function(
51 foo,
52 bar
53 ) {});
54 `,
55 `
56 (function baz(
57 foo,
58 bar
59 ) {});
60 `,
61 `
62 (
63 foo,
64 bar
65 ) => {};
66 `,
67 `
68 baz(
69 foo,
70 bar
71 );
72 `,
73 `
74 baz(\`foo
75 bar\`)
76 `,
77 "new Foo(bar, baz)",
78 "new Foo",
79 "new (Foo)",
80
81 `
82 (foo)
83 (bar)
84 `,
85 `
86 foo.map(value => {
87 return value;
88 })
89 `,
90 {
91 code: "function baz(foo, bar) {}",
92 options: ["multiline"]
93 },
6f036462
TL
94 {
95 code: "async (foo, bar) => {};",
96 parserOptions: { ecmaVersion: 2017 }
97 },
98 {
99 code: `
100 async (
101 foo,
102 bar
103 ) => {};
104 `,
105 parserOptions: { ecmaVersion: 2017 }
106 },
107 {
108 code: "async foo => {};",
109 parserOptions: { ecmaVersion: 2017 }
110 },
eb39fafa
DC
111 {
112 code: "import(source)",
113 parserOptions: { ecmaVersion: 2020 }
114 },
115 {
116 code: "import(source\n + ext)",
117 parserOptions: { ecmaVersion: 2020 }
118 },
119
120 // multiline-arguments
121 {
122 code: "function baz(foo, bar) {}",
123 options: ["multiline-arguments"]
124 },
125 {
126 code: "function baz(foo) {}",
127 options: ["multiline-arguments"]
128 },
129 {
130 code: "(function(foo, bar) {});",
131 options: ["multiline-arguments"]
132 },
133 {
134 code: "(function(foo) {});",
135 options: ["multiline-arguments"]
136 },
137 {
138 code: "(function baz(foo, bar) {});",
139 options: ["multiline-arguments"]
140 },
141 {
142 code: "(function baz(foo) {});",
143 options: ["multiline-arguments"]
144 },
145 {
146 code: "(foo, bar) => {};",
147 options: ["multiline-arguments"]
148 },
149 {
150 code: "foo => {};",
151 options: ["multiline-arguments"]
152 },
153 {
154 code: "baz(foo, bar);",
155 options: ["multiline-arguments"]
156 },
157 {
158 code: "baz(foo);",
159 options: ["multiline-arguments"]
160 },
161 {
162 code: "function baz() {}",
163 options: ["multiline-arguments"]
164 },
165 {
166 code: `
167 function baz(
168 foo,
169 bar
170 ) {}
171 `,
172 options: ["multiline-arguments"]
173 },
174 {
175 code: `
176 function baz(
177 foo
178 ) {}
179 `,
180 options: ["multiline-arguments"]
181 },
182 {
183 code: `
184 (function(
185 foo,
186 bar
187 ) {});
188 `,
189 options: ["multiline-arguments"]
190 },
191 {
192 code: `
193 (function(
194 foo
195 ) {});
196 `,
197 options: ["multiline-arguments"]
198 },
199 {
200 code: `
201 (function baz(
202 foo,
203 bar
204 ) {});
205 `,
206 options: ["multiline-arguments"]
207 },
208 {
209 code: `
210 (function baz(
211 foo
212 ) {});
213 `,
214 options: ["multiline-arguments"]
215 },
216 {
217 code: `
218 (
219 foo,
220 bar
221 ) => {};
222 `,
223 options: ["multiline-arguments"]
224 },
225 {
226 code: `
227 (
228 foo
229 ) => {};
230 `,
231 options: ["multiline-arguments"]
232 },
233 {
234 code: `
235 baz(
236 foo,
237 bar
238 );
239 `,
240 options: ["multiline-arguments"]
241 },
242 {
243 code: `
244 baz(
245 foo
246 );
247 `,
248 options: ["multiline-arguments"]
249 },
250 {
251 code: `
252 baz(\`foo
253 bar\`)
254 `,
255 options: ["multiline-arguments"]
256 },
257 {
258 code: "new Foo(bar, baz)",
259 options: ["multiline-arguments"]
260 },
261 {
262 code: "new Foo(bar)",
263 options: ["multiline-arguments"]
264 },
265 {
266 code: "new Foo",
267 options: ["multiline-arguments"]
268 },
269 {
270 code: "new (Foo)",
271 options: ["multiline-arguments"]
272 },
6f036462
TL
273 {
274 code: "async (foo, bar) => {};",
275 options: ["multiline-arguments"],
276 parserOptions: { ecmaVersion: 2017 }
277 },
278 {
279 code: "async (foo) => {};",
280 options: ["multiline-arguments"],
281 parserOptions: { ecmaVersion: 2017 }
282 },
283 {
284 code: `
285 async (
286 foo
287 ) => {};
288 `,
289 options: ["multiline-arguments"],
290 parserOptions: { ecmaVersion: 2017 }
291 },
292 {
293 code: `
294 async (
295 foo,
296 bar
297 ) => {};
298 `,
299 options: ["multiline-arguments"],
300 parserOptions: { ecmaVersion: 2017 }
301 },
302 {
303 code: "async foo => {};",
304 options: ["multiline-arguments"],
305 parserOptions: { ecmaVersion: 2017 }
306 },
eb39fafa
DC
307 {
308 code: "import(source)",
309 options: ["multiline-arguments"],
310 parserOptions: { ecmaVersion: 2020 }
311 },
312 {
313 code: "import(source\n + ext)",
314 options: ["multiline-arguments"],
315 parserOptions: { ecmaVersion: 2020 }
316 },
317
318 {
319 code: `
320 (foo)
321 (bar)
322 `,
323 options: ["multiline-arguments"]
324 },
325 {
326 code: `
327 foo.map(value => {
328 return value;
329 })
330 `,
331 options: ["multiline-arguments"]
332 },
333
334 // always option
335 {
336 code: `
337 function baz(
338 foo,
339 bar
340 ) {}
341 `,
342 options: ["always"]
343 },
344 {
345 code: `
346 (function(
347 foo,
348 bar
349 ) {});
350 `,
351 options: ["always"]
352 },
353 {
354 code: `
355 (function baz(
356 foo,
357 bar
358 ) {});
359 `,
360 options: ["always"]
361 },
362 {
363 code: `
364 (
365 foo,
366 bar
367 ) => {};
368 `,
369 options: ["always"]
370 },
371 {
372 code: `
373 baz(
374 foo,
375 bar
376 );
377 `,
378 options: ["always"]
379 },
380 {
381 code: `
382 function baz(
383 ) {}
384 `,
385 options: ["always"]
386 },
6f036462
TL
387 {
388 code: `
389 async (
390 foo
391 ) => {};
392 `,
393 options: ["always"],
394 parserOptions: { ecmaVersion: 2017 }
395 },
396 {
397 code: `
398 async (
399 foo,
400 bar
401 ) => {};
402 `,
403 options: ["always"],
404 parserOptions: { ecmaVersion: 2017 }
405 },
406 {
407 code: "async foo => {};",
408 options: ["always"],
409 parserOptions: { ecmaVersion: 2017 }
410 },
eb39fafa
DC
411 {
412 code: "import(\n source\n)",
413 options: ["always"],
414 parserOptions: { ecmaVersion: 2020 }
415 },
416
417 // never option
418 {
419 code: "function baz(foo, bar) {}",
420 options: ["never"]
421 },
422 {
423 code: "(function(foo, bar) {});",
424 options: ["never"]
425 },
426 {
427 code: "(function baz(foo, bar) {});",
428 options: ["never"]
429 },
430 {
431 code: "(foo, bar) => {};",
432 options: ["never"]
433 },
434 {
435 code: "baz(foo, bar);",
436 options: ["never"]
437 },
438 {
439 code: "function baz() {}",
440 options: ["never"]
441 },
6f036462
TL
442 {
443 code: "async (foo, bar) => {};",
444 options: ["never"],
445 parserOptions: { ecmaVersion: 2017 }
446 },
447 {
448 code: "async foo => {};",
449 options: ["never"],
450 parserOptions: { ecmaVersion: 2017 }
451 },
eb39fafa
DC
452 {
453 code: "import(source)",
454 options: ["never"],
455 parserOptions: { ecmaVersion: 2020 }
456 },
457
458 // minItems option
459 {
460 code: "function baz(foo, bar) {}",
461 options: [{ minItems: 3 }]
462 },
463 {
464 code: `
465 function baz(
466 foo, bar, qux
467 ) {}
468 `,
469 options: [{ minItems: 3 }]
470 },
471 {
472 code: `
473 baz(
474 foo, bar, qux
475 );
476 `,
477 options: [{ minItems: 3 }]
478 },
479 {
480 code: "baz(foo, bar);",
481 options: [{ minItems: 3 }]
482 },
6f036462
TL
483 {
484 code: "async (foo, bar) => {};",
485 options: [{ minItems: 3 }],
486 parserOptions: { ecmaVersion: 2017 }
487 },
488 {
489 code: `
490 async (
491 foo,
492 bar,
493 baz
494 ) => {};
495 `,
496 options: [{ minItems: 3 }],
497 parserOptions: { ecmaVersion: 2017 }
498 },
499 {
500 code: "async foo => {};",
501 options: [{ minItems: 3 }],
502 parserOptions: { ecmaVersion: 2017 }
503 },
eb39fafa
DC
504 {
505 code: "import(source)",
506 options: [{ minItems: 3 }],
507 parserOptions: { ecmaVersion: 2020 }
508 },
509 {
510 code: "import(\n source\n)",
511 options: [{ minItems: 1 }],
512 parserOptions: { ecmaVersion: 2020 }
513 },
514
515 // consistent option
516 {
517 code: "foo(bar, baz)",
518 options: ["consistent"]
519 },
520 {
521 code: `
522 foo(bar,
523 baz)
524 `,
525 options: ["consistent"]
526 },
527 {
528 code: `
529 foo(
530 bar, baz
531 )
532 `,
533 options: ["consistent"]
534 },
535 {
536 code: `
537 foo(
538 bar,
539 baz
540 )
541 `,
542 options: ["consistent"]
543 },
6f036462
TL
544 {
545 code: "async (foo, bar) => {};",
546 options: ["consistent"],
547 parserOptions: { ecmaVersion: 2017 }
548 },
549 {
550 code: "async foo => {};",
551 options: ["consistent"],
552 parserOptions: { ecmaVersion: 2017 }
553 },
554 {
555 code: `
556 async (foo,
557 bar) => {};
558 `,
559 options: ["consistent"],
560 parserOptions: { ecmaVersion: 2017 }
561 },
562 {
563 code: `
564 async (
565 foo, bar
566 ) => {};
567 `,
568 options: ["consistent"],
569 parserOptions: { ecmaVersion: 2017 }
570 },
571 {
572 code: `
573 async (
574 foo,
575 bar
576 ) => {};
577 `,
578 options: ["consistent"],
579 parserOptions: { ecmaVersion: 2017 }
580 },
eb39fafa
DC
581 {
582 code: "import(source)",
583 options: ["consistent"],
584 parserOptions: { ecmaVersion: 2020 }
585 },
586 {
587 code: "import(\n source\n)",
588 options: ["consistent"],
589 parserOptions: { ecmaVersion: 2020 }
8f9d1d4d
DC
590 },
591
592 // https://github.com/eslint/eslint/issues/15091#issuecomment-975605821
593 {
594 code: unIndent`
595 const method6 = (
596 abc: number,
597 def: () => void,
598 ): [
599 string,
600 () => void
601 ] => [\`a\${abc}\`, def];
602 method6(3, () => {});
603 `,
604 options: ["multiline"],
605 parser: fixtureParser("function-paren-newline", "arrow-function-return-type")
eb39fafa
DC
606 }
607 ],
608
609 invalid: [
610
611 // multiline option (default)
612 {
613 code: `
614 function baz(foo,
615 bar
616 ) {}
617 `,
618 output: `
619 function baz(\nfoo,
620 bar
621 ) {}
622 `,
623 errors: [LEFT_MISSING_ERROR]
624 },
625 {
626 code: `
627 (function(
628 foo,
629 bar) {})
630 `,
631 output: `
632 (function(
633 foo,
634 bar\n) {})
635 `,
636 errors: [RIGHT_MISSING_ERROR]
637 },
638 {
639 code: `
640 (function baz(foo,
641 bar) {})
642 `,
643 output: `
644 (function baz(\nfoo,
645 bar\n) {})
646 `,
647 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
648 },
649 {
650 code: `
651 baz(
652 foo, bar);
653 `,
654 output: `
655 baz(foo, bar);
656 `,
657 errors: [LEFT_UNEXPECTED_ERROR]
658 },
659 {
660 code: `
661 (foo, bar
662 ) => {};
663 `,
664 output: `
665 (foo, bar) => {};
666 `,
667 errors: [RIGHT_UNEXPECTED_ERROR]
668 },
669 {
670 code: `
671 function baz(
672 foo, bar
673 ) {}
674 `,
675 output: `
676 function baz(foo, bar) {}
677 `,
678 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
679 },
680 {
681 code: `
682 function baz(
683 foo =
684 1
685 ) {}
686 `,
687 output: `
688 function baz(foo =
689 1) {}
690 `,
691 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
692 },
693 {
694 code: `
695 function baz(
696 ) {}
697 `,
698 output: `
699 function baz() {}
700 `,
701 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
702 },
703 {
704 code: `
705 new Foo(bar,
706 baz);
707 `,
708 output: `
709 new Foo(\nbar,
710 baz\n);
711 `,
712 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
713 },
714 {
715 code: `
716 function baz(/* not fixed due to comment */
717 foo) {}
718 `,
719 output: null,
720 errors: [LEFT_UNEXPECTED_ERROR]
721 },
722 {
723 code: `
724 function baz(foo
725 /* not fixed due to comment */) {}
726 `,
727 output: null,
728 errors: [RIGHT_UNEXPECTED_ERROR]
729 },
6f036462
TL
730 {
731 code: `
732 async (
733 foo, bar
734 ) => {};
735 `,
736 output: `
737 async (foo, bar) => {};
738 `,
739 parserOptions: { ecmaVersion: 2017 },
740 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
741 },
742 {
743 code: `
744 async (foo, bar
745 ) => {};
746 `,
747 output: `
748 async (foo, bar) => {};
749 `,
750 parserOptions: { ecmaVersion: 2017 },
751 errors: [RIGHT_UNEXPECTED_ERROR]
752 },
753 {
754 code: `
755 async (foo,
756 bar) => {};
757 `,
758 output: `
759 async (\nfoo,
760 bar\n) => {};
761 `,
762 parserOptions: { ecmaVersion: 2017 },
763 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
764 },
765 {
766 code: `
767 async (
768 foo,
769 bar) => {};
770 `,
771 output: `
772 async (
773 foo,
774 bar\n) => {};
775 `,
776 parserOptions: { ecmaVersion: 2017 },
777 errors: [RIGHT_MISSING_ERROR]
778 },
eb39fafa
DC
779 {
780 code: "import(\n source\n)",
781 output: "import(source)",
782 parserOptions: { ecmaVersion: 2020 },
783 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
784 },
785
786 // multiline-arguments
787 {
788 code: `
789 function baz(foo,
790 bar
791 ) {}
792 `,
793 output: `
794 function baz(\nfoo,
795 bar
796 ) {}
797 `,
798 options: ["multiline-arguments"],
799 errors: [LEFT_MISSING_ERROR]
800 },
801 {
802 code: `
803 (function(
804 foo,
805 bar) {})
806 `,
807 output: `
808 (function(
809 foo,
810 bar\n) {})
811 `,
812 options: ["multiline-arguments"],
813 errors: [RIGHT_MISSING_ERROR]
814 },
815 {
816 code: `
817 (function baz(foo,
818 bar) {})
819 `,
820 output: `
821 (function baz(\nfoo,
822 bar\n) {})
823 `,
824 options: ["multiline-arguments"],
825 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
826 },
827 {
828 code: `
829 baz(
830 foo, bar);
831 `,
832 output: `
833 baz(foo, bar);
834 `,
835 options: ["multiline-arguments"],
836 errors: [LEFT_UNEXPECTED_ERROR]
837 },
838 {
839 code: `
840 (foo, bar
841 ) => {};
842 `,
843 output: `
844 (foo, bar) => {};
845 `,
846 options: ["multiline-arguments"],
847 errors: [RIGHT_UNEXPECTED_ERROR]
848 },
849 {
850 code: `
851 function baz(
852 foo, bar
853 ) {}
854 `,
855 output: `
856 function baz(foo, bar) {}
857 `,
858 options: ["multiline-arguments"],
859 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
860 },
861 {
862 code: `
863 function baz(
864 ) {}
865 `,
866 output: `
867 function baz() {}
868 `,
869 options: ["multiline-arguments"],
870 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
871 },
872 {
873 code: `
874 new Foo(bar,
875 baz);
876 `,
877 output: `
878 new Foo(\nbar,
879 baz\n);
880 `,
881 options: ["multiline-arguments"],
882 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
883 },
884 {
885 code: `
886 function baz(/* not fixed due to comment */
887 foo) {}
888 `,
889 output: `
890 function baz(/* not fixed due to comment */
891 foo\n) {}
892 `,
893 options: ["multiline-arguments"],
894 errors: [RIGHT_MISSING_ERROR]
895 },
896 {
897 code: `
898 function baz(foo
899 /* not fixed due to comment */) {}
900 `,
901 output: null,
902 options: ["multiline-arguments"],
903 errors: [RIGHT_UNEXPECTED_ERROR]
904 },
905 {
906 code: `
907 function baz(
908 qwe,
909 foo, bar
910 ) {}
911 `,
912 output: `
913 function baz(
914 qwe,
915 foo, \nbar
916 ) {}
917 `,
918 options: ["multiline-arguments"],
919 errors: [EXPECTED_BETWEEN]
920 },
921 {
922 code: `
923 function baz(
924 qwe, foo,
925 bar
926 ) {}
927 `,
928 output: `
929 function baz(
930 qwe, \nfoo,
931 bar
932 ) {}
933 `,
934 options: ["multiline-arguments"],
935 errors: [EXPECTED_BETWEEN]
936 },
937 {
938 code: `
939 function baz(qwe, foo,
940 bar) {}
941 `,
942 output: `
943 function baz(\nqwe, \nfoo,
944 bar\n) {}
945 `,
946 options: ["multiline-arguments"],
947 errors: [LEFT_MISSING_ERROR, EXPECTED_BETWEEN, RIGHT_MISSING_ERROR]
948 },
949 {
950 code: `
951 baz(
952 foo);
953 `,
954 output: `
955 baz(
956 foo\n);
957 `,
958 options: ["multiline-arguments"],
959 errors: [RIGHT_MISSING_ERROR]
960 },
961 {
962 code: `
963 baz(foo
964 );
965 `,
966 output: `
967 baz(foo);
968 `,
969 options: ["multiline-arguments"],
970 errors: [RIGHT_UNEXPECTED_ERROR]
971 },
6f036462
TL
972 {
973 code: `
974 async (foo, bar
975 ) => {};
976 `,
977 output: `
978 async (foo, bar) => {};
979 `,
980 options: ["multiline-arguments"],
981 parserOptions: { ecmaVersion: 2017 },
982 errors: [RIGHT_UNEXPECTED_ERROR]
983 },
984 {
985 code: `
986 async (foo,
987 bar) => {};
988 `,
989 output: `
990 async (\nfoo,
991 bar\n) => {};
992 `,
993 options: ["multiline-arguments"],
994 parserOptions: { ecmaVersion: 2017 },
995 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
996 },
997 {
998 code: `
999 async (
1000 foo,
1001 bar) => {};
1002 `,
1003 output: `
1004 async (
1005 foo,
1006 bar\n) => {};
1007 `,
1008 options: ["multiline-arguments"],
1009 parserOptions: { ecmaVersion: 2017 },
1010 errors: [RIGHT_MISSING_ERROR]
1011 },
eb39fafa
DC
1012 {
1013 code: "import(source\n)",
1014 output: "import(source)",
1015 options: ["multiline-arguments"],
1016 parserOptions: { ecmaVersion: 2020 },
1017 errors: [RIGHT_UNEXPECTED_ERROR]
1018 },
1019 {
1020 code: "import(\n source)",
1021 output: "import(\n source\n)",
1022 options: ["multiline-arguments"],
1023 parserOptions: { ecmaVersion: 2020 },
1024 errors: [RIGHT_MISSING_ERROR]
1025 },
1026
1027 // always option
1028 {
1029 code: `
1030 function baz(foo,
1031 bar
1032 ) {}
1033 `,
1034 output: `
1035 function baz(\nfoo,
1036 bar
1037 ) {}
1038 `,
1039 options: ["always"],
1040 errors: [LEFT_MISSING_ERROR]
1041 },
1042 {
1043 code: `
1044 (function(
1045 foo,
1046 bar) {})
1047 `,
1048 output: `
1049 (function(
1050 foo,
1051 bar\n) {})
1052 `,
1053 options: ["always"],
1054 errors: [RIGHT_MISSING_ERROR]
1055 },
1056 {
1057 code: `
1058 (function baz(foo,
1059 bar) {})
1060 `,
1061 output: `
1062 (function baz(\nfoo,
1063 bar\n) {})
1064 `,
1065 options: ["always"],
1066 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
1067 },
1068 {
1069 code: "function baz(foo, bar) {}",
1070 output: "function baz(\nfoo, bar\n) {}",
1071 options: ["always"],
1072 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
1073 },
1074 {
1075 code: "(function(foo, bar) {});",
1076 output: "(function(\nfoo, bar\n) {});",
1077 options: ["always"],
1078 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
1079 },
1080 {
1081 code: "(function baz(foo, bar) {});",
1082 output: "(function baz(\nfoo, bar\n) {});",
1083 options: ["always"],
1084 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
1085 },
1086 {
1087 code: "(foo, bar) => {};",
1088 output: "(\nfoo, bar\n) => {};",
1089 options: ["always"],
1090 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
1091 },
1092 {
1093 code: "baz(foo, bar);",
1094 output: "baz(\nfoo, bar\n);",
1095 options: ["always"],
1096 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
1097 },
1098 {
1099 code: "function baz() {}",
1100 output: "function baz(\n) {}",
1101 options: ["always"],
1102 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
1103 },
6f036462
TL
1104 {
1105 code: `
1106 async (foo, bar) => {};
1107 `,
1108 output: `
1109 async (\nfoo, bar\n) => {};
1110 `,
1111 options: ["always"],
1112 parserOptions: { ecmaVersion: 2017 },
1113 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
1114 },
1115 {
1116 code: `
1117 async (foo,
1118 bar) => {};
1119 `,
1120 output: `
1121 async (\nfoo,
1122 bar\n) => {};
1123 `,
1124 options: ["always"],
1125 parserOptions: { ecmaVersion: 2017 },
1126 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
1127 },
1128 {
1129 code: `
1130 async (
1131 foo,
1132 bar) => {};
1133 `,
1134 output: `
1135 async (
1136 foo,
1137 bar\n) => {};
1138 `,
1139 options: ["always"],
1140 parserOptions: { ecmaVersion: 2017 },
1141 errors: [RIGHT_MISSING_ERROR]
1142 },
eb39fafa
DC
1143 {
1144 code: "import(source)",
1145 output: "import(\nsource\n)",
1146 options: ["always"],
1147 parserOptions: { ecmaVersion: 2020 },
1148 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
1149 },
1150
1151 // never option
1152 {
1153 code: `
1154 function baz(foo,
1155 bar
1156 ) {}
1157 `,
1158 output: `
1159 function baz(foo,
1160 bar) {}
1161 `,
1162 options: ["never"],
1163 errors: [RIGHT_UNEXPECTED_ERROR]
1164 },
1165 {
1166 code: `
1167 (function(
1168 foo,
1169 bar) {})
1170 `,
1171 output: `
1172 (function(foo,
1173 bar) {})
1174 `,
1175 options: ["never"],
1176 errors: [LEFT_UNEXPECTED_ERROR]
1177 },
8f9d1d4d
DC
1178 {
1179 code: `
1180 new new C()(
1181 );
1182 `,
1183 output: `
1184 new new C()();
1185 `,
1186 options: ["never"],
1187 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
1188 },
1189
eb39fafa
DC
1190 {
1191 code: `
1192 function baz(
1193 foo,
1194 bar
1195 ) {}
1196 `,
1197 output: `
1198 function baz(foo,
1199 bar) {}
1200 `,
1201 options: ["never"],
1202 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
1203 },
1204 {
1205 code: `
1206 (function(
1207 foo,
1208 bar
1209 ) {});
1210 `,
1211 output: `
1212 (function(foo,
1213 bar) {});
1214 `,
1215 options: ["never"],
1216 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
1217 },
1218 {
1219 code: `
1220 (function baz(
1221 foo,
1222 bar
1223 ) {});
1224 `,
1225 output: `
1226 (function baz(foo,
1227 bar) {});
1228 `,
1229 options: ["never"],
1230 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
1231 },
1232 {
1233 code: `
1234 (
1235 foo,
1236 bar
1237 ) => {};
1238 `,
1239 output: `
1240 (foo,
1241 bar) => {};
1242 `,
1243 options: ["never"],
1244 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
1245 },
1246 {
1247 code: `
1248 baz(
1249 foo,
1250 bar
1251 );
1252 `,
1253 output: `
1254 baz(foo,
1255 bar);
1256 `,
1257 options: ["never"],
1258 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
1259 },
1260 {
1261 code: `
1262 function baz(
1263 ) {}
1264 `,
1265 output: `
1266 function baz() {}
1267 `,
1268 options: ["never"],
1269 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
1270 },
6f036462
TL
1271 {
1272 code: `
1273 async (
1274 foo,
1275 bar
1276 ) => {};
1277 `,
1278 output: `
1279 async (foo,
1280 bar) => {};
1281 `,
1282 options: ["never"],
1283 parserOptions: { ecmaVersion: 2017 },
1284 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
1285 },
1286 {
1287 code: `
1288 async (
1289 foo,
1290 bar) => {};
1291 `,
1292 output: `
1293 async (foo,
1294 bar) => {};
1295 `,
1296 options: ["never"],
1297 parserOptions: { ecmaVersion: 2017 },
1298 errors: [LEFT_UNEXPECTED_ERROR]
1299 },
eb39fafa
DC
1300 {
1301 code: "import(\n source\n)",
1302 output: "import(source)",
1303 options: ["never"],
1304 parserOptions: { ecmaVersion: 2020 },
1305 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
1306 },
1307
1308 // minItems option
1309 {
1310 code: "function baz(foo, bar, qux) {}",
1311 output: "function baz(\nfoo, bar, qux\n) {}",
1312 options: [{ minItems: 3 }],
1313 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
1314 },
1315 {
1316 code: `
1317 function baz(
1318 foo, bar
1319 ) {}
1320 `,
1321 output: `
1322 function baz(foo, bar) {}
1323 `,
1324 options: [{ minItems: 3 }],
1325 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
1326 },
1327 {
1328 code: "baz(foo, bar, qux);",
1329 output: "baz(\nfoo, bar, qux\n);",
1330 options: [{ minItems: 3 }],
1331 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
1332 },
1333 {
1334 code: `
1335 baz(
1336 foo,
1337 bar
1338 );
1339 `,
1340 output: `
1341 baz(foo,
1342 bar);
1343 `,
1344 options: [{ minItems: 3 }],
1345 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
1346 },
6f036462
TL
1347 {
1348 code: `
1349 async (
1350 foo,
1351 bar
1352 ) => {};
1353 `,
1354 output: `
1355 async (foo,
1356 bar) => {};
1357 `,
1358 options: [{ minItems: 3 }],
1359 parserOptions: { ecmaVersion: 2017 },
1360 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
1361 },
1362 {
1363 code: `
1364 async (
1365 foo,
1366 bar) => {};
1367 `,
1368 output: `
1369 async (foo,
1370 bar) => {};
1371 `,
1372 options: [{ minItems: 3 }],
1373 parserOptions: { ecmaVersion: 2017 },
1374 errors: [LEFT_UNEXPECTED_ERROR]
1375 },
1376 {
1377 code: `
1378 async (foo, bar, baz) => {};
1379 `,
1380 output: `
1381 async (\nfoo, bar, baz\n) => {};
1382 `,
1383 options: [{ minItems: 3 }],
1384 parserOptions: { ecmaVersion: 2017 },
1385 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
1386 },
eb39fafa
DC
1387 {
1388 code: "import(\n source\n)",
1389 output: "import(source)",
1390 options: [{ minItems: 3 }],
1391 parserOptions: { ecmaVersion: 2020 },
1392 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
1393 },
1394 {
1395 code: "import(source)",
1396 output: "import(\nsource\n)",
1397 options: [{ minItems: 1 }],
1398 parserOptions: { ecmaVersion: 2020 },
1399 errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR]
1400 },
1401
1402 // consistent option
1403 {
1404 code: `
1405 foo(
1406 bar,
1407 baz)
1408 `,
1409 output: `
1410 foo(
1411 bar,
1412 baz\n)
1413 `,
1414 options: ["consistent"],
1415 errors: [RIGHT_MISSING_ERROR]
1416 },
1417 {
1418 code: `
1419 foo(bar,
1420 baz
1421 )
1422 `,
1423 output: `
1424 foo(bar,
1425 baz)
1426 `,
1427 options: ["consistent"],
1428 errors: [RIGHT_UNEXPECTED_ERROR]
1429 },
6f036462
TL
1430 {
1431 code: `
1432 async (
1433 foo,
1434 bar) => {};
1435 `,
1436 output: `
1437 async (
1438 foo,
1439 bar\n) => {};
1440 `,
1441 options: ["consistent"],
1442 parserOptions: { ecmaVersion: 2017 },
1443 errors: [RIGHT_MISSING_ERROR]
1444 },
1445 {
1446 code: `
1447 async (foo,
1448 bar
1449 ) => {};
1450 `,
1451 output: `
1452 async (foo,
1453 bar) => {};
1454 `,
1455 options: ["consistent"],
1456 parserOptions: { ecmaVersion: 2017 },
1457 errors: [RIGHT_UNEXPECTED_ERROR]
1458 },
eb39fafa
DC
1459 {
1460 code: "import(source\n)",
1461 output: "import(source)",
1462 options: ["consistent"],
1463 parserOptions: { ecmaVersion: 2020 },
1464 errors: [RIGHT_UNEXPECTED_ERROR]
1465 },
1466 {
1467 code: "import(\n source)",
1468 output: "import(\n source\n)",
1469 options: ["consistent"],
1470 parserOptions: { ecmaVersion: 2020 },
1471 errors: [RIGHT_MISSING_ERROR]
8f9d1d4d
DC
1472 },
1473
1474 // https://github.com/eslint/eslint/issues/15091#issuecomment-975605821
1475 {
1476 code: unIndent`
1477 const method6 = (
1478 abc: number,
1479 def: () => void,
1480 ): [
1481 string,
1482 () => void
1483 ] => [\`a\${abc}\`, def];
1484 method6(3, () => {});
1485 `,
1486 output: unIndent`
1487 const method6 = (abc: number,
1488 def: () => void,): [
1489 string,
1490 () => void
1491 ] => [\`a\${abc}\`, def];
1492 method6(3, () => {});
1493 `,
1494 options: ["never"],
1495 parser: fixtureParser("function-paren-newline", "arrow-function-return-type"),
1496 errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR]
eb39fafa
DC
1497 }
1498 ]
1499});