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