]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/indent.js
buildsys: change upload dist to bullseye
[pve-eslint.git] / eslint / tests / lib / rules / indent.js
1 /**
2 * @fileoverview This option sets a specific tab width for your code
3 * @author Dmitriy Shekhovtsov
4 * @author Gyandeep Singh
5 */
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/indent"),
13 { RuleTester } = require("../../../lib/rule-tester");
14 const fs = require("fs");
15 const path = require("path");
16
17 //------------------------------------------------------------------------------
18 // Tests
19 //------------------------------------------------------------------------------
20
21 const fixture = fs.readFileSync(path.join(__dirname, "../../fixtures/rules/indent/indent-invalid-fixture-1.js"), "utf8");
22 const fixedFixture = fs.readFileSync(path.join(__dirname, "../../fixtures/rules/indent/indent-valid-fixture-1.js"), "utf8");
23 const parser = require("../../fixtures/fixture-parser");
24 const { unIndent } = require("../../_utils");
25
26
27 /**
28 * Create error message object for failure cases with a single 'found' indentation type
29 * @param {string} providedIndentType indent type of string or tab
30 * @param {Array} providedErrors error info
31 * @returns {Object} returns the error messages collection
32 * @private
33 */
34 function expectedErrors(providedIndentType, providedErrors) {
35 let indentType;
36 let errors;
37
38 if (Array.isArray(providedIndentType)) {
39 errors = Array.isArray(providedIndentType[0]) ? providedIndentType : [providedIndentType];
40 indentType = "space";
41 } else {
42 errors = Array.isArray(providedErrors[0]) ? providedErrors : [providedErrors];
43 indentType = providedIndentType;
44 }
45
46 return errors.map(err => ({
47 messageId: "wrongIndentation",
48 data: {
49 expected: typeof err[1] === "string" && typeof err[2] === "string"
50 ? err[1]
51 : `${err[1]} ${indentType}${err[1] === 1 ? "" : "s"}`,
52 actual: err[2]
53 },
54 type: err[3],
55 line: err[0]
56 }));
57 }
58
59 const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } });
60
61 ruleTester.run("indent", rule, {
62 valid: [
63 {
64 code: unIndent`
65 bridge.callHandler(
66 'getAppVersion', 'test23', function(responseData) {
67 window.ah.mobileAppVersion = responseData;
68 }
69 );
70 `,
71 options: [2]
72 },
73 {
74 code: unIndent`
75 bridge.callHandler(
76 'getAppVersion', 'test23', function(responseData) {
77 window.ah.mobileAppVersion = responseData;
78 });
79 `,
80 options: [2]
81 },
82 {
83 code: unIndent`
84 bridge.callHandler(
85 'getAppVersion',
86 null,
87 function responseCallback(responseData) {
88 window.ah.mobileAppVersion = responseData;
89 }
90 );
91 `,
92 options: [2]
93 },
94 {
95 code: unIndent`
96 bridge.callHandler(
97 'getAppVersion',
98 null,
99 function responseCallback(responseData) {
100 window.ah.mobileAppVersion = responseData;
101 });
102 `,
103 options: [2]
104 },
105 {
106 code: unIndent`
107 function doStuff(keys) {
108 _.forEach(
109 keys,
110 key => {
111 doSomething(key);
112 }
113 );
114 }
115 `,
116 options: [4]
117 },
118 {
119 code: unIndent`
120 example(
121 function () {
122 console.log('example');
123 }
124 );
125 `,
126 options: [4]
127 },
128 {
129 code: unIndent`
130 let foo = somethingList
131 .filter(x => {
132 return x;
133 })
134 .map(x => {
135 return 100 * x;
136 });
137 `,
138 options: [4]
139 },
140 {
141 code: unIndent`
142 var x = 0 &&
143 {
144 a: 1,
145 b: 2
146 };
147 `,
148 options: [4]
149 },
150 {
151 code: unIndent`
152 var x = 0 &&
153 \t{
154 \t\ta: 1,
155 \t\tb: 2
156 \t};
157 `,
158 options: ["tab"]
159 },
160 {
161 code: unIndent`
162 var x = 0 &&
163 {
164 a: 1,
165 b: 2
166 }||
167 {
168 c: 3,
169 d: 4
170 };
171 `,
172 options: [4]
173 },
174 {
175 code: unIndent`
176 var x = [
177 'a',
178 'b',
179 'c'
180 ];
181 `,
182 options: [4]
183 },
184 {
185 code: unIndent`
186 var x = ['a',
187 'b',
188 'c',
189 ];
190 `,
191 options: [4]
192 },
193 {
194 code: "var x = 0 && 1;",
195 options: [4]
196 },
197 {
198 code: "var x = 0 && { a: 1, b: 2 };",
199 options: [4]
200 },
201 {
202 code: unIndent`
203 var x = 0 &&
204 (
205 1
206 );
207 `,
208 options: [4]
209 },
210 {
211 code: unIndent`
212 require('http').request({hostname: 'localhost',
213 port: 80}, function(res) {
214 res.end();
215 });
216 `,
217 options: [2]
218 },
219 {
220 code: unIndent`
221 function test() {
222 return client.signUp(email, PASSWORD, { preVerified: true })
223 .then(function (result) {
224 // hi
225 })
226 .then(function () {
227 return FunctionalHelpers.clearBrowserState(self, {
228 contentServer: true,
229 contentServer1: true
230 });
231 });
232 }
233 `,
234 options: [2]
235 },
236 {
237 code: unIndent`
238 it('should... some lengthy test description that is forced to be' +
239 'wrapped into two lines since the line length limit is set', () => {
240 expect(true).toBe(true);
241 });
242 `,
243 options: [2]
244 },
245 {
246 code: unIndent`
247 function test() {
248 return client.signUp(email, PASSWORD, { preVerified: true })
249 .then(function (result) {
250 var x = 1;
251 var y = 1;
252 }, function(err){
253 var o = 1 - 2;
254 var y = 1 - 2;
255 return true;
256 })
257 }
258 `,
259 options: [4]
260 },
261 {
262
263 // https://github.com/eslint/eslint/issues/11802
264 code: unIndent`
265 import foo from "foo"
266
267 ;(() => {})()
268 `,
269 options: [4],
270 parserOptions: { ecmaVersion: 6, sourceType: "module" }
271 },
272 {
273 code: unIndent`
274 function test() {
275 return client.signUp(email, PASSWORD, { preVerified: true })
276 .then(function (result) {
277 var x = 1;
278 var y = 1;
279 }, function(err){
280 var o = 1 - 2;
281 var y = 1 - 2;
282 return true;
283 });
284 }
285 `,
286 options: [4, { MemberExpression: 0 }]
287 },
288
289 {
290 code: "// hi",
291 options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
292 },
293 {
294 code: unIndent`
295 var Command = function() {
296 var fileList = [],
297 files = []
298
299 files.concat(fileList)
300 };
301 `,
302 options: [2, { VariableDeclarator: { var: 2, let: 2, const: 3 } }]
303 },
304 {
305 code: " ",
306 options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
307 },
308 {
309 code: unIndent`
310 if(data) {
311 console.log('hi');
312 b = true;};
313 `,
314 options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
315 },
316 {
317 code: unIndent`
318 foo = () => {
319 console.log('hi');
320 return true;};
321 `,
322 options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
323 },
324 {
325 code: unIndent`
326 function test(data) {
327 console.log('hi');
328 return true;};
329 `,
330 options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
331 },
332 {
333 code: unIndent`
334 var test = function(data) {
335 console.log('hi');
336 };
337 `,
338 options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
339 },
340 {
341 code: unIndent`
342 arr.forEach(function(data) {
343 otherdata.forEach(function(zero) {
344 console.log('hi');
345 }) });
346 `,
347 options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
348 },
349 {
350 code: unIndent`
351 a = [
352 ,3
353 ]
354 `,
355 options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
356 },
357 {
358 code: unIndent`
359 [
360 ['gzip', 'gunzip'],
361 ['gzip', 'unzip'],
362 ['deflate', 'inflate'],
363 ['deflateRaw', 'inflateRaw'],
364 ].forEach(function(method) {
365 console.log(method);
366 });
367 `,
368 options: [2, { SwitchCase: 1, VariableDeclarator: 2 }]
369 },
370 {
371 code: unIndent`
372 test(123, {
373 bye: {
374 hi: [1,
375 {
376 b: 2
377 }
378 ]
379 }
380 });
381 `,
382 options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
383 },
384 {
385 code: unIndent`
386 var xyz = 2,
387 lmn = [
388 {
389 a: 1
390 }
391 ];
392 `,
393 options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
394 },
395 {
396 code: unIndent`
397 lmnn = [{
398 a: 1
399 },
400 {
401 b: 2
402 }, {
403 x: 2
404 }];
405 `,
406 options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
407 },
408 unIndent`
409 [{
410 foo: 1
411 }, {
412 foo: 2
413 }, {
414 foo: 3
415 }]
416 `,
417 unIndent`
418 foo([
419 bar
420 ], [
421 baz
422 ], [
423 qux
424 ]);
425 `,
426 {
427 code: unIndent`
428 abc({
429 test: [
430 [
431 c,
432 xyz,
433 2
434 ].join(',')
435 ]
436 });
437 `,
438 options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
439 },
440 {
441 code: unIndent`
442 abc = {
443 test: [
444 [
445 c,
446 xyz,
447 2
448 ]
449 ]
450 };
451 `,
452 options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
453 },
454 {
455 code: unIndent`
456 abc(
457 {
458 a: 1,
459 b: 2
460 }
461 );
462 `,
463 options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
464 },
465 {
466 code: unIndent`
467 abc({
468 a: 1,
469 b: 2
470 });
471 `,
472 options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
473 },
474 {
475 code: unIndent`
476 var abc =
477 [
478 c,
479 xyz,
480 {
481 a: 1,
482 b: 2
483 }
484 ];
485 `,
486 options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
487 },
488 {
489 code: unIndent`
490 var abc = [
491 c,
492 xyz,
493 {
494 a: 1,
495 b: 2
496 }
497 ];
498 `,
499 options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
500 },
501 {
502 code: unIndent`
503 var abc = 5,
504 c = 2,
505 xyz =
506 {
507 a: 1,
508 b: 2
509 };
510 `,
511 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
512 },
513 unIndent`
514 var
515 x = {
516 a: 1,
517 },
518 y = {
519 b: 2
520 }
521 `,
522 unIndent`
523 const
524 x = {
525 a: 1,
526 },
527 y = {
528 b: 2
529 }
530 `,
531 unIndent`
532 let
533 x = {
534 a: 1,
535 },
536 y = {
537 b: 2
538 }
539 `,
540 unIndent`
541 var foo = { a: 1 }, bar = {
542 b: 2
543 };
544 `,
545 unIndent`
546 var foo = { a: 1 }, bar = {
547 b: 2
548 },
549 baz = {
550 c: 3
551 }
552 `,
553 unIndent`
554 const {
555 foo
556 } = 1,
557 bar = 2
558 `,
559 {
560 code: unIndent`
561 var foo = 1,
562 bar =
563 2
564 `,
565 options: [2, { VariableDeclarator: 1 }]
566 },
567 {
568 code: unIndent`
569 var foo = 1,
570 bar
571 = 2
572 `,
573 options: [2, { VariableDeclarator: 1 }]
574 },
575 {
576 code: unIndent`
577 var foo
578 = 1,
579 bar
580 = 2
581 `,
582 options: [2, { VariableDeclarator: 1 }]
583 },
584 {
585 code: unIndent`
586 var foo
587 =
588 1,
589 bar
590 =
591 2
592 `,
593 options: [2, { VariableDeclarator: 1 }]
594 },
595 {
596 code: unIndent`
597 var foo
598 = (1),
599 bar
600 = (2)
601 `,
602 options: [2, { VariableDeclarator: 1 }]
603 },
604 {
605 code: unIndent`
606 let foo = 'foo',
607 bar = bar;
608 const a = 'a',
609 b = 'b';
610 `,
611 options: [2, { VariableDeclarator: "first" }]
612 },
613 {
614 code: unIndent`
615 let foo = 'foo',
616 bar = bar // <-- no semicolon here
617 const a = 'a',
618 b = 'b' // <-- no semicolon here
619 `,
620 options: [2, { VariableDeclarator: "first" }]
621 },
622 {
623 code: unIndent`
624 var foo = 1,
625 bar = 2,
626 baz = 3
627 ;
628 `,
629 options: [2, { VariableDeclarator: { var: 2 } }]
630 },
631 {
632 code: unIndent`
633 var foo = 1,
634 bar = 2,
635 baz = 3
636 ;
637 `,
638 options: [2, { VariableDeclarator: { var: 2 } }]
639 },
640 {
641 code: unIndent`
642 var foo = 'foo',
643 bar = bar;
644 `,
645 options: [2, { VariableDeclarator: { var: "first" } }]
646 },
647 {
648 code: unIndent`
649 var foo = 'foo',
650 bar = 'bar' // <-- no semicolon here
651 `,
652 options: [2, { VariableDeclarator: { var: "first" } }]
653 },
654 {
655 code: unIndent`
656 let foo = 1,
657 bar = 2,
658 baz
659 `,
660 options: [2, { VariableDeclarator: "first" }]
661 },
662 {
663 code: unIndent`
664 let
665 foo
666 `,
667 options: [4, { VariableDeclarator: "first" }]
668 },
669 {
670 code: unIndent`
671 let foo = 1,
672 bar =
673 2
674 `,
675 options: [2, { VariableDeclarator: "first" }]
676 },
677 {
678 code: unIndent`
679 var abc =
680 {
681 a: 1,
682 b: 2
683 };
684 `,
685 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
686 },
687 {
688 code: unIndent`
689 var a = new abc({
690 a: 1,
691 b: 2
692 }),
693 b = 2;
694 `,
695 options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
696 },
697 {
698 code: unIndent`
699 var a = 2,
700 c = {
701 a: 1,
702 b: 2
703 },
704 b = 2;
705 `,
706 options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
707 },
708 {
709 code: unIndent`
710 var x = 2,
711 y = {
712 a: 1,
713 b: 2
714 },
715 b = 2;
716 `,
717 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
718 },
719 {
720 code: unIndent`
721 var e = {
722 a: 1,
723 b: 2
724 },
725 b = 2;
726 `,
727 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
728 },
729 {
730 code: unIndent`
731 var a = {
732 a: 1,
733 b: 2
734 };
735 `,
736 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
737 },
738 {
739 code: unIndent`
740 function test() {
741 if (true ||
742 false){
743 console.log(val);
744 }
745 }
746 `,
747 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
748 },
749 unIndent`
750 var foo = bar ||
751 !(
752 baz
753 );
754 `,
755 unIndent`
756 for (var foo = 1;
757 foo < 10;
758 foo++) {}
759 `,
760 unIndent`
761 for (
762 var foo = 1;
763 foo < 10;
764 foo++
765 ) {}
766 `,
767 {
768 code: unIndent`
769 for (var val in obj)
770 if (true)
771 console.log(val);
772 `,
773 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
774 },
775 {
776 code: unIndent`
777 if(true)
778 if (true)
779 if (true)
780 console.log(val);
781 `,
782 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
783 },
784 {
785 code: unIndent`
786 function hi(){ var a = 1;
787 y++; x++;
788 }
789 `,
790 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
791 },
792 {
793 code: unIndent`
794 for(;length > index; index++)if(NO_HOLES || index in self){
795 x++;
796 }
797 `,
798 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
799 },
800 {
801 code: unIndent`
802 function test(){
803 switch(length){
804 case 1: return function(a){
805 return fn.call(that, a);
806 };
807 }
808 }
809 `,
810 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
811 },
812 {
813 code: unIndent`
814 var geometry = 2,
815 rotate = 2;
816 `,
817 options: [2, { VariableDeclarator: 0 }]
818 },
819 {
820 code: unIndent`
821 var geometry,
822 rotate;
823 `,
824 options: [4, { VariableDeclarator: 1 }]
825 },
826 {
827 code: unIndent`
828 var geometry,
829 \trotate;
830 `,
831 options: ["tab", { VariableDeclarator: 1 }]
832 },
833 {
834 code: unIndent`
835 var geometry,
836 rotate;
837 `,
838 options: [2, { VariableDeclarator: 1 }]
839 },
840 {
841 code: unIndent`
842 var geometry,
843 rotate;
844 `,
845 options: [2, { VariableDeclarator: 2 }]
846 },
847 {
848 code: unIndent`
849 let geometry,
850 rotate;
851 `,
852 options: [2, { VariableDeclarator: 2 }]
853 },
854 {
855 code: unIndent`
856 const geometry = 2,
857 rotate = 3;
858 `,
859 options: [2, { VariableDeclarator: 2 }]
860 },
861 {
862 code: unIndent`
863 var geometry, box, face1, face2, colorT, colorB, sprite, padding, maxWidth,
864 height, rotate;
865 `,
866 options: [2, { SwitchCase: 1 }]
867 },
868 {
869 code: "var geometry, box, face1, face2, colorT, colorB, sprite, padding, maxWidth;",
870 options: [2, { SwitchCase: 1 }]
871 },
872 {
873 code: unIndent`
874 if (1 < 2){
875 //hi sd
876 }
877 `,
878 options: [2]
879 },
880 {
881 code: unIndent`
882 while (1 < 2){
883 //hi sd
884 }
885 `,
886 options: [2]
887 },
888 {
889 code: "while (1 < 2) console.log('hi');",
890 options: [2]
891 },
892
893 {
894 code: unIndent`
895 [a, boop,
896 c].forEach((index) => {
897 index;
898 });
899 `,
900 options: [4]
901 },
902 {
903 code: unIndent`
904 [a, b,
905 c].forEach(function(index){
906 return index;
907 });
908 `,
909 options: [4]
910 },
911 {
912 code: unIndent`
913 [a, b, c].forEach((index) => {
914 index;
915 });
916 `,
917 options: [4]
918 },
919 {
920 code: unIndent`
921 [a, b, c].forEach(function(index){
922 return index;
923 });
924 `,
925 options: [4]
926 },
927 {
928 code: unIndent`
929 (foo)
930 .bar([
931 baz
932 ]);
933 `,
934 options: [4, { MemberExpression: 1 }]
935 },
936 {
937 code: unIndent`
938 switch (x) {
939 case "foo":
940 a();
941 break;
942 case "bar":
943 switch (y) {
944 case "1":
945 break;
946 case "2":
947 a = 6;
948 break;
949 }
950 case "test":
951 break;
952 }
953 `,
954 options: [4, { SwitchCase: 1 }]
955 },
956 {
957 code: unIndent`
958 switch (x) {
959 case "foo":
960 a();
961 break;
962 case "bar":
963 switch (y) {
964 case "1":
965 break;
966 case "2":
967 a = 6;
968 break;
969 }
970 case "test":
971 break;
972 }
973 `,
974 options: [4, { SwitchCase: 2 }]
975 },
976 unIndent`
977 switch (a) {
978 case "foo":
979 a();
980 break;
981 case "bar":
982 switch(x){
983 case '1':
984 break;
985 case '2':
986 a = 6;
987 break;
988 }
989 }
990 `,
991 unIndent`
992 switch (a) {
993 case "foo":
994 a();
995 break;
996 case "bar":
997 if(x){
998 a = 2;
999 }
1000 else{
1001 a = 6;
1002 }
1003 }
1004 `,
1005 unIndent`
1006 switch (a) {
1007 case "foo":
1008 a();
1009 break;
1010 case "bar":
1011 if(x){
1012 a = 2;
1013 }
1014 else
1015 a = 6;
1016 }
1017 `,
1018 unIndent`
1019 switch (a) {
1020 case "foo":
1021 a();
1022 break;
1023 case "bar":
1024 a(); break;
1025 case "baz":
1026 a(); break;
1027 }
1028 `,
1029 unIndent`
1030 switch (0) {
1031 }
1032 `,
1033 unIndent`
1034 function foo() {
1035 var a = "a";
1036 switch(a) {
1037 case "a":
1038 return "A";
1039 case "b":
1040 return "B";
1041 }
1042 }
1043 foo();
1044 `,
1045 {
1046 code: unIndent`
1047 switch(value){
1048 case "1":
1049 case "2":
1050 a();
1051 break;
1052 default:
1053 a();
1054 break;
1055 }
1056 switch(value){
1057 case "1":
1058 a();
1059 break;
1060 case "2":
1061 break;
1062 default:
1063 break;
1064 }
1065 `,
1066 options: [4, { SwitchCase: 1 }]
1067 },
1068 unIndent`
1069 var obj = {foo: 1, bar: 2};
1070 with (obj) {
1071 console.log(foo + bar);
1072 }
1073 `,
1074 unIndent`
1075 if (a) {
1076 (1 + 2 + 3); // no error on this line
1077 }
1078 `,
1079 "switch(value){ default: a(); break; }",
1080 {
1081 code: unIndent`
1082 import {addons} from 'react/addons'
1083 import React from 'react'
1084 `,
1085 options: [2],
1086 parserOptions: { ecmaVersion: 6, sourceType: "module" }
1087 },
1088 {
1089 code: unIndent`
1090 import {
1091 foo,
1092 bar,
1093 baz
1094 } from 'qux';
1095 `,
1096 parserOptions: { ecmaVersion: 6, sourceType: "module" }
1097 },
1098 {
1099 code: unIndent`
1100 var foo = 0, bar = 0; baz = 0;
1101 export {
1102 foo,
1103 bar,
1104 baz
1105 } from 'qux';
1106 `,
1107 parserOptions: { ecmaVersion: 6, sourceType: "module" }
1108 },
1109 {
1110 code: unIndent`
1111 var a = 1,
1112 b = 2,
1113 c = 3;
1114 `,
1115 options: [4]
1116 },
1117 {
1118 code: unIndent`
1119 var a = 1
1120 ,b = 2
1121 ,c = 3;
1122 `,
1123 options: [4]
1124 },
1125 {
1126 code: "while (1 < 2) console.log('hi')",
1127 options: [2]
1128 },
1129 {
1130 code: unIndent`
1131 function salutation () {
1132 switch (1) {
1133 case 0: return console.log('hi')
1134 case 1: return console.log('hey')
1135 }
1136 }
1137 `,
1138 options: [2, { SwitchCase: 1 }]
1139 },
1140 {
1141 code: unIndent`
1142 var items = [
1143 {
1144 foo: 'bar'
1145 }
1146 ];
1147 `,
1148 options: [2, { VariableDeclarator: 2 }]
1149 },
1150 {
1151 code: unIndent`
1152 const a = 1,
1153 b = 2;
1154 const items1 = [
1155 {
1156 foo: 'bar'
1157 }
1158 ];
1159 const items2 = Items(
1160 {
1161 foo: 'bar'
1162 }
1163 );
1164 `,
1165 options: [2, { VariableDeclarator: 3 }]
1166
1167 },
1168 {
1169 code: unIndent`
1170 const geometry = 2,
1171 rotate = 3;
1172 var a = 1,
1173 b = 2;
1174 let light = true,
1175 shadow = false;
1176 `,
1177 options: [2, { VariableDeclarator: { const: 3, let: 2 } }]
1178 },
1179 {
1180 code: unIndent`
1181 const abc = 5,
1182 c = 2,
1183 xyz =
1184 {
1185 a: 1,
1186 b: 2
1187 };
1188 let abc2 = 5,
1189 c2 = 2,
1190 xyz2 =
1191 {
1192 a: 1,
1193 b: 2
1194 };
1195 var abc3 = 5,
1196 c3 = 2,
1197 xyz3 =
1198 {
1199 a: 1,
1200 b: 2
1201 };
1202 `,
1203 options: [2, { VariableDeclarator: { var: 2, const: 3 }, SwitchCase: 1 }]
1204 },
1205 {
1206 code: unIndent`
1207 module.exports = {
1208 'Unit tests':
1209 {
1210 rootPath: './',
1211 environment: 'node',
1212 tests:
1213 [
1214 'test/test-*.js'
1215 ],
1216 sources:
1217 [
1218 '*.js',
1219 'test/**.js'
1220 ]
1221 }
1222 };
1223 `,
1224 options: [2]
1225 },
1226 {
1227 code: unIndent`
1228 foo =
1229 bar;
1230 `,
1231 options: [2]
1232 },
1233 {
1234 code: unIndent`
1235 foo = (
1236 bar
1237 );
1238 `,
1239 options: [2]
1240 },
1241 {
1242 code: unIndent`
1243 var path = require('path')
1244 , crypto = require('crypto')
1245 ;
1246 `,
1247 options: [2]
1248 },
1249 unIndent`
1250 var a = 1
1251 ,b = 2
1252 ;
1253 `,
1254 {
1255 code: unIndent`
1256 export function create (some,
1257 argument) {
1258 return Object.create({
1259 a: some,
1260 b: argument
1261 });
1262 };
1263 `,
1264 options: [2, { FunctionDeclaration: { parameters: "first" } }],
1265 parserOptions: { ecmaVersion: 6, sourceType: "module" }
1266 },
1267 {
1268 code: unIndent`
1269 export function create (id, xfilter, rawType,
1270 width=defaultWidth, height=defaultHeight,
1271 footerHeight=defaultFooterHeight,
1272 padding=defaultPadding) {
1273 // ... function body, indented two spaces
1274 }
1275 `,
1276 options: [2, { FunctionDeclaration: { parameters: "first" } }],
1277 parserOptions: { ecmaVersion: 6, sourceType: "module" }
1278 },
1279 {
1280 code: unIndent`
1281 var obj = {
1282 foo: function () {
1283 return new p()
1284 .then(function (ok) {
1285 return ok;
1286 }, function () {
1287 // ignore things
1288 });
1289 }
1290 };
1291 `,
1292 options: [2]
1293 },
1294 {
1295 code: unIndent`
1296 a.b()
1297 .c(function(){
1298 var a;
1299 }).d.e;
1300 `,
1301 options: [2]
1302 },
1303 {
1304 code: unIndent`
1305 const YO = 'bah',
1306 TE = 'mah'
1307
1308 var res,
1309 a = 5,
1310 b = 4
1311 `,
1312 options: [2, { VariableDeclarator: { var: 2, let: 2, const: 3 } }]
1313 },
1314 {
1315 code: unIndent`
1316 const YO = 'bah',
1317 TE = 'mah'
1318
1319 var res,
1320 a = 5,
1321 b = 4
1322
1323 if (YO) console.log(TE)
1324 `,
1325 options: [2, { VariableDeclarator: { var: 2, let: 2, const: 3 } }]
1326 },
1327 {
1328 code: unIndent`
1329 var foo = 'foo',
1330 bar = 'bar',
1331 baz = function() {
1332
1333 }
1334
1335 function hello () {
1336
1337 }
1338 `,
1339 options: [2]
1340 },
1341 {
1342 code: unIndent`
1343 var obj = {
1344 send: function () {
1345 return P.resolve({
1346 type: 'POST'
1347 })
1348 .then(function () {
1349 return true;
1350 }, function () {
1351 return false;
1352 });
1353 }
1354 };
1355 `,
1356 options: [2]
1357 },
1358 {
1359 code: unIndent`
1360 var obj = {
1361 send: function () {
1362 return P.resolve({
1363 type: 'POST'
1364 })
1365 .then(function () {
1366 return true;
1367 }, function () {
1368 return false;
1369 });
1370 }
1371 };
1372 `,
1373 options: [2, { MemberExpression: 0 }]
1374 },
1375 unIndent`
1376 const someOtherFunction = argument => {
1377 console.log(argument);
1378 },
1379 someOtherValue = 'someOtherValue';
1380 `,
1381 {
1382 code: unIndent`
1383 [
1384 'a',
1385 'b'
1386 ].sort().should.deepEqual([
1387 'x',
1388 'y'
1389 ]);
1390 `,
1391 options: [2]
1392 },
1393 {
1394 code: unIndent`
1395 var a = 1,
1396 B = class {
1397 constructor(){}
1398 a(){}
1399 get b(){}
1400 };
1401 `,
1402 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
1403 },
1404 {
1405 code: unIndent`
1406 var a = 1,
1407 B =
1408 class {
1409 constructor(){}
1410 a(){}
1411 get b(){}
1412 },
1413 c = 3;
1414 `,
1415 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
1416 },
1417 {
1418 code: unIndent`
1419 class A{
1420 constructor(){}
1421 a(){}
1422 get b(){}
1423 }
1424 `,
1425 options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
1426 },
1427 {
1428 code: unIndent`
1429 var A = class {
1430 constructor(){}
1431 a(){}
1432 get b(){}
1433 }
1434 `,
1435 options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
1436 },
1437 {
1438 code: unIndent`
1439 var a = {
1440 some: 1
1441 , name: 2
1442 };
1443 `,
1444 options: [2]
1445 },
1446 {
1447 code: unIndent`
1448 a.c = {
1449 aa: function() {
1450 'test1';
1451 return 'aa';
1452 }
1453 , bb: function() {
1454 return this.bb();
1455 }
1456 };
1457 `,
1458 options: [4]
1459 },
1460 {
1461 code: unIndent`
1462 var a =
1463 {
1464 actions:
1465 [
1466 {
1467 name: 'compile'
1468 }
1469 ]
1470 };
1471 `,
1472 options: [4, { VariableDeclarator: 0, SwitchCase: 1 }]
1473 },
1474 {
1475 code: unIndent`
1476 var a =
1477 [
1478 {
1479 name: 'compile'
1480 }
1481 ];
1482 `,
1483 options: [4, { VariableDeclarator: 0, SwitchCase: 1 }]
1484 },
1485 unIndent`
1486 [[
1487 ], function(
1488 foo
1489 ) {}
1490 ]
1491 `,
1492 unIndent`
1493 define([
1494 'foo'
1495 ], function(
1496 bar
1497 ) {
1498 baz;
1499 }
1500 )
1501 `,
1502 {
1503 code: unIndent`
1504 const func = function (opts) {
1505 return Promise.resolve()
1506 .then(() => {
1507 [
1508 'ONE', 'TWO'
1509 ].forEach(command => { doSomething(); });
1510 });
1511 };
1512 `,
1513 options: [4, { MemberExpression: 0 }]
1514 },
1515 {
1516 code: unIndent`
1517 const func = function (opts) {
1518 return Promise.resolve()
1519 .then(() => {
1520 [
1521 'ONE', 'TWO'
1522 ].forEach(command => { doSomething(); });
1523 });
1524 };
1525 `,
1526 options: [4]
1527 },
1528 {
1529 code: unIndent`
1530 var haveFun = function () {
1531 SillyFunction(
1532 {
1533 value: true,
1534 },
1535 {
1536 _id: true,
1537 }
1538 );
1539 };
1540 `,
1541 options: [4]
1542 },
1543 {
1544 code: unIndent`
1545 var haveFun = function () {
1546 new SillyFunction(
1547 {
1548 value: true,
1549 },
1550 {
1551 _id: true,
1552 }
1553 );
1554 };
1555 `,
1556 options: [4]
1557 },
1558 {
1559 code: unIndent`
1560 let object1 = {
1561 doThing() {
1562 return _.chain([])
1563 .map(v => (
1564 {
1565 value: true,
1566 }
1567 ))
1568 .value();
1569 }
1570 };
1571 `,
1572 options: [2]
1573 },
1574 {
1575 code: unIndent`
1576 var foo = {
1577 bar: 1,
1578 baz: {
1579 qux: 2
1580 }
1581 },
1582 bar = 1;
1583 `,
1584 options: [2]
1585 },
1586 {
1587 code: unIndent`
1588 class Foo
1589 extends Bar {
1590 baz() {}
1591 }
1592 `,
1593 options: [2]
1594 },
1595 {
1596 code: unIndent`
1597 class Foo extends
1598 Bar {
1599 baz() {}
1600 }
1601 `,
1602 options: [2]
1603 },
1604 {
1605 code: unIndent`
1606 class Foo extends
1607 (
1608 Bar
1609 ) {
1610 baz() {}
1611 }
1612 `,
1613 options: [2]
1614 },
1615 {
1616 code: unIndent`
1617 fs.readdirSync(path.join(__dirname, '../rules')).forEach(name => {
1618 files[name] = foo;
1619 });
1620 `,
1621 options: [2, { outerIIFEBody: 0 }]
1622 },
1623 {
1624 code: unIndent`
1625 (function(){
1626 function foo(x) {
1627 return x + 1;
1628 }
1629 })();
1630 `,
1631 options: [2, { outerIIFEBody: 0 }]
1632 },
1633 {
1634 code: unIndent`
1635 (function(){
1636 function foo(x) {
1637 return x + 1;
1638 }
1639 })();
1640 `,
1641 options: [4, { outerIIFEBody: 2 }]
1642 },
1643 {
1644 code: unIndent`
1645 (function(x, y){
1646 function foo(x) {
1647 return x + 1;
1648 }
1649 })(1, 2);
1650 `,
1651 options: [2, { outerIIFEBody: 0 }]
1652 },
1653 {
1654 code: unIndent`
1655 (function(){
1656 function foo(x) {
1657 return x + 1;
1658 }
1659 }());
1660 `,
1661 options: [2, { outerIIFEBody: 0 }]
1662 },
1663 {
1664 code: unIndent`
1665 !function(){
1666 function foo(x) {
1667 return x + 1;
1668 }
1669 }();
1670 `,
1671 options: [2, { outerIIFEBody: 0 }]
1672 },
1673 {
1674 code: unIndent`
1675 !function(){
1676 \t\t\tfunction foo(x) {
1677 \t\t\t\treturn x + 1;
1678 \t\t\t}
1679 }();
1680 `,
1681 options: ["tab", { outerIIFEBody: 3 }]
1682 },
1683 {
1684 code: unIndent`
1685 var out = function(){
1686 function fooVar(x) {
1687 return x + 1;
1688 }
1689 };
1690 `,
1691 options: [2, { outerIIFEBody: 0 }]
1692 },
1693 {
1694 code: unIndent`
1695 var ns = function(){
1696 function fooVar(x) {
1697 return x + 1;
1698 }
1699 }();
1700 `,
1701 options: [2, { outerIIFEBody: 0 }]
1702 },
1703 {
1704 code: unIndent`
1705 ns = function(){
1706 function fooVar(x) {
1707 return x + 1;
1708 }
1709 }();
1710 `,
1711 options: [2, { outerIIFEBody: 0 }]
1712 },
1713 {
1714 code: unIndent`
1715 var ns = (function(){
1716 function fooVar(x) {
1717 return x + 1;
1718 }
1719 }(x));
1720 `,
1721 options: [2, { outerIIFEBody: 0 }]
1722 },
1723 {
1724 code: unIndent`
1725 var ns = (function(){
1726 function fooVar(x) {
1727 return x + 1;
1728 }
1729 }(x));
1730 `,
1731 options: [4, { outerIIFEBody: 2 }]
1732 },
1733 {
1734 code: unIndent`
1735 var obj = {
1736 foo: function() {
1737 return true;
1738 }
1739 };
1740 `,
1741 options: [2, { outerIIFEBody: 0 }]
1742 },
1743 {
1744 code: unIndent`
1745 while (
1746 function() {
1747 return true;
1748 }()) {
1749
1750 x = x + 1;
1751 };
1752 `,
1753 options: [2, { outerIIFEBody: 20 }]
1754 },
1755 {
1756 code: unIndent`
1757 (() => {
1758 function foo(x) {
1759 return x + 1;
1760 }
1761 })();
1762 `,
1763 options: [2, { outerIIFEBody: 0 }]
1764 },
1765 {
1766 code: unIndent`
1767 function foo() {
1768 }
1769 `,
1770 options: ["tab", { outerIIFEBody: 0 }]
1771 },
1772 {
1773 code: unIndent`
1774 ;(() => {
1775 function foo(x) {
1776 return x + 1;
1777 }
1778 })();
1779 `,
1780 options: [2, { outerIIFEBody: 0 }]
1781 },
1782 {
1783 code: unIndent`
1784 if(data) {
1785 console.log('hi');
1786 }
1787 `,
1788 options: [2, { outerIIFEBody: 0 }]
1789 },
1790 {
1791 code: unIndent`
1792 (function(x) {
1793 return x + 1;
1794 })();
1795 `,
1796 options: [4, { outerIIFEBody: "off" }]
1797 },
1798 {
1799 code: unIndent`
1800 (function(x) {
1801 return x + 1;
1802 })();
1803 `,
1804 options: [4, { outerIIFEBody: "off" }]
1805 },
1806 {
1807 code: unIndent`
1808 ;(() => {
1809 function x(y) {
1810 return y + 1;
1811 }
1812 })();
1813 `,
1814 options: [4, { outerIIFEBody: "off" }]
1815 },
1816 {
1817 code: unIndent`
1818 ;(() => {
1819 function x(y) {
1820 return y + 1;
1821 }
1822 })();
1823 `,
1824 options: [4, { outerIIFEBody: "off" }]
1825 },
1826 {
1827 code: unIndent`
1828 function foo() {
1829 }
1830 `,
1831 options: [4, { outerIIFEBody: "off" }]
1832 },
1833 {
1834 code: "Buffer.length",
1835 options: [4, { MemberExpression: 1 }]
1836 },
1837 {
1838 code: unIndent`
1839 Buffer
1840 .indexOf('a')
1841 .toString()
1842 `,
1843 options: [4, { MemberExpression: 1 }]
1844 },
1845 {
1846 code: unIndent`
1847 Buffer.
1848 length
1849 `,
1850 options: [4, { MemberExpression: 1 }]
1851 },
1852 {
1853 code: unIndent`
1854 Buffer
1855 .foo
1856 .bar
1857 `,
1858 options: [4, { MemberExpression: 1 }]
1859 },
1860 {
1861 code: unIndent`
1862 Buffer
1863 \t.foo
1864 \t.bar
1865 `,
1866 options: ["tab", { MemberExpression: 1 }]
1867 },
1868 {
1869 code: unIndent`
1870 Buffer
1871 .foo
1872 .bar
1873 `,
1874 options: [2, { MemberExpression: 2 }]
1875 },
1876 unIndent`
1877 (
1878 foo
1879 .bar
1880 )
1881 `,
1882 unIndent`
1883 (
1884 (
1885 foo
1886 .bar
1887 )
1888 )
1889 `,
1890 unIndent`
1891 (
1892 foo
1893 )
1894 .bar
1895 `,
1896 unIndent`
1897 (
1898 (
1899 foo
1900 )
1901 .bar
1902 )
1903 `,
1904 unIndent`
1905 (
1906 (
1907 foo
1908 )
1909 [
1910 (
1911 bar
1912 )
1913 ]
1914 )
1915 `,
1916 unIndent`
1917 (
1918 foo[bar]
1919 )
1920 .baz
1921 `,
1922 unIndent`
1923 (
1924 (foo.bar)
1925 )
1926 .baz
1927 `,
1928 {
1929 code: unIndent`
1930 MemberExpression
1931 .can
1932 .be
1933 .turned
1934 .off();
1935 `,
1936 options: [4, { MemberExpression: "off" }]
1937 },
1938 {
1939 code: unIndent`
1940 foo = bar.baz()
1941 .bip();
1942 `,
1943 options: [4, { MemberExpression: 1 }]
1944 },
1945 unIndent`
1946 function foo() {
1947 new
1948 .target
1949 }
1950 `,
1951 unIndent`
1952 function foo() {
1953 new.
1954 target
1955 }
1956 `,
1957 {
1958 code: unIndent`
1959 if (foo) {
1960 bar();
1961 } else if (baz) {
1962 foobar();
1963 } else if (qux) {
1964 qux();
1965 }
1966 `,
1967 options: [2]
1968 },
1969 {
1970 code: unIndent`
1971 function foo(aaa,
1972 bbb, ccc, ddd) {
1973 bar();
1974 }
1975 `,
1976 options: [2, { FunctionDeclaration: { parameters: 1, body: 2 } }]
1977 },
1978 {
1979 code: unIndent`
1980 function foo(aaa, bbb,
1981 ccc, ddd) {
1982 bar();
1983 }
1984 `,
1985 options: [2, { FunctionDeclaration: { parameters: 3, body: 1 } }]
1986 },
1987 {
1988 code: unIndent`
1989 function foo(aaa,
1990 bbb,
1991 ccc) {
1992 bar();
1993 }
1994 `,
1995 options: [4, { FunctionDeclaration: { parameters: 1, body: 3 } }]
1996 },
1997 {
1998 code: unIndent`
1999 function foo(aaa,
2000 bbb, ccc,
2001 ddd, eee, fff) {
2002 bar();
2003 }
2004 `,
2005 options: [2, { FunctionDeclaration: { parameters: "first", body: 1 } }]
2006 },
2007 {
2008 code: unIndent`
2009 function foo(aaa, bbb)
2010 {
2011 bar();
2012 }
2013 `,
2014 options: [2, { FunctionDeclaration: { body: 3 } }]
2015 },
2016 {
2017 code: unIndent`
2018 function foo(
2019 aaa,
2020 bbb) {
2021 bar();
2022 }
2023 `,
2024 options: [2, { FunctionDeclaration: { parameters: "first", body: 2 } }]
2025 },
2026 {
2027 code: unIndent`
2028 var foo = function(aaa,
2029 bbb,
2030 ccc,
2031 ddd) {
2032 bar();
2033 }
2034 `,
2035 options: [2, { FunctionExpression: { parameters: 2, body: 0 } }]
2036 },
2037 {
2038 code: unIndent`
2039 var foo = function(aaa,
2040 bbb,
2041 ccc) {
2042 bar();
2043 }
2044 `,
2045 options: [2, { FunctionExpression: { parameters: 1, body: 10 } }]
2046 },
2047 {
2048 code: unIndent`
2049 var foo = function(aaa,
2050 bbb, ccc, ddd,
2051 eee, fff) {
2052 bar();
2053 }
2054 `,
2055 options: [4, { FunctionExpression: { parameters: "first", body: 1 } }]
2056 },
2057 {
2058 code: unIndent`
2059 var foo = function(
2060 aaa, bbb, ccc,
2061 ddd, eee) {
2062 bar();
2063 }
2064 `,
2065 options: [2, { FunctionExpression: { parameters: "first", body: 3 } }]
2066 },
2067 {
2068 code: unIndent`
2069 foo.bar(
2070 baz, qux, function() {
2071 qux;
2072 }
2073 );
2074 `,
2075 options: [2, { FunctionExpression: { body: 3 }, CallExpression: { arguments: 3 } }]
2076 },
2077 {
2078 code: unIndent`
2079 function foo() {
2080 bar();
2081 \tbaz();
2082 \t \t\t\t \t\t\t \t \tqux();
2083 }
2084 `,
2085 options: [2]
2086 },
2087 {
2088 code: unIndent`
2089 function foo() {
2090 function bar() {
2091 baz();
2092 }
2093 }
2094 `,
2095 options: [2, { FunctionDeclaration: { body: 1 } }]
2096 },
2097 {
2098 code: unIndent`
2099 function foo() {
2100 bar();
2101 \t\t}
2102 `,
2103 options: [2]
2104 },
2105 {
2106 code: unIndent`
2107 function foo() {
2108 function bar(baz,
2109 qux) {
2110 foobar();
2111 }
2112 }
2113 `,
2114 options: [2, { FunctionDeclaration: { body: 1, parameters: 2 } }]
2115 },
2116 {
2117 code: unIndent`
2118 ((
2119 foo
2120 ))
2121 `,
2122 options: [4]
2123 },
2124
2125 // ternary expressions (https://github.com/eslint/eslint/issues/7420)
2126 {
2127 code: unIndent`
2128 foo
2129 ? bar
2130 : baz
2131 `,
2132 options: [2]
2133 },
2134 {
2135 code: unIndent`
2136 foo = (bar ?
2137 baz :
2138 qux
2139 );
2140 `,
2141 options: [2]
2142 },
2143 {
2144 code: unIndent`
2145 condition
2146 ? () => {
2147 return true
2148 }
2149 : condition2
2150 ? () => {
2151 return true
2152 }
2153 : () => {
2154 return false
2155 }
2156 `,
2157 options: [2]
2158 },
2159 {
2160 code: unIndent`
2161 condition
2162 ? () => {
2163 return true
2164 }
2165 : condition2
2166 ? () => {
2167 return true
2168 }
2169 : () => {
2170 return false
2171 }
2172 `,
2173 options: [2, { offsetTernaryExpressions: false }]
2174 },
2175 {
2176 code: unIndent`
2177 condition
2178 ? () => {
2179 return true
2180 }
2181 : condition2
2182 ? () => {
2183 return true
2184 }
2185 : () => {
2186 return false
2187 }
2188 `,
2189 options: [2, { offsetTernaryExpressions: true }]
2190 },
2191 {
2192 code: unIndent`
2193 condition
2194 ? () => {
2195 return true
2196 }
2197 : condition2
2198 ? () => {
2199 return true
2200 }
2201 : () => {
2202 return false
2203 }
2204 `,
2205 options: [4, { offsetTernaryExpressions: true }]
2206 },
2207 {
2208 code: unIndent`
2209 condition
2210 \t? () => {
2211 \t\t\treturn true
2212 \t\t}
2213 \t: condition2
2214 \t\t? () => {
2215 \t\t\t\treturn true
2216 \t\t\t}
2217 \t\t: () => {
2218 \t\t\t\treturn false
2219 \t\t\t}
2220 `,
2221 options: ["tab", { offsetTernaryExpressions: true }]
2222 },
2223 unIndent`
2224 [
2225 foo ?
2226 bar :
2227 baz,
2228 qux
2229 ];
2230 `,
2231 {
2232
2233 /*
2234 * Checking comments:
2235 * https://github.com/eslint/eslint/issues/3845, https://github.com/eslint/eslint/issues/6571
2236 */
2237 code: unIndent`
2238 foo();
2239 // Line
2240 /* multiline
2241 Line */
2242 bar();
2243 // trailing comment
2244 `,
2245 options: [2]
2246 },
2247 {
2248 code: unIndent`
2249 switch (foo) {
2250 case bar:
2251 baz();
2252 // call the baz function
2253 }
2254 `,
2255 options: [2, { SwitchCase: 1 }]
2256 },
2257 {
2258 code: unIndent`
2259 switch (foo) {
2260 case bar:
2261 baz();
2262 // no default
2263 }
2264 `,
2265 options: [2, { SwitchCase: 1 }]
2266 },
2267 unIndent`
2268 [
2269 // no elements
2270 ]
2271 `,
2272 {
2273
2274 /*
2275 * Destructuring assignments:
2276 * https://github.com/eslint/eslint/issues/6813
2277 */
2278 code: unIndent`
2279 var {
2280 foo,
2281 bar,
2282 baz: qux,
2283 foobar: baz = foobar
2284 } = qux;
2285 `,
2286 options: [2]
2287 },
2288 {
2289 code: unIndent`
2290 var [
2291 foo,
2292 bar,
2293 baz,
2294 foobar = baz
2295 ] = qux;
2296 `,
2297 options: [2]
2298 },
2299 {
2300 code: unIndent`
2301 const {
2302 a
2303 }
2304 =
2305 {
2306 a: 1
2307 }
2308 `,
2309 options: [2]
2310 },
2311 {
2312 code: unIndent`
2313 const {
2314 a
2315 } = {
2316 a: 1
2317 }
2318 `,
2319 options: [2]
2320 },
2321 {
2322 code: unIndent`
2323 const
2324 {
2325 a
2326 } = {
2327 a: 1
2328 };
2329 `,
2330 options: [2]
2331 },
2332 {
2333 code: unIndent`
2334 const
2335 foo = {
2336 bar: 1
2337 }
2338 `,
2339 options: [2]
2340 },
2341 {
2342 code: unIndent`
2343 const [
2344 a
2345 ] = [
2346 1
2347 ]
2348 `,
2349 options: [2]
2350 },
2351 {
2352
2353 // https://github.com/eslint/eslint/issues/7233
2354 code: unIndent`
2355 var folder = filePath
2356 .foo()
2357 .bar;
2358 `,
2359 options: [2, { MemberExpression: 2 }]
2360 },
2361 {
2362 code: unIndent`
2363 for (const foo of bar)
2364 baz();
2365 `,
2366 options: [2]
2367 },
2368 {
2369 code: unIndent`
2370 var x = () =>
2371 5;
2372 `,
2373 options: [2]
2374 },
2375 unIndent`
2376 (
2377 foo
2378 )(
2379 bar
2380 )
2381 `,
2382 unIndent`
2383 (() =>
2384 foo
2385 )(
2386 bar
2387 )
2388 `,
2389 unIndent`
2390 (() => {
2391 foo();
2392 })(
2393 bar
2394 )
2395 `,
2396 {
2397
2398 // Don't lint the indentation of the first token after a :
2399 code: unIndent`
2400 ({code:
2401 "foo.bar();"})
2402 `,
2403 options: [2]
2404 },
2405 {
2406
2407 // Don't lint the indentation of the first token after a :
2408 code: unIndent`
2409 ({code:
2410 "foo.bar();"})
2411 `,
2412 options: [2]
2413 },
2414 unIndent`
2415 ({
2416 foo:
2417 bar
2418 })
2419 `,
2420 unIndent`
2421 ({
2422 [foo]:
2423 bar
2424 })
2425 `,
2426 {
2427
2428 // Comments in switch cases
2429 code: unIndent`
2430 switch (foo) {
2431 // comment
2432 case study:
2433 // comment
2434 bar();
2435 case closed:
2436 /* multiline comment
2437 */
2438 }
2439 `,
2440 options: [2, { SwitchCase: 1 }]
2441 },
2442 {
2443
2444 // Comments in switch cases
2445 code: unIndent`
2446 switch (foo) {
2447 // comment
2448 case study:
2449 // the comment can also be here
2450 case closed:
2451 }
2452 `,
2453 options: [2, { SwitchCase: 1 }]
2454 },
2455 {
2456
2457 // BinaryExpressions with parens
2458 code: unIndent`
2459 foo && (
2460 bar
2461 )
2462 `,
2463 options: [4]
2464 },
2465 {
2466
2467 // BinaryExpressions with parens
2468 code: unIndent`
2469 foo && ((
2470 bar
2471 ))
2472 `,
2473 options: [4]
2474 },
2475 {
2476 code: unIndent`
2477 foo &&
2478 (
2479 bar
2480 )
2481 `,
2482 options: [4]
2483 },
2484 unIndent`
2485 foo &&
2486 !bar(
2487 )
2488 `,
2489 unIndent`
2490 foo &&
2491 ![].map(() => {
2492 bar();
2493 })
2494 `,
2495 {
2496 code: unIndent`
2497 foo =
2498 bar;
2499 `,
2500 options: [4]
2501 },
2502 {
2503 code: unIndent`
2504 function foo() {
2505 var bar = function(baz,
2506 qux) {
2507 foobar();
2508 };
2509 }
2510 `,
2511 options: [2, { FunctionExpression: { parameters: 3 } }]
2512 },
2513 unIndent`
2514 function foo() {
2515 return (bar === 1 || bar === 2 &&
2516 (/Function/.test(grandparent.type))) &&
2517 directives(parent).indexOf(node) >= 0;
2518 }
2519 `,
2520 {
2521 code: unIndent`
2522 function foo() {
2523 return (foo === bar || (
2524 baz === qux && (
2525 foo === foo ||
2526 bar === bar ||
2527 baz === baz
2528 )
2529 ))
2530 }
2531 `,
2532 options: [4]
2533 },
2534 unIndent`
2535 if (
2536 foo === 1 ||
2537 bar === 1 ||
2538 // comment
2539 (baz === 1 && qux === 1)
2540 ) {}
2541 `,
2542 {
2543 code: unIndent`
2544 foo =
2545 (bar + baz);
2546 `,
2547 options: [2]
2548 },
2549 {
2550 code: unIndent`
2551 function foo() {
2552 return (bar === 1 || bar === 2) &&
2553 (z === 3 || z === 4);
2554 }
2555 `,
2556 options: [2]
2557 },
2558 {
2559 code: unIndent`
2560 /* comment */ if (foo) {
2561 bar();
2562 }
2563 `,
2564 options: [2]
2565 },
2566 {
2567
2568 // Comments at the end of if blocks that have `else` blocks can either refer to the lines above or below them
2569 code: unIndent`
2570 if (foo) {
2571 bar();
2572 // Otherwise, if foo is false, do baz.
2573 // baz is very important.
2574 } else {
2575 baz();
2576 }
2577 `,
2578 options: [2]
2579 },
2580 {
2581 code: unIndent`
2582 function foo() {
2583 return ((bar === 1 || bar === 2) &&
2584 (z === 3 || z === 4));
2585 }
2586 `,
2587 options: [2]
2588 },
2589 {
2590 code: unIndent`
2591 foo(
2592 bar,
2593 baz,
2594 qux
2595 );
2596 `,
2597 options: [2, { CallExpression: { arguments: 1 } }]
2598 },
2599 {
2600 code: unIndent`
2601 foo(
2602 \tbar,
2603 \tbaz,
2604 \tqux
2605 );
2606 `,
2607 options: ["tab", { CallExpression: { arguments: 1 } }]
2608 },
2609 {
2610 code: unIndent`
2611 foo(bar,
2612 baz,
2613 qux);
2614 `,
2615 options: [4, { CallExpression: { arguments: 2 } }]
2616 },
2617 {
2618 code: unIndent`
2619 foo(
2620 bar,
2621 baz,
2622 qux
2623 );
2624 `,
2625 options: [2, { CallExpression: { arguments: 0 } }]
2626 },
2627 {
2628 code: unIndent`
2629 foo(bar,
2630 baz,
2631 qux
2632 );
2633 `,
2634 options: [2, { CallExpression: { arguments: "first" } }]
2635 },
2636 {
2637 code: unIndent`
2638 foo(bar, baz,
2639 qux, barbaz,
2640 barqux, bazqux);
2641 `,
2642 options: [2, { CallExpression: { arguments: "first" } }]
2643 },
2644 {
2645 code: unIndent`
2646 foo(bar,
2647 1 + 2,
2648 !baz,
2649 new Car('!')
2650 );
2651 `,
2652 options: [2, { CallExpression: { arguments: 4 } }]
2653 },
2654 unIndent`
2655 foo(
2656 (bar)
2657 );
2658 `,
2659 {
2660 code: unIndent`
2661 foo(
2662 (bar)
2663 );
2664 `,
2665 options: [4, { CallExpression: { arguments: 1 } }]
2666 },
2667
2668 // https://github.com/eslint/eslint/issues/7484
2669 {
2670 code: unIndent`
2671 var foo = function() {
2672 return bar(
2673 [{
2674 }].concat(baz)
2675 );
2676 };
2677 `,
2678 options: [2]
2679 },
2680
2681 // https://github.com/eslint/eslint/issues/7573
2682 {
2683 code: unIndent`
2684 return (
2685 foo
2686 );
2687 `,
2688 parserOptions: { ecmaFeatures: { globalReturn: true } }
2689 },
2690 {
2691 code: unIndent`
2692 return (
2693 foo
2694 )
2695 `,
2696 parserOptions: { ecmaFeatures: { globalReturn: true } }
2697 },
2698 unIndent`
2699 var foo = [
2700 bar,
2701 baz
2702 ]
2703 `,
2704 unIndent`
2705 var foo = [bar,
2706 baz,
2707 qux
2708 ]
2709 `,
2710 {
2711 code: unIndent`
2712 var foo = [bar,
2713 baz,
2714 qux
2715 ]
2716 `,
2717 options: [2, { ArrayExpression: 0 }]
2718 },
2719 {
2720 code: unIndent`
2721 var foo = [bar,
2722 baz,
2723 qux
2724 ]
2725 `,
2726 options: [2, { ArrayExpression: 8 }]
2727 },
2728 {
2729 code: unIndent`
2730 var foo = [bar,
2731 baz,
2732 qux
2733 ]
2734 `,
2735 options: [2, { ArrayExpression: "first" }]
2736 },
2737 {
2738 code: unIndent`
2739 var foo = [bar,
2740 baz, qux
2741 ]
2742 `,
2743 options: [2, { ArrayExpression: "first" }]
2744 },
2745 {
2746 code: unIndent`
2747 var foo = [
2748 { bar: 1,
2749 baz: 2 },
2750 { bar: 3,
2751 baz: 4 }
2752 ]
2753 `,
2754 options: [4, { ArrayExpression: 2, ObjectExpression: "first" }]
2755 },
2756 {
2757 code: unIndent`
2758 var foo = {
2759 bar: 1,
2760 baz: 2
2761 };
2762 `,
2763 options: [2, { ObjectExpression: 0 }]
2764 },
2765 {
2766 code: unIndent`
2767 var foo = { foo: 1, bar: 2,
2768 baz: 3 }
2769 `,
2770 options: [2, { ObjectExpression: "first" }]
2771 },
2772 {
2773 code: unIndent`
2774 var foo = [
2775 {
2776 foo: 1
2777 }
2778 ]
2779 `,
2780 options: [4, { ArrayExpression: 2 }]
2781 },
2782 {
2783 code: unIndent`
2784 function foo() {
2785 [
2786 foo
2787 ]
2788 }
2789 `,
2790 options: [2, { ArrayExpression: 4 }]
2791 },
2792 {
2793 code: "[\n]",
2794 options: [2, { ArrayExpression: "first" }]
2795 },
2796 {
2797 code: "[\n]",
2798 options: [2, { ArrayExpression: 1 }]
2799 },
2800 {
2801 code: "{\n}",
2802 options: [2, { ObjectExpression: "first" }]
2803 },
2804 {
2805 code: "{\n}",
2806 options: [2, { ObjectExpression: 1 }]
2807 },
2808 {
2809 code: unIndent`
2810 var foo = [
2811 [
2812 1
2813 ]
2814 ]
2815 `,
2816 options: [2, { ArrayExpression: "first" }]
2817 },
2818 {
2819 code: unIndent`
2820 var foo = [ 1,
2821 [
2822 2
2823 ]
2824 ];
2825 `,
2826 options: [2, { ArrayExpression: "first" }]
2827 },
2828 {
2829 code: unIndent`
2830 var foo = bar(1,
2831 [ 2,
2832 3
2833 ]
2834 );
2835 `,
2836 options: [4, { ArrayExpression: "first", CallExpression: { arguments: "first" } }]
2837 },
2838 {
2839 code: unIndent`
2840 var foo =
2841 [
2842 ]()
2843 `,
2844 options: [4, { CallExpression: { arguments: "first" }, ArrayExpression: "first" }]
2845 },
2846
2847 // https://github.com/eslint/eslint/issues/7732
2848 {
2849 code: unIndent`
2850 const lambda = foo => {
2851 Object.assign({},
2852 filterName,
2853 {
2854 display
2855 }
2856 );
2857 }
2858 `,
2859 options: [2, { ObjectExpression: 1 }]
2860 },
2861 {
2862 code: unIndent`
2863 const lambda = foo => {
2864 Object.assign({},
2865 filterName,
2866 {
2867 display
2868 }
2869 );
2870 }
2871 `,
2872 options: [2, { ObjectExpression: "first" }]
2873 },
2874
2875 // https://github.com/eslint/eslint/issues/7733
2876 {
2877 code: unIndent`
2878 var foo = function() {
2879 \twindow.foo('foo',
2880 \t\t{
2881 \t\t\tfoo: 'bar',
2882 \t\t\tbar: {
2883 \t\t\t\tfoo: 'bar'
2884 \t\t\t}
2885 \t\t}
2886 \t);
2887 }
2888 `,
2889 options: ["tab"]
2890 },
2891 {
2892 code: unIndent`
2893 echo = spawn('cmd.exe',
2894 ['foo', 'bar',
2895 'baz']);
2896 `,
2897 options: [2, { ArrayExpression: "first", CallExpression: { arguments: "first" } }]
2898 },
2899 {
2900 code: unIndent`
2901 if (foo)
2902 bar();
2903 // Otherwise, if foo is false, do baz.
2904 // baz is very important.
2905 else {
2906 baz();
2907 }
2908 `,
2909 options: [2]
2910 },
2911 {
2912 code: unIndent`
2913 if (
2914 foo && bar ||
2915 baz && qux // This line is ignored because BinaryExpressions are not checked.
2916 ) {
2917 qux();
2918 }
2919 `,
2920 options: [4]
2921 },
2922 unIndent`
2923 [
2924 ] || [
2925 ]
2926 `,
2927 unIndent`
2928 (
2929 [
2930 ] || [
2931 ]
2932 )
2933 `,
2934 unIndent`
2935 1
2936 + (
2937 1
2938 )
2939 `,
2940 unIndent`
2941 (
2942 foo && (
2943 bar ||
2944 baz
2945 )
2946 )
2947 `,
2948 unIndent`
2949 foo
2950 || (
2951 bar
2952 )
2953 `,
2954 unIndent`
2955 foo
2956 || (
2957 bar
2958 )
2959 `,
2960 {
2961 code: unIndent`
2962 var foo =
2963 1;
2964 `,
2965 options: [4, { VariableDeclarator: 2 }]
2966 },
2967 {
2968 code: unIndent`
2969 var foo = 1,
2970 bar =
2971 2;
2972 `,
2973 options: [4]
2974 },
2975 {
2976 code: unIndent`
2977 switch (foo) {
2978 case bar:
2979 {
2980 baz();
2981 }
2982 }
2983 `,
2984 options: [2, { SwitchCase: 1 }]
2985 },
2986
2987 // Template curlies
2988 {
2989 code: unIndent`
2990 \`foo\${
2991 bar}\`
2992 `,
2993 options: [2]
2994 },
2995 {
2996 code: unIndent`
2997 \`foo\${
2998 \`bar\${
2999 baz}\`}\`
3000 `,
3001 options: [2]
3002 },
3003 {
3004 code: unIndent`
3005 \`foo\${
3006 \`bar\${
3007 baz
3008 }\`
3009 }\`
3010 `,
3011 options: [2]
3012 },
3013 {
3014 code: unIndent`
3015 \`foo\${
3016 (
3017 bar
3018 )
3019 }\`
3020 `,
3021 options: [2]
3022 },
3023 unIndent`
3024 foo(\`
3025 bar
3026 \`, {
3027 baz: 1
3028 });
3029 `,
3030 unIndent`
3031 function foo() {
3032 \`foo\${bar}baz\${
3033 qux}foo\${
3034 bar}baz\`
3035 }
3036 `,
3037 unIndent`
3038 JSON
3039 .stringify(
3040 {
3041 ok: true
3042 }
3043 );
3044 `,
3045
3046 // Don't check AssignmentExpression assignments
3047 unIndent`
3048 foo =
3049 bar =
3050 baz;
3051 `,
3052 unIndent`
3053 foo =
3054 bar =
3055 baz;
3056 `,
3057 unIndent`
3058 function foo() {
3059 const template = \`this indentation is not checked
3060 because it's part of a template literal.\`;
3061 }
3062 `,
3063 unIndent`
3064 function foo() {
3065 const template = \`the indentation of a \${
3066 node.type
3067 } node is checked.\`;
3068 }
3069 `,
3070 {
3071
3072 // https://github.com/eslint/eslint/issues/7320
3073 code: unIndent`
3074 JSON
3075 .stringify(
3076 {
3077 test: 'test'
3078 }
3079 );
3080 `,
3081 options: [4, { CallExpression: { arguments: 1 } }]
3082 },
3083 unIndent`
3084 [
3085 foo,
3086 // comment
3087 // another comment
3088 bar
3089 ]
3090 `,
3091 unIndent`
3092 if (foo) {
3093 /* comment */ bar();
3094 }
3095 `,
3096 unIndent`
3097 function foo() {
3098 return (
3099 1
3100 );
3101 }
3102 `,
3103 unIndent`
3104 function foo() {
3105 return (
3106 1
3107 )
3108 }
3109 `,
3110 unIndent`
3111 if (
3112 foo &&
3113 !(
3114 bar
3115 )
3116 ) {}
3117 `,
3118 {
3119
3120 // https://github.com/eslint/eslint/issues/6007
3121 code: unIndent`
3122 var abc = [
3123 (
3124 ''
3125 ),
3126 def,
3127 ]
3128 `,
3129 options: [2]
3130 },
3131 {
3132 code: unIndent`
3133 var abc = [
3134 (
3135 ''
3136 ),
3137 (
3138 'bar'
3139 )
3140 ]
3141 `,
3142 options: [2]
3143 },
3144 unIndent`
3145 function f() {
3146 return asyncCall()
3147 .then(
3148 'some string',
3149 [
3150 1,
3151 2,
3152 3
3153 ]
3154 );
3155 }
3156 `,
3157 {
3158
3159 // https://github.com/eslint/eslint/issues/6670
3160 code: unIndent`
3161 function f() {
3162 return asyncCall()
3163 .then(
3164 'some string',
3165 [
3166 1,
3167 2,
3168 3
3169 ]
3170 );
3171 }
3172 `,
3173 options: [4, { MemberExpression: 1 }]
3174 },
3175
3176 // https://github.com/eslint/eslint/issues/7242
3177 unIndent`
3178 var x = [
3179 [1],
3180 [2]
3181 ]
3182 `,
3183 unIndent`
3184 var y = [
3185 {a: 1},
3186 {b: 2}
3187 ]
3188 `,
3189 unIndent`
3190 foo(
3191 )
3192 `,
3193 {
3194
3195 // https://github.com/eslint/eslint/issues/7616
3196 code: unIndent`
3197 foo(
3198 bar,
3199 {
3200 baz: 1
3201 }
3202 )
3203 `,
3204 options: [4, { CallExpression: { arguments: "first" } }]
3205 },
3206 "new Foo",
3207 "new (Foo)",
3208 unIndent`
3209 if (Foo) {
3210 new Foo
3211 }
3212 `,
3213 {
3214 code: unIndent`
3215 var foo = 0, bar = 0, baz = 0;
3216 export {
3217 foo,
3218 bar,
3219 baz
3220 }
3221 `,
3222 parserOptions: { ecmaVersion: 6, sourceType: "module" }
3223 },
3224 {
3225 code: unIndent`
3226 foo
3227 ? bar
3228 : baz
3229 `,
3230 options: [4, { flatTernaryExpressions: true }]
3231 },
3232 {
3233 code: unIndent`
3234 foo ?
3235 bar :
3236 baz
3237 `,
3238 options: [4, { flatTernaryExpressions: true }]
3239 },
3240 {
3241 code: unIndent`
3242 foo ?
3243 bar
3244 : baz
3245 `,
3246 options: [4, { flatTernaryExpressions: true }]
3247 },
3248 {
3249 code: unIndent`
3250 foo
3251 ? bar :
3252 baz
3253 `,
3254 options: [4, { flatTernaryExpressions: true }]
3255 },
3256 {
3257 code: unIndent`
3258 foo
3259 ? bar
3260 : baz
3261 ? qux
3262 : foobar
3263 ? boop
3264 : beep
3265 `,
3266 options: [4, { flatTernaryExpressions: true }]
3267 },
3268 {
3269 code: unIndent`
3270 foo ?
3271 bar :
3272 baz ?
3273 qux :
3274 foobar ?
3275 boop :
3276 beep
3277 `,
3278 options: [4, { flatTernaryExpressions: true }]
3279 },
3280 {
3281 code: unIndent`
3282 var a =
3283 foo ? bar :
3284 baz ? qux :
3285 foobar ? boop :
3286 /*else*/ beep
3287 `,
3288 options: [4, { flatTernaryExpressions: true }]
3289 },
3290 {
3291 code: unIndent`
3292 var a = foo
3293 ? bar
3294 : baz
3295 `,
3296 options: [4, { flatTernaryExpressions: true }]
3297 },
3298 {
3299 code: unIndent`
3300 var a =
3301 foo
3302 ? bar
3303 : baz
3304 `,
3305 options: [4, { flatTernaryExpressions: true }]
3306 },
3307 {
3308 code: unIndent`
3309 a =
3310 foo ? bar :
3311 baz ? qux :
3312 foobar ? boop :
3313 /*else*/ beep
3314 `,
3315 options: [4, { flatTernaryExpressions: true }]
3316 },
3317 {
3318 code: unIndent`
3319 a = foo
3320 ? bar
3321 : baz
3322 `,
3323 options: [4, { flatTernaryExpressions: true }]
3324 },
3325 {
3326 code: unIndent`
3327 a =
3328 foo
3329 ? bar
3330 : baz
3331 `,
3332 options: [4, { flatTernaryExpressions: true }]
3333 },
3334 {
3335 code: unIndent`
3336 foo(
3337 foo ? bar :
3338 baz ? qux :
3339 foobar ? boop :
3340 /*else*/ beep
3341 )
3342 `,
3343 options: [4, { flatTernaryExpressions: true }]
3344 },
3345 {
3346 code: unIndent`
3347 function wrap() {
3348 return (
3349 foo ? bar :
3350 baz ? qux :
3351 foobar ? boop :
3352 /*else*/ beep
3353 )
3354 }
3355 `,
3356 options: [4, { flatTernaryExpressions: true }]
3357 },
3358 {
3359 code: unIndent`
3360 function wrap() {
3361 return foo
3362 ? bar
3363 : baz
3364 }
3365 `,
3366 options: [4, { flatTernaryExpressions: true }]
3367 },
3368 {
3369 code: unIndent`
3370 function wrap() {
3371 return (
3372 foo
3373 ? bar
3374 : baz
3375 )
3376 }
3377 `,
3378 options: [4, { flatTernaryExpressions: true }]
3379 },
3380 {
3381 code: unIndent`
3382 foo(
3383 foo
3384 ? bar
3385 : baz
3386 )
3387 `,
3388 options: [4, { flatTernaryExpressions: true }]
3389 },
3390 {
3391 code: unIndent`
3392 foo(foo
3393 ? bar
3394 : baz
3395 )
3396 `,
3397 options: [4, { flatTernaryExpressions: true }]
3398 },
3399 {
3400 code: unIndent`
3401 foo
3402 ? bar
3403 : baz
3404 ? qux
3405 : foobar
3406 ? boop
3407 : beep
3408 `,
3409 options: [4, { flatTernaryExpressions: false }]
3410 },
3411 {
3412 code: unIndent`
3413 foo ?
3414 bar :
3415 baz ?
3416 qux :
3417 foobar ?
3418 boop :
3419 beep
3420 `,
3421 options: [4, { flatTernaryExpressions: false }]
3422 },
3423 {
3424 code: "[,]",
3425 options: [2, { ArrayExpression: "first" }]
3426 },
3427 {
3428 code: "[,]",
3429 options: [2, { ArrayExpression: "off" }]
3430 },
3431 {
3432 code: unIndent`
3433 [
3434 ,
3435 foo
3436 ]
3437 `,
3438 options: [4, { ArrayExpression: "first" }]
3439 },
3440 {
3441 code: "[sparse, , array];",
3442 options: [2, { ArrayExpression: "first" }]
3443 },
3444 {
3445 code: unIndent`
3446 foo.bar('baz', function(err) {
3447 qux;
3448 });
3449 `,
3450 options: [2, { CallExpression: { arguments: "first" } }]
3451 },
3452 {
3453 code: unIndent`
3454 foo.bar(function() {
3455 cookies;
3456 }).baz(function() {
3457 cookies;
3458 });
3459 `,
3460 options: [2, { MemberExpression: 1 }]
3461 },
3462 {
3463 code: unIndent`
3464 foo.bar().baz(function() {
3465 cookies;
3466 }).qux(function() {
3467 cookies;
3468 });
3469 `,
3470 options: [2, { MemberExpression: 1 }]
3471 },
3472 {
3473 code: unIndent`
3474 (
3475 {
3476 foo: 1,
3477 baz: 2
3478 }
3479 );
3480 `,
3481 options: [2, { ObjectExpression: "first" }]
3482 },
3483 {
3484 code: unIndent`
3485 foo(() => {
3486 bar;
3487 }, () => {
3488 baz;
3489 })
3490 `,
3491 options: [4, { CallExpression: { arguments: "first" } }]
3492 },
3493 {
3494 code: unIndent`
3495 [ foo,
3496 bar ].forEach(function() {
3497 baz;
3498 })
3499 `,
3500 options: [2, { ArrayExpression: "first", MemberExpression: 1 }]
3501 },
3502 unIndent`
3503 foo = bar[
3504 baz
3505 ];
3506 `,
3507 {
3508 code: unIndent`
3509 foo[
3510 bar
3511 ];
3512 `,
3513 options: [4, { MemberExpression: 1 }]
3514 },
3515 {
3516 code: unIndent`
3517 foo[
3518 (
3519 bar
3520 )
3521 ];
3522 `,
3523 options: [4, { MemberExpression: 1 }]
3524 },
3525 unIndent`
3526 if (foo)
3527 bar;
3528 else if (baz)
3529 qux;
3530 `,
3531 unIndent`
3532 if (foo) bar()
3533
3534 ; [1, 2, 3].map(baz)
3535 `,
3536 unIndent`
3537 if (foo)
3538 ;
3539 `,
3540 "x => {}",
3541 {
3542 code: unIndent`
3543 import {foo}
3544 from 'bar';
3545 `,
3546 parserOptions: { ecmaVersion: 6, sourceType: "module" }
3547 },
3548 {
3549 code: "import 'foo'",
3550 parserOptions: { ecmaVersion: 6, sourceType: "module" }
3551 },
3552 {
3553 code: unIndent`
3554 import { foo,
3555 bar,
3556 baz,
3557 } from 'qux';
3558 `,
3559 options: [4, { ImportDeclaration: 1 }],
3560 parserOptions: { ecmaVersion: 6, sourceType: "module" }
3561 },
3562 {
3563 code: unIndent`
3564 import {
3565 foo,
3566 bar,
3567 baz,
3568 } from 'qux';
3569 `,
3570 options: [4, { ImportDeclaration: 1 }],
3571 parserOptions: { ecmaVersion: 6, sourceType: "module" }
3572 },
3573 {
3574 code: unIndent`
3575 import { apple as a,
3576 banana as b } from 'fruits';
3577 import { cat } from 'animals';
3578 `,
3579 options: [4, { ImportDeclaration: "first" }],
3580 parserOptions: { ecmaVersion: 6, sourceType: "module" }
3581 },
3582 {
3583 code: unIndent`
3584 import { declaration,
3585 can,
3586 be,
3587 turned } from 'off';
3588 `,
3589 options: [4, { ImportDeclaration: "off" }],
3590 parserOptions: { ecmaVersion: 6, sourceType: "module" }
3591 },
3592
3593 // https://github.com/eslint/eslint/issues/8455
3594 unIndent`
3595 (
3596 a
3597 ) => b => {
3598 c
3599 }
3600 `,
3601 unIndent`
3602 (
3603 a
3604 ) => b => c => d => {
3605 e
3606 }
3607 `,
3608 unIndent`
3609 (
3610 a
3611 ) =>
3612 (
3613 b
3614 ) => {
3615 c
3616 }
3617 `,
3618 unIndent`
3619 if (
3620 foo
3621 ) bar(
3622 baz
3623 );
3624 `,
3625 unIndent`
3626 if (foo)
3627 {
3628 bar();
3629 }
3630 `,
3631 unIndent`
3632 function foo(bar)
3633 {
3634 baz();
3635 }
3636 `,
3637 unIndent`
3638 () =>
3639 ({})
3640 `,
3641 unIndent`
3642 () =>
3643 (({}))
3644 `,
3645 unIndent`
3646 (
3647 () =>
3648 ({})
3649 )
3650 `,
3651 unIndent`
3652 var x = function foop(bar)
3653 {
3654 baz();
3655 }
3656 `,
3657 unIndent`
3658 var x = (bar) =>
3659 {
3660 baz();
3661 }
3662 `,
3663 unIndent`
3664 class Foo
3665 {
3666 constructor()
3667 {
3668 foo();
3669 }
3670
3671 bar()
3672 {
3673 baz();
3674 }
3675 }
3676 `,
3677 unIndent`
3678 class Foo
3679 extends Bar
3680 {
3681 constructor()
3682 {
3683 foo();
3684 }
3685
3686 bar()
3687 {
3688 baz();
3689 }
3690 }
3691 `,
3692 unIndent`
3693 (
3694 class Foo
3695 {
3696 constructor()
3697 {
3698 foo();
3699 }
3700
3701 bar()
3702 {
3703 baz();
3704 }
3705 }
3706 )
3707 `,
3708 {
3709 code: unIndent`
3710 switch (foo)
3711 {
3712 case 1:
3713 bar();
3714 }
3715 `,
3716 options: [4, { SwitchCase: 1 }]
3717 },
3718 unIndent`
3719 foo
3720 .bar(function() {
3721 baz
3722 })
3723 `,
3724 {
3725 code: unIndent`
3726 foo
3727 .bar(function() {
3728 baz
3729 })
3730 `,
3731 options: [4, { MemberExpression: 2 }]
3732 },
3733 unIndent`
3734 foo
3735 [bar](function() {
3736 baz
3737 })
3738 `,
3739 unIndent`
3740 foo.
3741 bar.
3742 baz
3743 `,
3744 {
3745 code: unIndent`
3746 foo
3747 .bar(function() {
3748 baz
3749 })
3750 `,
3751 options: [4, { MemberExpression: "off" }]
3752 },
3753 {
3754 code: unIndent`
3755 foo
3756 .bar(function() {
3757 baz
3758 })
3759 `,
3760 options: [4, { MemberExpression: "off" }]
3761 },
3762 {
3763 code: unIndent`
3764 foo
3765 [bar](function() {
3766 baz
3767 })
3768 `,
3769 options: [4, { MemberExpression: "off" }]
3770 },
3771 {
3772 code: unIndent`
3773 foo.
3774 bar.
3775 baz
3776 `,
3777 options: [4, { MemberExpression: "off" }]
3778 },
3779 {
3780 code: unIndent`
3781 foo = bar(
3782 ).baz(
3783 )
3784 `,
3785 options: [4, { MemberExpression: "off" }]
3786 },
3787 {
3788 code: unIndent`
3789 foo[
3790 bar ? baz :
3791 qux
3792 ]
3793 `,
3794 options: [4, { flatTernaryExpressions: true }]
3795 },
3796 {
3797 code: unIndent`
3798 function foo() {
3799 return foo ? bar :
3800 baz
3801 }
3802 `,
3803 options: [4, { flatTernaryExpressions: true }]
3804 },
3805 {
3806 code: unIndent`
3807 throw foo ? bar :
3808 baz
3809 `,
3810 options: [4, { flatTernaryExpressions: true }]
3811 },
3812 {
3813 code: unIndent`
3814 foo(
3815 bar
3816 ) ? baz :
3817 qux
3818 `,
3819 options: [4, { flatTernaryExpressions: true }]
3820 },
3821 unIndent`
3822 foo
3823 [
3824 bar
3825 ]
3826 .baz(function() {
3827 quz();
3828 })
3829 `,
3830 unIndent`
3831 [
3832 foo
3833 ][
3834 "map"](function() {
3835 qux();
3836 })
3837 `,
3838 unIndent`
3839 (
3840 a.b(function() {
3841 c;
3842 })
3843 )
3844 `,
3845 unIndent`
3846 (
3847 foo
3848 ).bar(function() {
3849 baz();
3850 })
3851 `,
3852 unIndent`
3853 new Foo(
3854 bar
3855 .baz
3856 .qux
3857 )
3858 `,
3859 unIndent`
3860 const foo = a.b(),
3861 longName =
3862 (baz(
3863 'bar',
3864 'bar'
3865 ));
3866 `,
3867 unIndent`
3868 const foo = a.b(),
3869 longName =
3870 (baz(
3871 'bar',
3872 'bar'
3873 ));
3874 `,
3875 unIndent`
3876 const foo = a.b(),
3877 longName =
3878 baz(
3879 'bar',
3880 'bar'
3881 );
3882 `,
3883 unIndent`
3884 const foo = a.b(),
3885 longName =
3886 baz(
3887 'bar',
3888 'bar'
3889 );
3890 `,
3891 unIndent`
3892 const foo = a.b(),
3893 longName
3894 = baz(
3895 'bar',
3896 'bar'
3897 );
3898 `,
3899 unIndent`
3900 const foo = a.b(),
3901 longName
3902 = baz(
3903 'bar',
3904 'bar'
3905 );
3906 `,
3907 unIndent`
3908 const foo = a.b(),
3909 longName =
3910 ('fff');
3911 `,
3912 unIndent`
3913 const foo = a.b(),
3914 longName =
3915 ('fff');
3916 `,
3917 unIndent`
3918 const foo = a.b(),
3919 longName
3920 = ('fff');
3921
3922 `,
3923 unIndent`
3924 const foo = a.b(),
3925 longName
3926 = ('fff');
3927
3928 `,
3929 unIndent`
3930 const foo = a.b(),
3931 longName =
3932 (
3933 'fff'
3934 );
3935 `,
3936 unIndent`
3937 const foo = a.b(),
3938 longName =
3939 (
3940 'fff'
3941 );
3942 `,
3943 unIndent`
3944 const foo = a.b(),
3945 longName
3946 =(
3947 'fff'
3948 );
3949 `,
3950 unIndent`
3951 const foo = a.b(),
3952 longName
3953 =(
3954 'fff'
3955 );
3956 `,
3957
3958
3959 //----------------------------------------------------------------------
3960 // Ignore Unknown Nodes
3961 //----------------------------------------------------------------------
3962
3963 {
3964 code: unIndent`
3965 interface Foo {
3966 bar: string;
3967 baz: number;
3968 }
3969 `,
3970 parser: parser("unknown-nodes/interface")
3971 },
3972 {
3973 code: unIndent`
3974 namespace Foo {
3975 const bar = 3,
3976 baz = 2;
3977
3978 if (true) {
3979 const bax = 3;
3980 }
3981 }
3982 `,
3983 parser: parser("unknown-nodes/namespace-valid")
3984 },
3985 {
3986 code: unIndent`
3987 abstract class Foo {
3988 public bar() {
3989 let aaa = 4,
3990 boo;
3991
3992 if (true) {
3993 boo = 3;
3994 }
3995
3996 boo = 3 + 2;
3997 }
3998 }
3999 `,
4000 parser: parser("unknown-nodes/abstract-class-valid")
4001 },
4002 {
4003 code: unIndent`
4004 function foo() {
4005 function bar() {
4006 abstract class X {
4007 public baz() {
4008 if (true) {
4009 qux();
4010 }
4011 }
4012 }
4013 }
4014 }
4015 `,
4016 parser: parser("unknown-nodes/functions-with-abstract-class-valid")
4017 },
4018 {
4019 code: unIndent`
4020 namespace Unknown {
4021 function foo() {
4022 function bar() {
4023 abstract class X {
4024 public baz() {
4025 if (true) {
4026 qux();
4027 }
4028 }
4029 }
4030 }
4031 }
4032 }
4033 `,
4034 parser: parser("unknown-nodes/namespace-with-functions-with-abstract-class-valid")
4035 },
4036 {
4037 code: unIndent`
4038 type httpMethod = 'GET'
4039 | 'POST'
4040 | 'PUT';
4041 `,
4042 options: [2, { VariableDeclarator: 0 }],
4043 parser: parser("unknown-nodes/variable-declarator-type-indent-two-spaces")
4044 },
4045 {
4046 code: unIndent`
4047 type httpMethod = 'GET'
4048 | 'POST'
4049 | 'PUT';
4050 `,
4051 options: [2, { VariableDeclarator: 1 }],
4052 parser: parser("unknown-nodes/variable-declarator-type-no-indent")
4053 },
4054 unIndent`
4055 foo(\`foo
4056 \`, {
4057 ok: true
4058 },
4059 {
4060 ok: false
4061 })
4062 `,
4063 unIndent`
4064 foo(tag\`foo
4065 \`, {
4066 ok: true
4067 },
4068 {
4069 ok: false
4070 }
4071 )
4072 `,
4073
4074 // https://github.com/eslint/eslint/issues/8815
4075 unIndent`
4076 async function test() {
4077 const {
4078 foo,
4079 bar,
4080 } = await doSomethingAsync(
4081 1,
4082 2,
4083 3,
4084 );
4085 }
4086 `,
4087 unIndent`
4088 function* test() {
4089 const {
4090 foo,
4091 bar,
4092 } = yield doSomethingAsync(
4093 1,
4094 2,
4095 3,
4096 );
4097 }
4098 `,
4099 unIndent`
4100 ({
4101 a: b
4102 } = +foo(
4103 bar
4104 ));
4105 `,
4106 unIndent`
4107 const {
4108 foo,
4109 bar,
4110 } = typeof foo(
4111 1,
4112 2,
4113 3,
4114 );
4115 `,
4116 unIndent`
4117 const {
4118 foo,
4119 bar,
4120 } = +(
4121 foo
4122 );
4123 `,
4124
4125 //----------------------------------------------------------------------
4126 // JSX tests
4127 // https://github.com/eslint/eslint/issues/8425
4128 // Some of the following tests are adapted from the the tests in eslint-plugin-react.
4129 // License: https://github.com/yannickcr/eslint-plugin-react/blob/7ca9841f22d599f447a27ef5b2a97def9229d6c8/LICENSE
4130 //----------------------------------------------------------------------
4131
4132 "<Foo a=\"b\" c=\"d\"/>;",
4133 unIndent`
4134 <Foo
4135 a="b"
4136 c="d"
4137 />;
4138 `,
4139 "var foo = <Bar a=\"b\" c=\"d\"/>;",
4140 unIndent`
4141 var foo = <Bar
4142 a="b"
4143 c="d"
4144 />;
4145 `,
4146 unIndent`
4147 var foo = (<Bar
4148 a="b"
4149 c="d"
4150 />);
4151 `,
4152 unIndent`
4153 var foo = (
4154 <Bar
4155 a="b"
4156 c="d"
4157 />
4158 );
4159 `,
4160 unIndent`
4161 <
4162 Foo
4163 a="b"
4164 c="d"
4165 />;
4166 `,
4167 unIndent`
4168 <Foo
4169 a="b"
4170 c="d"/>;
4171 `,
4172 unIndent`
4173 <
4174 Foo
4175 a="b"
4176 c="d"/>;
4177 `,
4178 "<a href=\"foo\">bar</a>;",
4179 unIndent`
4180 <a href="foo">
4181 bar
4182 </a>;
4183 `,
4184 unIndent`
4185 <a
4186 href="foo"
4187 >
4188 bar
4189 </a>;
4190 `,
4191 unIndent`
4192 <a
4193 href="foo">
4194 bar
4195 </a>;
4196 `,
4197 unIndent`
4198 <
4199 a
4200 href="foo">
4201 bar
4202 </a>;
4203 `,
4204 unIndent`
4205 <a
4206 href="foo">
4207 bar
4208 </
4209 a>;
4210 `,
4211 unIndent`
4212 <a
4213 href="foo">
4214 bar
4215 </a
4216 >;
4217 `,
4218 unIndent`
4219 var foo = <a href="bar">
4220 baz
4221 </a>;
4222 `,
4223 unIndent`
4224 var foo = <a
4225 href="bar"
4226 >
4227 baz
4228 </a>;
4229 `,
4230 unIndent`
4231 var foo = <a
4232 href="bar">
4233 baz
4234 </a>;
4235 `,
4236 unIndent`
4237 var foo = <
4238 a
4239 href="bar">
4240 baz
4241 </a>;
4242 `,
4243 unIndent`
4244 var foo = <a
4245 href="bar">
4246 baz
4247 </
4248 a>;
4249 `,
4250 unIndent`
4251 var foo = <a
4252 href="bar">
4253 baz
4254 </a
4255 >
4256 `,
4257 unIndent`
4258 var foo = (<a
4259 href="bar">
4260 baz
4261 </a>);
4262 `,
4263 unIndent`
4264 var foo = (
4265 <a href="bar">baz</a>
4266 );
4267 `,
4268 unIndent`
4269 var foo = (
4270 <a href="bar">
4271 baz
4272 </a>
4273 );
4274 `,
4275 unIndent`
4276 var foo = (
4277 <a
4278 href="bar">
4279 baz
4280 </a>
4281 );
4282 `,
4283 "var foo = <a href=\"bar\">baz</a>;",
4284 unIndent`
4285 <a>
4286 {
4287 }
4288 </a>
4289 `,
4290 unIndent`
4291 <a>
4292 {
4293 foo
4294 }
4295 </a>
4296 `,
4297 unIndent`
4298 function foo() {
4299 return (
4300 <a>
4301 {
4302 b.forEach(() => {
4303 // comment
4304 a = c
4305 .d()
4306 .e();
4307 })
4308 }
4309 </a>
4310 );
4311 }
4312 `,
4313 "<App></App>",
4314 unIndent`
4315 <App>
4316 </App>
4317 `,
4318 {
4319 code: unIndent`
4320 <App>
4321 <Foo />
4322 </App>
4323 `,
4324 options: [2]
4325 },
4326 {
4327 code: unIndent`
4328 <App>
4329 <Foo />
4330 </App>
4331 `,
4332 options: [0]
4333 },
4334 {
4335 code: unIndent`
4336 <App>
4337 \t<Foo />
4338 </App>
4339 `,
4340 options: ["tab"]
4341 },
4342 {
4343 code: unIndent`
4344 function App() {
4345 return <App>
4346 <Foo />
4347 </App>;
4348 }
4349 `,
4350 options: [2]
4351 },
4352 {
4353 code: unIndent`
4354 function App() {
4355 return (<App>
4356 <Foo />
4357 </App>);
4358 }
4359 `,
4360 options: [2]
4361 },
4362 {
4363 code: unIndent`
4364 function App() {
4365 return (
4366 <App>
4367 <Foo />
4368 </App>
4369 );
4370 }
4371 `,
4372 options: [2]
4373 },
4374 {
4375 code: unIndent`
4376 it(
4377 (
4378 <div>
4379 <span />
4380 </div>
4381 )
4382 )
4383 `,
4384 options: [2]
4385 },
4386 {
4387 code: unIndent`
4388 it(
4389 (<div>
4390 <span />
4391 <span />
4392 <span />
4393 </div>)
4394 )
4395 `,
4396 options: [2]
4397 },
4398 {
4399 code: unIndent`
4400 (
4401 <div>
4402 <span />
4403 </div>
4404 )
4405 `,
4406 options: [2]
4407 },
4408 {
4409 code: unIndent`
4410 {
4411 head.title &&
4412 <h1>
4413 {head.title}
4414 </h1>
4415 }
4416 `,
4417 options: [2]
4418 },
4419 {
4420 code: unIndent`
4421 {
4422 head.title &&
4423 <h1>
4424 {head.title}
4425 </h1>
4426 }
4427 `,
4428 options: [2]
4429 },
4430 {
4431 code: unIndent`
4432 {
4433 head.title && (
4434 <h1>
4435 {head.title}
4436 </h1>)
4437 }
4438 `,
4439 options: [2]
4440 },
4441 {
4442 code: unIndent`
4443 {
4444 head.title && (
4445 <h1>
4446 {head.title}
4447 </h1>
4448 )
4449 }
4450 `,
4451 options: [2]
4452 },
4453 {
4454 code: unIndent`
4455 [
4456 <div />,
4457 <div />
4458 ]
4459 `,
4460 options: [2]
4461 },
4462 unIndent`
4463 <div>
4464 {
4465 [
4466 <Foo />,
4467 <Bar />
4468 ]
4469 }
4470 </div>
4471 `,
4472 unIndent`
4473 <div>
4474 {foo &&
4475 [
4476 <Foo />,
4477 <Bar />
4478 ]
4479 }
4480 </div>
4481 `,
4482 unIndent`
4483 <div>
4484 bar <div>
4485 bar
4486 bar {foo}
4487 bar </div>
4488 </div>
4489 `,
4490 unIndent`
4491 foo ?
4492 <Foo /> :
4493 <Bar />
4494 `,
4495 unIndent`
4496 foo ?
4497 <Foo />
4498 : <Bar />
4499 `,
4500 unIndent`
4501 foo ?
4502 <Foo />
4503 :
4504 <Bar />
4505 `,
4506 unIndent`
4507 <div>
4508 {!foo ?
4509 <Foo
4510 onClick={this.onClick}
4511 />
4512 :
4513 <Bar
4514 onClick={this.onClick}
4515 />
4516 }
4517 </div>
4518 `,
4519 {
4520 code: unIndent`
4521 <span>
4522 {condition ?
4523 <Thing
4524 foo={\`bar\`}
4525 /> :
4526 <Thing/>
4527 }
4528 </span>
4529 `,
4530 options: [2]
4531 },
4532 {
4533 code: unIndent`
4534 <span>
4535 {condition ?
4536 <Thing
4537 foo={"bar"}
4538 /> :
4539 <Thing/>
4540 }
4541 </span>
4542 `,
4543 options: [2]
4544 },
4545 {
4546 code: unIndent`
4547 function foo() {
4548 <span>
4549 {condition ?
4550 <Thing
4551 foo={bar}
4552 /> :
4553 <Thing/>
4554 }
4555 </span>
4556 }
4557 `,
4558 options: [2]
4559 },
4560 unIndent`
4561 <App foo
4562 />
4563 `,
4564 {
4565 code: unIndent`
4566 <App
4567 foo
4568 />
4569 `,
4570 options: [2]
4571 },
4572 {
4573 code: unIndent`
4574 <App
4575 foo
4576 />
4577 `,
4578 options: [0]
4579 },
4580 {
4581 code: unIndent`
4582 <App
4583 \tfoo
4584 />
4585 `,
4586 options: ["tab"]
4587 },
4588 unIndent`
4589 <App
4590 foo
4591 />
4592 `,
4593 unIndent`
4594 <App
4595 foo
4596 ></App>
4597 `,
4598 {
4599 code: unIndent`
4600 <App
4601 foo={function() {
4602 console.log('bar');
4603 }}
4604 />
4605 `,
4606 options: [2]
4607 },
4608 {
4609 code: unIndent`
4610 <App foo={function() {
4611 console.log('bar');
4612 }}
4613 />
4614 `,
4615 options: [2]
4616 },
4617 {
4618 code: unIndent`
4619 var x = function() {
4620 return <App
4621 foo={function() {
4622 console.log('bar');
4623 }}
4624 />
4625 }
4626 `,
4627 options: [2]
4628 },
4629 {
4630 code: unIndent`
4631 var x = <App
4632 foo={function() {
4633 console.log('bar');
4634 }}
4635 />
4636 `,
4637 options: [2]
4638 },
4639 {
4640 code: unIndent`
4641 <Provider
4642 store
4643 >
4644 <App
4645 foo={function() {
4646 console.log('bar');
4647 }}
4648 />
4649 </Provider>
4650 `,
4651 options: [2]
4652 },
4653 {
4654 code: unIndent`
4655 <Provider
4656 store
4657 >
4658 {baz && <App
4659 foo={function() {
4660 console.log('bar');
4661 }}
4662 />}
4663 </Provider>
4664 `,
4665 options: [2]
4666 },
4667 {
4668 code: unIndent`
4669 <App
4670 \tfoo
4671 />
4672 `,
4673 options: ["tab"]
4674 },
4675 {
4676 code: unIndent`
4677 <App
4678 \tfoo
4679 ></App>
4680 `,
4681 options: ["tab"]
4682 },
4683 {
4684 code: unIndent`
4685 <App foo={function() {
4686 \tconsole.log('bar');
4687 }}
4688 />
4689 `,
4690 options: ["tab"]
4691 },
4692 {
4693 code: unIndent`
4694 var x = <App
4695 \tfoo={function() {
4696 \t\tconsole.log('bar');
4697 \t}}
4698 />
4699 `,
4700 options: ["tab"]
4701 },
4702 unIndent`
4703 <App
4704 foo />
4705 `,
4706 unIndent`
4707 <div>
4708 unrelated{
4709 foo
4710 }
4711 </div>
4712 `,
4713 unIndent`
4714 <div>unrelated{
4715 foo
4716 }
4717 </div>
4718 `,
4719 unIndent`
4720 <
4721 foo
4722 .bar
4723 .baz
4724 >
4725 foo
4726 </
4727 foo.
4728 bar.
4729 baz
4730 >
4731 `,
4732 unIndent`
4733 <
4734 input
4735 type=
4736 "number"
4737 />
4738 `,
4739 unIndent`
4740 <
4741 input
4742 type=
4743 {'number'}
4744 />
4745 `,
4746 unIndent`
4747 <
4748 input
4749 type
4750 ="number"
4751 />
4752 `,
4753 unIndent`
4754 foo ? (
4755 bar
4756 ) : (
4757 baz
4758 )
4759 `,
4760 unIndent`
4761 foo ? (
4762 <div>
4763 </div>
4764 ) : (
4765 <span>
4766 </span>
4767 )
4768 `,
4769 unIndent`
4770 <div>
4771 {
4772 /* foo */
4773 }
4774 </div>
4775 `,
4776
4777 /*
4778 * JSX Fragments
4779 * https://github.com/eslint/eslint/issues/12208
4780 */
4781 unIndent`
4782 <>
4783 <A />
4784 </>
4785 `,
4786 unIndent`
4787 <
4788 >
4789 <A />
4790 </>
4791 `,
4792 unIndent`
4793 <>
4794 <A />
4795 <
4796 />
4797 `,
4798 unIndent`
4799 <>
4800 <A />
4801 </
4802 >
4803 `,
4804 unIndent`
4805 <
4806 >
4807 <A />
4808 </
4809 >
4810 `,
4811 unIndent`
4812 <
4813 >
4814 <A />
4815 <
4816 />
4817 `,
4818 unIndent`
4819 < // Comment
4820 >
4821 <A />
4822 </>
4823 `,
4824 unIndent`
4825 <
4826 // Comment
4827 >
4828 <A />
4829 </>
4830 `,
4831 unIndent`
4832 <
4833 // Comment
4834 >
4835 <A />
4836 </>
4837 `,
4838 unIndent`
4839 <>
4840 <A />
4841 < // Comment
4842 />
4843 `,
4844 unIndent`
4845 <>
4846 <A />
4847 <
4848 // Comment
4849 />
4850 `,
4851 unIndent`
4852 <>
4853 <A />
4854 <
4855 // Comment
4856 />
4857 `,
4858 unIndent`
4859 <>
4860 <A />
4861 </ // Comment
4862 >
4863 `,
4864 unIndent`
4865 <>
4866 <A />
4867 </
4868 // Comment
4869 >
4870 `,
4871 unIndent`
4872 <>
4873 <A />
4874 </
4875 // Comment
4876 >
4877 `,
4878 unIndent`
4879 < /* Comment */
4880 >
4881 <A />
4882 </>
4883 `,
4884 unIndent`
4885 <
4886 /* Comment */
4887 >
4888 <A />
4889 </>
4890 `,
4891 unIndent`
4892 <
4893 /* Comment */
4894 >
4895 <A />
4896 </>
4897 `,
4898 unIndent`
4899 <
4900 /*
4901 * Comment
4902 */
4903 >
4904 <A />
4905 </>
4906 `,
4907 unIndent`
4908 <
4909 /*
4910 * Comment
4911 */
4912 >
4913 <A />
4914 </>
4915 `,
4916 unIndent`
4917 <>
4918 <A />
4919 < /* Comment */
4920 />
4921 `,
4922 unIndent`
4923 <>
4924 <A />
4925 <
4926 /* Comment */ />
4927 `,
4928 unIndent`
4929 <>
4930 <A />
4931 <
4932 /* Comment */ />
4933 `,
4934 unIndent`
4935 <>
4936 <A />
4937 <
4938 /* Comment */
4939 />
4940 `,
4941 unIndent`
4942 <>
4943 <A />
4944 <
4945 /* Comment */
4946 />
4947 `,
4948 unIndent`
4949 <>
4950 <A />
4951 </ /* Comment */
4952 >
4953 `,
4954 unIndent`
4955 <>
4956 <A />
4957 </
4958 /* Comment */ >
4959 `,
4960 unIndent`
4961 <>
4962 <A />
4963 </
4964 /* Comment */ >
4965 `,
4966 unIndent`
4967 <>
4968 <A />
4969 </
4970 /* Comment */
4971 >
4972 `,
4973 unIndent`
4974 <>
4975 <A />
4976 </
4977 /* Comment */
4978 >
4979 `,
4980
4981 // https://github.com/eslint/eslint/issues/8832
4982 unIndent`
4983 <div>
4984 {
4985 (
4986 1
4987 )
4988 }
4989 </div>
4990 `,
4991 unIndent`
4992 function A() {
4993 return (
4994 <div>
4995 {
4996 b && (
4997 <div>
4998 </div>
4999 )
5000 }
5001 </div>
5002 );
5003 }
5004 `,
5005 unIndent`
5006 <div>foo
5007 <div>bar</div>
5008 </div>
5009 `,
5010 unIndent`
5011 <small>Foo bar&nbsp;
5012 <a>baz qux</a>.
5013 </small>
5014 `,
5015 unIndent`
5016 <div
5017 {...props}
5018 />
5019 `,
5020 unIndent`
5021 <div
5022 {
5023 ...props
5024 }
5025 />
5026 `,
5027 {
5028 code: unIndent`
5029 a(b
5030 , c
5031 )
5032 `,
5033 options: [2, { CallExpression: { arguments: "off" } }]
5034 },
5035 {
5036 code: unIndent`
5037 a(
5038 new B({
5039 c,
5040 })
5041 );
5042 `,
5043 options: [2, { CallExpression: { arguments: "off" } }]
5044 },
5045 {
5046 code: unIndent`
5047 foo
5048 ? bar
5049 : baz
5050 `,
5051 options: [4, { ignoredNodes: ["ConditionalExpression"] }]
5052 },
5053 {
5054 code: unIndent`
5055 class Foo {
5056 foo() {
5057 bar();
5058 }
5059 }
5060 `,
5061 options: [4, { ignoredNodes: ["ClassBody"] }]
5062 },
5063 {
5064 code: unIndent`
5065 class Foo {
5066 foo() {
5067 bar();
5068 }
5069 }
5070 `,
5071 options: [4, { ignoredNodes: ["ClassBody", "BlockStatement"] }]
5072 },
5073 {
5074 code: unIndent`
5075 foo({
5076 bar: 1
5077 },
5078 {
5079 baz: 2
5080 },
5081 {
5082 qux: 3
5083 })
5084 `,
5085 options: [4, { ignoredNodes: ["CallExpression > ObjectExpression"] }]
5086 },
5087 {
5088 code: unIndent`
5089 foo
5090 .bar
5091 `,
5092 options: [4, { ignoredNodes: ["MemberExpression"] }]
5093 },
5094 {
5095 code: unIndent`
5096 $(function() {
5097
5098 foo();
5099 bar();
5100
5101 });
5102 `,
5103 options: [4, {
5104 ignoredNodes: ["Program > ExpressionStatement > CallExpression[callee.name='$'] > FunctionExpression > BlockStatement"]
5105 }]
5106 },
5107 {
5108 code: unIndent`
5109 <Foo
5110 bar="1" />
5111 `,
5112 options: [4, { ignoredNodes: ["JSXOpeningElement"] }]
5113 },
5114 {
5115 code: unIndent`
5116 foo &&
5117 <Bar
5118 >
5119 </Bar>
5120 `,
5121 options: [4, { ignoredNodes: ["JSXElement", "JSXOpeningElement"] }]
5122 },
5123 {
5124 code: unIndent`
5125 (function($) {
5126 $(function() {
5127 foo;
5128 });
5129 }())
5130 `,
5131 options: [4, { ignoredNodes: ["ExpressionStatement > CallExpression > FunctionExpression.callee > BlockStatement"] }]
5132 },
5133 {
5134 code: unIndent`
5135 const value = (
5136 condition ?
5137 valueIfTrue :
5138 valueIfFalse
5139 );
5140 `,
5141 options: [4, { ignoredNodes: ["ConditionalExpression"] }]
5142 },
5143 {
5144 code: unIndent`
5145 var a = 0, b = 0, c = 0;
5146 export default foo(
5147 a,
5148 b, {
5149 c
5150 }
5151 )
5152 `,
5153 options: [4, { ignoredNodes: ["ExportDefaultDeclaration > CallExpression > ObjectExpression"] }],
5154 parserOptions: { ecmaVersion: 6, sourceType: "module" }
5155 },
5156 {
5157 code: unIndent`
5158 foobar = baz
5159 ? qux
5160 : boop
5161 `,
5162 options: [4, { ignoredNodes: ["ConditionalExpression"] }]
5163 },
5164 {
5165 code: unIndent`
5166 \`
5167 SELECT
5168 \${
5169 foo
5170 } FROM THE_DATABASE
5171 \`
5172 `,
5173 options: [4, { ignoredNodes: ["TemplateLiteral"] }]
5174 },
5175 {
5176 code: unIndent`
5177 <foo
5178 prop='bar'
5179 >
5180 Text
5181 </foo>
5182 `,
5183 options: [4, { ignoredNodes: ["JSXOpeningElement"] }]
5184 },
5185 {
5186 code: unIndent`
5187 {
5188 \tvar x = 1,
5189 \t y = 2;
5190 }
5191 `,
5192 options: ["tab"]
5193 },
5194 {
5195 code: unIndent`
5196 var x = 1,
5197 y = 2;
5198 var z;
5199 `,
5200 options: ["tab", { ignoredNodes: ["VariableDeclarator"] }]
5201 },
5202 {
5203 code: unIndent`
5204 [
5205 foo(),
5206 bar
5207 ]
5208 `,
5209 options: ["tab", { ArrayExpression: "first", ignoredNodes: ["CallExpression"] }]
5210 },
5211 {
5212 code: unIndent`
5213 if (foo) {
5214 doSomething();
5215
5216 // Intentionally unindented comment
5217 doSomethingElse();
5218 }
5219 `,
5220 options: [4, { ignoreComments: true }]
5221 },
5222 {
5223 code: unIndent`
5224 if (foo) {
5225 doSomething();
5226
5227 /* Intentionally unindented comment */
5228 doSomethingElse();
5229 }
5230 `,
5231 options: [4, { ignoreComments: true }]
5232 },
5233 unIndent`
5234 const obj = {
5235 foo () {
5236 return condition ? // comment
5237 1 :
5238 2
5239 }
5240 }
5241 `,
5242
5243 //----------------------------------------------------------------------
5244 // Comment alignment tests
5245 //----------------------------------------------------------------------
5246 unIndent`
5247 if (foo) {
5248 // Comment can align with code immediately above even if "incorrect" alignment
5249 doSomething();
5250 }
5251 `,
5252 unIndent`
5253 if (foo) {
5254 doSomething();
5255 // Comment can align with code immediately below even if "incorrect" alignment
5256 }
5257 `,
5258 unIndent`
5259 if (foo) {
5260 // Comment can be in correct alignment even if not aligned with code above/below
5261 }
5262 `,
5263 unIndent`
5264 if (foo) {
5265
5266 // Comment can be in correct alignment even if gaps between (and not aligned with) code above/below
5267
5268 }
5269 `,
5270 unIndent`
5271 [{
5272 foo
5273 },
5274
5275 // Comment between nodes
5276
5277 {
5278 bar
5279 }];
5280 `,
5281 unIndent`
5282 [{
5283 foo
5284 },
5285
5286 // Comment between nodes
5287
5288 { // comment
5289 bar
5290 }];
5291 `,
5292 unIndent`
5293 let foo
5294
5295 // comment
5296
5297 ;(async () => {})()
5298 `,
5299 unIndent`
5300 let foo
5301 // comment
5302
5303 ;(async () => {})()
5304 `,
5305 unIndent`
5306 let foo
5307
5308 // comment
5309 ;(async () => {})()
5310 `,
5311 unIndent`
5312 let foo
5313 // comment
5314 ;(async () => {})()
5315 `,
5316 unIndent`
5317 let foo
5318
5319 /* comment */;
5320
5321 (async () => {})()
5322 `,
5323 unIndent`
5324 let foo
5325 /* comment */;
5326
5327 (async () => {})()
5328 `,
5329 unIndent`
5330 let foo
5331
5332 /* comment */;
5333 (async () => {})()
5334 `,
5335 unIndent`
5336 let foo
5337 /* comment */;
5338 (async () => {})()
5339 `,
5340 unIndent`
5341 let foo
5342 /* comment */;
5343
5344 (async () => {})()
5345 `,
5346 unIndent`
5347 let foo
5348 /* comment */;
5349 (async () => {})()
5350 `,
5351 unIndent`
5352 // comment
5353
5354 ;(async () => {})()
5355 `,
5356 unIndent`
5357 // comment
5358 ;(async () => {})()
5359 `,
5360 unIndent`
5361 {
5362 let foo
5363
5364 // comment
5365
5366 ;(async () => {})()
5367 }
5368 `,
5369 unIndent`
5370 {
5371 let foo
5372 // comment
5373 ;(async () => {})()
5374 }
5375 `,
5376 unIndent`
5377 {
5378 // comment
5379
5380 ;(async () => {})()
5381 }
5382 `,
5383 unIndent`
5384 {
5385 // comment
5386 ;(async () => {})()
5387 }
5388 `,
5389 unIndent`
5390 const foo = 1
5391 const bar = foo
5392
5393 /* comment */
5394
5395 ;[1, 2, 3].forEach(() => {})
5396 `,
5397 unIndent`
5398 const foo = 1
5399 const bar = foo
5400 /* comment */
5401
5402 ;[1, 2, 3].forEach(() => {})
5403 `,
5404 unIndent`
5405 const foo = 1
5406 const bar = foo
5407
5408 /* comment */
5409 ;[1, 2, 3].forEach(() => {})
5410 `,
5411 unIndent`
5412 const foo = 1
5413 const bar = foo
5414 /* comment */
5415 ;[1, 2, 3].forEach(() => {})
5416 `,
5417 unIndent`
5418 const foo = 1
5419 const bar = foo
5420
5421 /* comment */;
5422
5423 [1, 2, 3].forEach(() => {})
5424 `,
5425 unIndent`
5426 const foo = 1
5427 const bar = foo
5428 /* comment */;
5429
5430 [1, 2, 3].forEach(() => {})
5431 `,
5432 unIndent`
5433 const foo = 1
5434 const bar = foo
5435
5436 /* comment */;
5437 [1, 2, 3].forEach(() => {})
5438 `,
5439 unIndent`
5440 const foo = 1
5441 const bar = foo
5442 /* comment */;
5443 [1, 2, 3].forEach(() => {})
5444 `,
5445 unIndent`
5446 const foo = 1
5447 const bar = foo
5448 /* comment */;
5449
5450 [1, 2, 3].forEach(() => {})
5451 `,
5452 unIndent`
5453 const foo = 1
5454 const bar = foo
5455 /* comment */;
5456 [1, 2, 3].forEach(() => {})
5457 `,
5458 unIndent`
5459 /* comment */
5460
5461 ;[1, 2, 3].forEach(() => {})
5462 `,
5463 unIndent`
5464 /* comment */
5465 ;[1, 2, 3].forEach(() => {})
5466 `,
5467 unIndent`
5468 {
5469 const foo = 1
5470 const bar = foo
5471
5472 /* comment */
5473
5474 ;[1, 2, 3].forEach(() => {})
5475 }
5476 `,
5477 unIndent`
5478 {
5479 const foo = 1
5480 const bar = foo
5481 /* comment */
5482 ;[1, 2, 3].forEach(() => {})
5483 }
5484 `,
5485 unIndent`
5486 {
5487 /* comment */
5488
5489 ;[1, 2, 3].forEach(() => {})
5490 }
5491 `,
5492 unIndent`
5493 {
5494 /* comment */
5495 ;[1, 2, 3].forEach(() => {})
5496 }
5497 `,
5498
5499 // import expressions
5500 {
5501 code: unIndent`
5502 import(
5503 // before
5504 source
5505 // after
5506 )
5507 `,
5508 parserOptions: { ecmaVersion: 2020 }
5509 },
5510
5511 // https://github.com/eslint/eslint/issues/12122
5512 {
5513 code: unIndent`
5514 foo(() => {
5515 tag\`
5516 multiline
5517 template
5518 literal
5519 \`(() => {
5520 bar();
5521 });
5522 });
5523 `,
5524 parserOptions: { ecmaVersion: 2015 }
5525 },
5526 {
5527 code: unIndent`
5528 {
5529 tag\`
5530 multiline
5531 template
5532 \${a} \${b}
5533 literal
5534 \`(() => {
5535 bar();
5536 });
5537 }
5538 `,
5539 parserOptions: { ecmaVersion: 2015 }
5540 },
5541 {
5542 code: unIndent`
5543 foo(() => {
5544 tagOne\`
5545 multiline
5546 template
5547 literal
5548 \${a} \${b}
5549 \`(() => {
5550 tagTwo\`
5551 multiline
5552 template
5553 literal
5554 \`(() => {
5555 bar();
5556 });
5557
5558 baz();
5559 });
5560 });
5561 `,
5562 parserOptions: { ecmaVersion: 2015 }
5563 },
5564 {
5565 code: unIndent`
5566 {
5567 tagOne\`
5568 \${a} \${b}
5569 multiline
5570 template
5571 literal
5572 \`(() => {
5573 tagTwo\`
5574 multiline
5575 template
5576 literal
5577 \`(() => {
5578 bar();
5579 });
5580
5581 baz();
5582 });
5583 };
5584 `,
5585 parserOptions: { ecmaVersion: 2015 }
5586 },
5587 {
5588 code: unIndent`
5589 tagOne\`multiline
5590 \${a} \${b}
5591 template
5592 literal
5593 \`(() => {
5594 foo();
5595
5596 tagTwo\`multiline
5597 template
5598 literal
5599 \`({
5600 bar: 1,
5601 baz: 2
5602 });
5603 });
5604 `,
5605 parserOptions: { ecmaVersion: 2015 }
5606 },
5607 {
5608 code: unIndent`
5609 tagOne\`multiline
5610 template
5611 literal
5612 \${a} \${b}\`({
5613 foo: 1,
5614 bar: tagTwo\`multiline
5615 template
5616 literal\`(() => {
5617
5618 baz();
5619 })
5620 });
5621 `,
5622 parserOptions: { ecmaVersion: 2015 }
5623 },
5624 {
5625 code: unIndent`
5626 foo.bar\` template literal \`(() => {
5627 baz();
5628 })
5629 `,
5630 parserOptions: { ecmaVersion: 2015 }
5631 },
5632 {
5633 code: unIndent`
5634 foo.bar.baz\` template literal \`(() => {
5635 baz();
5636 })
5637 `,
5638 parserOptions: { ecmaVersion: 2015 }
5639 },
5640 {
5641 code: unIndent`
5642 foo
5643 .bar\` template
5644 literal \`(() => {
5645 baz();
5646 })
5647 `,
5648 parserOptions: { ecmaVersion: 2015 }
5649 },
5650 {
5651 code: unIndent`
5652 foo
5653 .bar
5654 .baz\` template
5655 literal \`(() => {
5656 baz();
5657 })
5658 `,
5659 parserOptions: { ecmaVersion: 2015 }
5660 },
5661 {
5662 code: unIndent`
5663 foo.bar\`
5664 \${a} \${b}
5665 \`(() => {
5666 baz();
5667 })
5668 `,
5669 parserOptions: { ecmaVersion: 2015 }
5670 },
5671 {
5672 code: unIndent`
5673 foo.bar1.bar2\`
5674 \${a} \${b}
5675 \`(() => {
5676 baz();
5677 })
5678 `,
5679 parserOptions: { ecmaVersion: 2015 }
5680 },
5681 {
5682 code: unIndent`
5683 foo
5684 .bar1
5685 .bar2\`
5686 \${a} \${b}
5687 \`(() => {
5688 baz();
5689 })
5690 `,
5691 parserOptions: { ecmaVersion: 2015 }
5692 },
5693 {
5694 code: unIndent`
5695 foo
5696 .bar\`
5697 \${a} \${b}
5698 \`(() => {
5699 baz();
5700 })
5701 `,
5702 parserOptions: { ecmaVersion: 2015 }
5703 },
5704 {
5705 code: unIndent`
5706 foo
5707 .test\`
5708 \${a} \${b}
5709 \`(() => {
5710 baz();
5711 })
5712 `,
5713 options: [4, { MemberExpression: 0 }],
5714 parserOptions: { ecmaVersion: 2015 }
5715 },
5716 {
5717 code: unIndent`
5718 foo
5719 .test\`
5720 \${a} \${b}
5721 \`(() => {
5722 baz();
5723 })
5724 `,
5725 options: [4, { MemberExpression: 2 }],
5726 parserOptions: { ecmaVersion: 2015 }
5727 },
5728 {
5729 code: unIndent`
5730 const foo = async (arg1,
5731 arg2) =>
5732 {
5733 return arg1 + arg2;
5734 }
5735 `,
5736 options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }]
5737 },
5738 {
5739 code: unIndent`
5740 const foo = async /* some comments */(arg1,
5741 arg2) =>
5742 {
5743 return arg1 + arg2;
5744 }
5745 `,
5746 options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }]
5747 },
5748 {
5749 code: unIndent`
5750 const a = async
5751 b => {}
5752 `,
5753 options: [2]
5754 },
5755 {
5756 code: unIndent`
5757 const foo = (arg1,
5758 arg2) => async (arr1,
5759 arr2) =>
5760 {
5761 return arg1 + arg2;
5762 }
5763 `,
5764 options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }]
5765 },
5766 {
5767 code: unIndent`
5768 const foo = async (arg1,
5769 arg2) =>
5770 {
5771 return arg1 + arg2;
5772 }
5773 `,
5774 options: [2]
5775 },
5776 {
5777 code: unIndent`
5778 const foo = async /*comments*/(arg1,
5779 arg2) =>
5780 {
5781 return arg1 + arg2;
5782 }
5783 `,
5784 options: [2]
5785 },
5786 {
5787 code: unIndent`
5788 const foo = async (arg1,
5789 arg2) =>
5790 {
5791 return arg1 + arg2;
5792 }
5793 `,
5794 options: [2, { FunctionDeclaration: { parameters: 4 }, FunctionExpression: { parameters: 4 } }]
5795 },
5796 {
5797 code: unIndent`
5798 const foo = (arg1,
5799 arg2) =>
5800 {
5801 return arg1 + arg2;
5802 }
5803 `,
5804 options: [2, { FunctionDeclaration: { parameters: 4 }, FunctionExpression: { parameters: 4 } }]
5805 },
5806 {
5807 code: unIndent`
5808 async function fn(ar1,
5809 ar2){}
5810 `,
5811 options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }]
5812 },
5813 {
5814 code: unIndent`
5815 async function /* some comments */ fn(ar1,
5816 ar2){}
5817 `,
5818 options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }]
5819 },
5820 {
5821 code: unIndent`
5822 async /* some comments */ function fn(ar1,
5823 ar2){}
5824 `,
5825 options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }]
5826 }
5827 ],
5828
5829 invalid: [
5830 {
5831 code: unIndent`
5832 var a = b;
5833 if (a) {
5834 b();
5835 }
5836 `,
5837 output: unIndent`
5838 var a = b;
5839 if (a) {
5840 b();
5841 }
5842 `,
5843 options: [2],
5844 errors: expectedErrors([[3, 2, 0, "Identifier"]])
5845 },
5846 {
5847 code: unIndent`
5848 require('http').request({hostname: 'localhost',
5849 port: 80}, function(res) {
5850 res.end();
5851 });
5852 `,
5853 output: unIndent`
5854 require('http').request({hostname: 'localhost',
5855 port: 80}, function(res) {
5856 res.end();
5857 });
5858 `,
5859 options: [2],
5860 errors: expectedErrors([[2, 2, 18, "Identifier"], [3, 2, 4, "Identifier"], [4, 0, 2, "Punctuator"]])
5861 },
5862 {
5863 code: unIndent`
5864 if (array.some(function(){
5865 return true;
5866 })) {
5867 a++; // ->
5868 b++;
5869 c++; // <-
5870 }
5871 `,
5872 output: unIndent`
5873 if (array.some(function(){
5874 return true;
5875 })) {
5876 a++; // ->
5877 b++;
5878 c++; // <-
5879 }
5880 `,
5881 options: [2],
5882 errors: expectedErrors([[4, 2, 0, "Identifier"], [6, 2, 4, "Identifier"]])
5883 },
5884 {
5885 code: unIndent`
5886 if (a){
5887 \tb=c;
5888 \t\tc=d;
5889 e=f;
5890 }
5891 `,
5892 output: unIndent`
5893 if (a){
5894 \tb=c;
5895 \tc=d;
5896 \te=f;
5897 }
5898 `,
5899 options: ["tab"],
5900 errors: expectedErrors("tab", [[3, 1, 2, "Identifier"], [4, 1, 0, "Identifier"]])
5901 },
5902 {
5903 code: unIndent`
5904 if (a){
5905 b=c;
5906 c=d;
5907 e=f;
5908 }
5909 `,
5910 output: unIndent`
5911 if (a){
5912 b=c;
5913 c=d;
5914 e=f;
5915 }
5916 `,
5917 options: [4],
5918 errors: expectedErrors([[3, 4, 6, "Identifier"], [4, 4, 1, "Identifier"]])
5919 },
5920 {
5921 code: fixture,
5922 output: fixedFixture,
5923 options: [2, { SwitchCase: 1, MemberExpression: 1, CallExpression: { arguments: "off" } }],
5924 errors: expectedErrors([
5925 [5, 2, 4, "Keyword"],
5926 [6, 2, 0, "Line"],
5927 [10, 4, 6, "Punctuator"],
5928 [11, 2, 4, "Punctuator"],
5929
5930 [15, 4, 2, "Identifier"],
5931 [16, 2, 4, "Punctuator"],
5932 [23, 2, 4, "Punctuator"],
5933 [29, 2, 4, "Keyword"],
5934 [30, 4, 6, "Identifier"],
5935 [36, 4, 6, "Identifier"],
5936 [38, 2, 4, "Punctuator"],
5937 [39, 4, 2, "Identifier"],
5938 [40, 2, 0, "Punctuator"],
5939 [54, 2, 4, "Punctuator"],
5940 [114, 4, 2, "Keyword"],
5941 [120, 4, 6, "Keyword"],
5942 [124, 4, 2, "Keyword"],
5943 [134, 4, 6, "Keyword"],
5944 [138, 2, 3, "Punctuator"],
5945 [139, 2, 3, "Punctuator"],
5946 [143, 4, 0, "Identifier"],
5947 [144, 6, 2, "Punctuator"],
5948 [145, 6, 2, "Punctuator"],
5949 [151, 4, 6, "Identifier"],
5950 [152, 6, 8, "Punctuator"],
5951 [153, 6, 8, "Punctuator"],
5952 [159, 4, 2, "Identifier"],
5953 [161, 4, 6, "Identifier"],
5954 [175, 2, 0, "Identifier"],
5955 [177, 2, 4, "Identifier"],
5956 [189, 2, 0, "Keyword"],
5957 [192, 6, 18, "Identifier"],
5958 [193, 6, 4, "Identifier"],
5959 [195, 6, 8, "Identifier"],
5960 [228, 5, 4, "Identifier"],
5961 [231, 3, 2, "Punctuator"],
5962 [245, 0, 2, "Punctuator"],
5963 [248, 0, 2, "Punctuator"],
5964 [304, 4, 6, "Identifier"],
5965 [306, 4, 8, "Identifier"],
5966 [307, 2, 4, "Punctuator"],
5967 [308, 2, 4, "Identifier"],
5968 [311, 4, 6, "Identifier"],
5969 [312, 4, 6, "Identifier"],
5970 [313, 4, 6, "Identifier"],
5971 [314, 2, 4, "Punctuator"],
5972 [315, 2, 4, "Identifier"],
5973 [318, 4, 6, "Identifier"],
5974 [319, 4, 6, "Identifier"],
5975 [320, 4, 6, "Identifier"],
5976 [321, 2, 4, "Punctuator"],
5977 [322, 2, 4, "Identifier"],
5978 [326, 2, 1, "Numeric"],
5979 [327, 2, 1, "Numeric"],
5980 [328, 2, 1, "Numeric"],
5981 [329, 2, 1, "Numeric"],
5982 [330, 2, 1, "Numeric"],
5983 [331, 2, 1, "Numeric"],
5984 [332, 2, 1, "Numeric"],
5985 [333, 2, 1, "Numeric"],
5986 [334, 2, 1, "Numeric"],
5987 [335, 2, 1, "Numeric"],
5988 [340, 2, 4, "Identifier"],
5989 [341, 2, 0, "Identifier"],
5990 [344, 2, 4, "Identifier"],
5991 [345, 2, 0, "Identifier"],
5992 [348, 2, 4, "Identifier"],
5993 [349, 2, 0, "Identifier"],
5994 [355, 2, 0, "Identifier"],
5995 [357, 2, 4, "Identifier"],
5996 [361, 4, 6, "Identifier"],
5997 [362, 2, 4, "Punctuator"],
5998 [363, 2, 4, "Identifier"],
5999 [368, 2, 0, "Keyword"],
6000 [370, 2, 4, "Keyword"],
6001 [374, 4, 6, "Keyword"],
6002 [376, 4, 2, "Keyword"],
6003 [383, 2, 0, "Identifier"],
6004 [385, 2, 4, "Identifier"],
6005 [390, 2, 0, "Identifier"],
6006 [392, 2, 4, "Identifier"],
6007 [409, 2, 0, "Identifier"],
6008 [410, 2, 4, "Identifier"],
6009 [416, 2, 0, "Identifier"],
6010 [417, 2, 4, "Identifier"],
6011 [418, 0, 4, "Punctuator"],
6012 [422, 2, 4, "Identifier"],
6013 [423, 2, 0, "Identifier"],
6014 [427, 2, 6, "Identifier"],
6015 [428, 2, 8, "Identifier"],
6016 [429, 2, 4, "Identifier"],
6017 [430, 0, 4, "Punctuator"],
6018 [433, 2, 4, "Identifier"],
6019 [434, 0, 4, "Punctuator"],
6020 [437, 2, 0, "Identifier"],
6021 [438, 0, 4, "Punctuator"],
6022 [442, 2, 4, "Identifier"],
6023 [443, 2, 4, "Identifier"],
6024 [444, 0, 2, "Punctuator"],
6025 [451, 2, 0, "Identifier"],
6026 [453, 2, 4, "Identifier"],
6027 [499, 6, 8, "Punctuator"],
6028 [500, 8, 6, "Identifier"],
6029 [504, 4, 6, "Punctuator"],
6030 [505, 6, 8, "Identifier"],
6031 [506, 4, 8, "Punctuator"]
6032 ])
6033 },
6034 {
6035 code: unIndent`
6036 switch(value){
6037 case "1":
6038 a();
6039 break;
6040 case "2":
6041 a();
6042 break;
6043 default:
6044 a();
6045 break;
6046 }
6047 `,
6048 output: unIndent`
6049 switch(value){
6050 case "1":
6051 a();
6052 break;
6053 case "2":
6054 a();
6055 break;
6056 default:
6057 a();
6058 break;
6059 }
6060 `,
6061 options: [4, { SwitchCase: 1 }],
6062 errors: expectedErrors([[4, 8, 4, "Keyword"], [7, 8, 4, "Keyword"]])
6063 },
6064 {
6065 code: unIndent`
6066 var x = 0 &&
6067 {
6068 a: 1,
6069 b: 2
6070 };
6071 `,
6072 output: unIndent`
6073 var x = 0 &&
6074 {
6075 a: 1,
6076 b: 2
6077 };
6078 `,
6079 options: [4],
6080 errors: expectedErrors([[3, 8, 7, "Identifier"], [4, 8, 10, "Identifier"]])
6081 },
6082 {
6083 code: unIndent`
6084 switch(value){
6085 case "1":
6086 a();
6087 break;
6088 case "2":
6089 a();
6090 break;
6091 default:
6092 break;
6093 }
6094 `,
6095 output: unIndent`
6096 switch(value){
6097 case "1":
6098 a();
6099 break;
6100 case "2":
6101 a();
6102 break;
6103 default:
6104 break;
6105 }
6106 `,
6107 options: [4, { SwitchCase: 1 }],
6108 errors: expectedErrors([9, 8, 4, "Keyword"])
6109 },
6110 {
6111 code: unIndent`
6112 switch(value){
6113 case "1":
6114 case "2":
6115 a();
6116 break;
6117 default:
6118 break;
6119 }
6120 switch(value){
6121 case "1":
6122 break;
6123 case "2":
6124 a();
6125 break;
6126 default:
6127 a();
6128 break;
6129 }
6130 `,
6131 output: unIndent`
6132 switch(value){
6133 case "1":
6134 case "2":
6135 a();
6136 break;
6137 default:
6138 break;
6139 }
6140 switch(value){
6141 case "1":
6142 break;
6143 case "2":
6144 a();
6145 break;
6146 default:
6147 a();
6148 break;
6149 }
6150 `,
6151 options: [4, { SwitchCase: 1 }],
6152 errors: expectedErrors([[11, 8, 4, "Keyword"], [14, 8, 4, "Keyword"], [17, 8, 4, "Keyword"]])
6153 },
6154 {
6155 code: unIndent`
6156 switch(value){
6157 case "1":
6158 a();
6159 break;
6160 case "2":
6161 break;
6162 default:
6163 break;
6164 }
6165 `,
6166 output: unIndent`
6167 switch(value){
6168 case "1":
6169 a();
6170 break;
6171 case "2":
6172 break;
6173 default:
6174 break;
6175 }
6176 `,
6177 options: [4],
6178 errors: expectedErrors([
6179 [3, 4, 8, "Identifier"],
6180 [4, 4, 8, "Keyword"],
6181 [5, 0, 4, "Keyword"],
6182 [6, 4, 8, "Keyword"],
6183 [7, 0, 4, "Keyword"],
6184 [8, 4, 8, "Keyword"]
6185 ])
6186 },
6187 {
6188 code: unIndent`
6189 var obj = {foo: 1, bar: 2};
6190 with (obj) {
6191 console.log(foo + bar);
6192 }
6193 `,
6194 output: unIndent`
6195 var obj = {foo: 1, bar: 2};
6196 with (obj) {
6197 console.log(foo + bar);
6198 }
6199 `,
6200 errors: expectedErrors([3, 4, 0, "Identifier"])
6201 },
6202 {
6203 code: unIndent`
6204 switch (a) {
6205 case '1':
6206 b();
6207 break;
6208 default:
6209 c();
6210 break;
6211 }
6212 `,
6213 output: unIndent`
6214 switch (a) {
6215 case '1':
6216 b();
6217 break;
6218 default:
6219 c();
6220 break;
6221 }
6222 `,
6223 options: [4, { SwitchCase: 1 }],
6224 errors: expectedErrors([
6225 [2, 4, 0, "Keyword"],
6226 [3, 8, 0, "Identifier"],
6227 [4, 8, 0, "Keyword"],
6228 [5, 4, 0, "Keyword"],
6229 [6, 8, 0, "Identifier"],
6230 [7, 8, 0, "Keyword"]
6231 ])
6232 },
6233 {
6234 code: unIndent`
6235 var foo = function(){
6236 foo
6237 .bar
6238 }
6239 `,
6240 output: unIndent`
6241 var foo = function(){
6242 foo
6243 .bar
6244 }
6245 `,
6246 options: [4, { MemberExpression: 1 }],
6247 errors: expectedErrors(
6248 [3, 8, 10, "Punctuator"]
6249 )
6250 },
6251 {
6252 code: unIndent`
6253 (
6254 foo
6255 .bar
6256 )
6257 `,
6258 output: unIndent`
6259 (
6260 foo
6261 .bar
6262 )
6263 `,
6264 errors: expectedErrors([3, 8, 4, "Punctuator"])
6265 },
6266 {
6267 code: unIndent`
6268 var foo = function(){
6269 foo
6270 .bar
6271 }
6272 `,
6273 output: unIndent`
6274 var foo = function(){
6275 foo
6276 .bar
6277 }
6278 `,
6279 options: [4, { MemberExpression: 2 }],
6280 errors: expectedErrors(
6281 [3, 12, 13, "Punctuator"]
6282 )
6283 },
6284 {
6285 code: unIndent`
6286 var foo = () => {
6287 foo
6288 .bar
6289 }
6290 `,
6291 output: unIndent`
6292 var foo = () => {
6293 foo
6294 .bar
6295 }
6296 `,
6297 options: [4, { MemberExpression: 2 }],
6298 errors: expectedErrors(
6299 [3, 12, 13, "Punctuator"]
6300 )
6301 },
6302 {
6303 code: unIndent`
6304 TestClass.prototype.method = function () {
6305 return Promise.resolve(3)
6306 .then(function (x) {
6307 return x;
6308 });
6309 };
6310 `,
6311 output: unIndent`
6312 TestClass.prototype.method = function () {
6313 return Promise.resolve(3)
6314 .then(function (x) {
6315 return x;
6316 });
6317 };
6318 `,
6319 options: [2, { MemberExpression: 1 }],
6320 errors: expectedErrors([3, 4, 6, "Punctuator"])
6321 },
6322 {
6323 code: unIndent`
6324 while (a)
6325 b();
6326 `,
6327 output: unIndent`
6328 while (a)
6329 b();
6330 `,
6331 options: [4],
6332 errors: expectedErrors([
6333 [2, 4, 0, "Identifier"]
6334 ])
6335 },
6336 {
6337 code: unIndent`
6338 lmn = [{
6339 a: 1
6340 },
6341 {
6342 b: 2
6343 },
6344 {
6345 x: 2
6346 }];
6347 `,
6348 output: unIndent`
6349 lmn = [{
6350 a: 1
6351 },
6352 {
6353 b: 2
6354 },
6355 {
6356 x: 2
6357 }];
6358 `,
6359 errors: expectedErrors([
6360 [2, 4, 8, "Identifier"],
6361 [3, 0, 4, "Punctuator"],
6362 [4, 0, 4, "Punctuator"],
6363 [5, 4, 8, "Identifier"],
6364 [6, 0, 4, "Punctuator"],
6365 [7, 0, 4, "Punctuator"],
6366 [8, 4, 8, "Identifier"]
6367 ])
6368 },
6369 {
6370 code: unIndent`
6371 for (var foo = 1;
6372 foo < 10;
6373 foo++) {}
6374 `,
6375 output: unIndent`
6376 for (var foo = 1;
6377 foo < 10;
6378 foo++) {}
6379 `,
6380 errors: expectedErrors([[2, 4, 0, "Identifier"], [3, 4, 0, "Identifier"]])
6381 },
6382 {
6383 code: unIndent`
6384 for (
6385 var foo = 1;
6386 foo < 10;
6387 foo++
6388 ) {}
6389 `,
6390 output: unIndent`
6391 for (
6392 var foo = 1;
6393 foo < 10;
6394 foo++
6395 ) {}
6396 `,
6397 errors: expectedErrors([[2, 4, 0, "Keyword"], [3, 4, 0, "Identifier"], [4, 4, 0, "Identifier"], [5, 0, 4, "Punctuator"]])
6398 },
6399 {
6400 code: unIndent`
6401 for (;;)
6402 b();
6403 `,
6404 output: unIndent`
6405 for (;;)
6406 b();
6407 `,
6408 options: [4],
6409 errors: expectedErrors([
6410 [2, 4, 0, "Identifier"]
6411 ])
6412 },
6413 {
6414 code: unIndent`
6415 for (a in x)
6416 b();
6417 `,
6418 output: unIndent`
6419 for (a in x)
6420 b();
6421 `,
6422 options: [4],
6423 errors: expectedErrors([
6424 [2, 4, 0, "Identifier"]
6425 ])
6426 },
6427 {
6428 code: unIndent`
6429 do
6430 b();
6431 while(true)
6432 `,
6433 output: unIndent`
6434 do
6435 b();
6436 while(true)
6437 `,
6438 options: [4],
6439 errors: expectedErrors([
6440 [2, 4, 0, "Identifier"]
6441 ])
6442 },
6443 {
6444 code: unIndent`
6445 if(true)
6446 b();
6447 `,
6448 output: unIndent`
6449 if(true)
6450 b();
6451 `,
6452 options: [4],
6453 errors: expectedErrors([
6454 [2, 4, 0, "Identifier"]
6455 ])
6456 },
6457 {
6458 code: unIndent`
6459 var test = {
6460 a: 1,
6461 b: 2
6462 };
6463 `,
6464 output: unIndent`
6465 var test = {
6466 a: 1,
6467 b: 2
6468 };
6469 `,
6470 options: [2],
6471 errors: expectedErrors([
6472 [2, 2, 6, "Identifier"],
6473 [3, 2, 4, "Identifier"],
6474 [4, 0, 4, "Punctuator"]
6475 ])
6476 },
6477 {
6478 code: unIndent`
6479 var a = function() {
6480 a++;
6481 b++;
6482 c++;
6483 },
6484 b;
6485 `,
6486 output: unIndent`
6487 var a = function() {
6488 a++;
6489 b++;
6490 c++;
6491 },
6492 b;
6493 `,
6494 options: [4],
6495 errors: expectedErrors([
6496 [2, 8, 6, "Identifier"],
6497 [3, 8, 4, "Identifier"],
6498 [4, 8, 10, "Identifier"]
6499 ])
6500 },
6501 {
6502 code: unIndent`
6503 var a = 1,
6504 b = 2,
6505 c = 3;
6506 `,
6507 output: unIndent`
6508 var a = 1,
6509 b = 2,
6510 c = 3;
6511 `,
6512 options: [4],
6513 errors: expectedErrors([
6514 [2, 4, 0, "Identifier"],
6515 [3, 4, 0, "Identifier"]
6516 ])
6517 },
6518 {
6519 code: unIndent`
6520 [a, b,
6521 c].forEach((index) => {
6522 index;
6523 });
6524 `,
6525 output: unIndent`
6526 [a, b,
6527 c].forEach((index) => {
6528 index;
6529 });
6530 `,
6531 options: [4],
6532 errors: expectedErrors([
6533 [3, 4, 8, "Identifier"],
6534 [4, 0, 4, "Punctuator"]
6535 ])
6536 },
6537 {
6538 code: unIndent`
6539 [a, b,
6540 c].forEach(function(index){
6541 return index;
6542 });
6543 `,
6544 output: unIndent`
6545 [a, b,
6546 c].forEach(function(index){
6547 return index;
6548 });
6549 `,
6550 options: [4],
6551 errors: expectedErrors([
6552 [2, 4, 0, "Identifier"],
6553 [3, 4, 2, "Keyword"]
6554 ])
6555 },
6556 {
6557 code: unIndent`
6558 [a, b, c].forEach(function(index){
6559 return index;
6560 });
6561 `,
6562 output: unIndent`
6563 [a, b, c].forEach(function(index){
6564 return index;
6565 });
6566 `,
6567 options: [4],
6568 errors: expectedErrors([
6569 [2, 4, 2, "Keyword"]
6570 ])
6571 },
6572 {
6573 code: unIndent`
6574 (foo)
6575 .bar([
6576 baz
6577 ]);
6578 `,
6579 output: unIndent`
6580 (foo)
6581 .bar([
6582 baz
6583 ]);
6584 `,
6585 options: [4, { MemberExpression: 1 }],
6586 errors: expectedErrors([[3, 8, 4, "Identifier"], [4, 4, 0, "Punctuator"]])
6587 },
6588 {
6589 code: unIndent`
6590 var x = ['a',
6591 'b',
6592 'c'
6593 ];
6594 `,
6595 output: unIndent`
6596 var x = ['a',
6597 'b',
6598 'c'
6599 ];
6600 `,
6601 options: [4],
6602 errors: expectedErrors([
6603 [2, 4, 9, "String"],
6604 [3, 4, 9, "String"]
6605 ])
6606 },
6607 {
6608 code: unIndent`
6609 var x = [
6610 'a',
6611 'b',
6612 'c'
6613 ];
6614 `,
6615 output: unIndent`
6616 var x = [
6617 'a',
6618 'b',
6619 'c'
6620 ];
6621 `,
6622 options: [4],
6623 errors: expectedErrors([
6624 [2, 4, 9, "String"],
6625 [3, 4, 9, "String"],
6626 [4, 4, 9, "String"]
6627 ])
6628 },
6629 {
6630 code: unIndent`
6631 var x = [
6632 'a',
6633 'b',
6634 'c',
6635 'd'];
6636 `,
6637 output: unIndent`
6638 var x = [
6639 'a',
6640 'b',
6641 'c',
6642 'd'];
6643 `,
6644 options: [4],
6645 errors: expectedErrors([
6646 [2, 4, 9, "String"],
6647 [3, 4, 9, "String"],
6648 [4, 4, 9, "String"],
6649 [5, 4, 0, "String"]
6650 ])
6651 },
6652 {
6653 code: unIndent`
6654 var x = [
6655 'a',
6656 'b',
6657 'c'
6658 ];
6659 `,
6660 output: unIndent`
6661 var x = [
6662 'a',
6663 'b',
6664 'c'
6665 ];
6666 `,
6667 options: [4],
6668 errors: expectedErrors([
6669 [2, 4, 9, "String"],
6670 [3, 4, 9, "String"],
6671 [4, 4, 9, "String"],
6672 [5, 0, 2, "Punctuator"]
6673 ])
6674 },
6675 {
6676 code: unIndent`
6677 [[
6678 ], function(
6679 foo
6680 ) {}
6681 ]
6682 `,
6683 output: unIndent`
6684 [[
6685 ], function(
6686 foo
6687 ) {}
6688 ]
6689 `,
6690 errors: expectedErrors([[3, 4, 8, "Identifier"], [4, 0, 4, "Punctuator"]])
6691 },
6692 {
6693 code: unIndent`
6694 define([
6695 'foo'
6696 ], function(
6697 bar
6698 ) {
6699 baz;
6700 }
6701 )
6702 `,
6703 output: unIndent`
6704 define([
6705 'foo'
6706 ], function(
6707 bar
6708 ) {
6709 baz;
6710 }
6711 )
6712 `,
6713 errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
6714 },
6715 {
6716 code: unIndent`
6717 while (1 < 2)
6718 console.log('foo')
6719 console.log('bar')
6720 `,
6721 output: unIndent`
6722 while (1 < 2)
6723 console.log('foo')
6724 console.log('bar')
6725 `,
6726 options: [2],
6727 errors: expectedErrors([
6728 [2, 2, 0, "Identifier"],
6729 [3, 0, 2, "Identifier"]
6730 ])
6731 },
6732 {
6733 code: unIndent`
6734 function salutation () {
6735 switch (1) {
6736 case 0: return console.log('hi')
6737 case 1: return console.log('hey')
6738 }
6739 }
6740 `,
6741 output: unIndent`
6742 function salutation () {
6743 switch (1) {
6744 case 0: return console.log('hi')
6745 case 1: return console.log('hey')
6746 }
6747 }
6748 `,
6749 options: [2, { SwitchCase: 1 }],
6750 errors: expectedErrors([
6751 [3, 4, 2, "Keyword"]
6752 ])
6753 },
6754 {
6755 code: unIndent`
6756 var geometry, box, face1, face2, colorT, colorB, sprite, padding, maxWidth,
6757 height, rotate;
6758 `,
6759 output: unIndent`
6760 var geometry, box, face1, face2, colorT, colorB, sprite, padding, maxWidth,
6761 height, rotate;
6762 `,
6763 options: [2, { SwitchCase: 1 }],
6764 errors: expectedErrors([
6765 [2, 2, 0, "Identifier"]
6766 ])
6767 },
6768 {
6769 code: unIndent`
6770 switch (a) {
6771 case '1':
6772 b();
6773 break;
6774 default:
6775 c();
6776 break;
6777 }
6778 `,
6779 output: unIndent`
6780 switch (a) {
6781 case '1':
6782 b();
6783 break;
6784 default:
6785 c();
6786 break;
6787 }
6788 `,
6789 options: [4, { SwitchCase: 2 }],
6790 errors: expectedErrors([
6791 [2, 8, 0, "Keyword"],
6792 [3, 12, 0, "Identifier"],
6793 [4, 12, 0, "Keyword"],
6794 [5, 8, 0, "Keyword"],
6795 [6, 12, 0, "Identifier"],
6796 [7, 12, 0, "Keyword"]
6797 ])
6798 },
6799 {
6800 code: unIndent`
6801 var geometry,
6802 rotate;
6803 `,
6804 output: unIndent`
6805 var geometry,
6806 rotate;
6807 `,
6808 options: [2, { VariableDeclarator: 1 }],
6809 errors: expectedErrors([
6810 [2, 2, 0, "Identifier"]
6811 ])
6812 },
6813 {
6814 code: unIndent`
6815 var geometry,
6816 rotate;
6817 `,
6818 output: unIndent`
6819 var geometry,
6820 rotate;
6821 `,
6822 options: [2, { VariableDeclarator: 2 }],
6823 errors: expectedErrors([
6824 [2, 4, 2, "Identifier"]
6825 ])
6826 },
6827 {
6828 code: unIndent`
6829 var geometry,
6830 \trotate;
6831 `,
6832 output: unIndent`
6833 var geometry,
6834 \t\trotate;
6835 `,
6836 options: ["tab", { VariableDeclarator: 2 }],
6837 errors: expectedErrors("tab", [
6838 [2, 2, 1, "Identifier"]
6839 ])
6840 },
6841 {
6842 code: unIndent`
6843 let geometry,
6844 rotate;
6845 `,
6846 output: unIndent`
6847 let geometry,
6848 rotate;
6849 `,
6850 options: [2, { VariableDeclarator: 2 }],
6851 errors: expectedErrors([
6852 [2, 4, 2, "Identifier"]
6853 ])
6854 },
6855 {
6856 code: unIndent`
6857 let foo = 'foo',
6858 bar = bar;
6859 const a = 'a',
6860 b = 'b';
6861 `,
6862 output: unIndent`
6863 let foo = 'foo',
6864 bar = bar;
6865 const a = 'a',
6866 b = 'b';
6867 `,
6868 options: [2, { VariableDeclarator: "first" }],
6869 errors: expectedErrors([
6870 [2, 4, 2, "Identifier"],
6871 [4, 6, 2, "Identifier"]
6872 ])
6873 },
6874 {
6875 code: unIndent`
6876 var foo = 'foo',
6877 bar = bar;
6878 `,
6879 output: unIndent`
6880 var foo = 'foo',
6881 bar = bar;
6882 `,
6883 options: [2, { VariableDeclarator: { var: "first" } }],
6884 errors: expectedErrors([
6885 [2, 4, 2, "Identifier"]
6886 ])
6887 },
6888 {
6889 code: unIndent`
6890 if(true)
6891 if (true)
6892 if (true)
6893 console.log(val);
6894 `,
6895 output: unIndent`
6896 if(true)
6897 if (true)
6898 if (true)
6899 console.log(val);
6900 `,
6901 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }],
6902 errors: expectedErrors([
6903 [4, 6, 4, "Identifier"]
6904 ])
6905 },
6906 {
6907 code: unIndent`
6908 var a = {
6909 a: 1,
6910 b: 2
6911 }
6912 `,
6913 output: unIndent`
6914 var a = {
6915 a: 1,
6916 b: 2
6917 }
6918 `,
6919 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }],
6920 errors: expectedErrors([
6921 [2, 2, 4, "Identifier"],
6922 [3, 2, 4, "Identifier"]
6923 ])
6924 },
6925 {
6926 code: unIndent`
6927 var a = [
6928 a,
6929 b
6930 ]
6931 `,
6932 output: unIndent`
6933 var a = [
6934 a,
6935 b
6936 ]
6937 `,
6938 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }],
6939 errors: expectedErrors([
6940 [2, 2, 4, "Identifier"],
6941 [3, 2, 4, "Identifier"]
6942 ])
6943 },
6944 {
6945 code: unIndent`
6946 let a = [
6947 a,
6948 b
6949 ]
6950 `,
6951 output: unIndent`
6952 let a = [
6953 a,
6954 b
6955 ]
6956 `,
6957 options: [2, { VariableDeclarator: { let: 2 }, SwitchCase: 1 }],
6958 errors: expectedErrors([
6959 [2, 2, 4, "Identifier"],
6960 [3, 2, 4, "Identifier"]
6961 ])
6962 },
6963 {
6964 code: unIndent`
6965 var a = new Test({
6966 a: 1
6967 }),
6968 b = 4;
6969 `,
6970 output: unIndent`
6971 var a = new Test({
6972 a: 1
6973 }),
6974 b = 4;
6975 `,
6976 options: [4],
6977 errors: expectedErrors([
6978 [2, 8, 6, "Identifier"],
6979 [3, 4, 2, "Punctuator"]
6980 ])
6981 },
6982 {
6983 code: unIndent`
6984 var a = new Test({
6985 a: 1
6986 }),
6987 b = 4;
6988 const c = new Test({
6989 a: 1
6990 }),
6991 d = 4;
6992 `,
6993 output: unIndent`
6994 var a = new Test({
6995 a: 1
6996 }),
6997 b = 4;
6998 const c = new Test({
6999 a: 1
7000 }),
7001 d = 4;
7002 `,
7003 options: [2, { VariableDeclarator: { var: 2 } }],
7004 errors: expectedErrors([
7005 [6, 4, 6, "Identifier"],
7006 [7, 2, 4, "Punctuator"],
7007 [8, 2, 4, "Identifier"]
7008 ])
7009 },
7010 {
7011 code: unIndent`
7012 var abc = 5,
7013 c = 2,
7014 xyz =
7015 {
7016 a: 1,
7017 b: 2
7018 };
7019 `,
7020 output: unIndent`
7021 var abc = 5,
7022 c = 2,
7023 xyz =
7024 {
7025 a: 1,
7026 b: 2
7027 };
7028 `,
7029 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }],
7030 errors: expectedErrors([6, 6, 7, "Identifier"])
7031 },
7032 {
7033 code: unIndent`
7034 var abc =
7035 {
7036 a: 1,
7037 b: 2
7038 };
7039 `,
7040 output: unIndent`
7041 var abc =
7042 {
7043 a: 1,
7044 b: 2
7045 };
7046 `,
7047 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }],
7048 errors: expectedErrors([4, 7, 8, "Identifier"])
7049 },
7050 {
7051 code: unIndent`
7052 var foo = {
7053 bar: 1,
7054 baz: {
7055 qux: 2
7056 }
7057 },
7058 bar = 1;
7059 `,
7060 output: unIndent`
7061 var foo = {
7062 bar: 1,
7063 baz: {
7064 qux: 2
7065 }
7066 },
7067 bar = 1;
7068 `,
7069 options: [2],
7070 errors: expectedErrors([[4, 6, 8, "Identifier"], [5, 4, 6, "Punctuator"]])
7071 },
7072 {
7073 code: unIndent`
7074 var path = require('path')
7075 , crypto = require('crypto')
7076 ;
7077 `,
7078 output: unIndent`
7079 var path = require('path')
7080 , crypto = require('crypto')
7081 ;
7082 `,
7083 options: [2],
7084 errors: expectedErrors([
7085 [2, 2, 1, "Punctuator"]
7086 ])
7087 },
7088 {
7089 code: unIndent`
7090 var a = 1
7091 ,b = 2
7092 ;
7093 `,
7094 output: unIndent`
7095 var a = 1
7096 ,b = 2
7097 ;
7098 `,
7099 errors: expectedErrors([
7100 [2, 4, 3, "Punctuator"]
7101 ])
7102 },
7103 {
7104 code: unIndent`
7105 class A{
7106 constructor(){}
7107 a(){}
7108 get b(){}
7109 }
7110 `,
7111 output: unIndent`
7112 class A{
7113 constructor(){}
7114 a(){}
7115 get b(){}
7116 }
7117 `,
7118 options: [4, { VariableDeclarator: 1, SwitchCase: 1 }],
7119 errors: expectedErrors([[2, 4, 2, "Identifier"]])
7120 },
7121 {
7122 code: unIndent`
7123 var A = class {
7124 constructor(){}
7125 a(){}
7126 get b(){}
7127 };
7128 `,
7129 output: unIndent`
7130 var A = class {
7131 constructor(){}
7132 a(){}
7133 get b(){}
7134 };
7135 `,
7136 options: [4, { VariableDeclarator: 1, SwitchCase: 1 }],
7137 errors: expectedErrors([[2, 4, 2, "Identifier"], [4, 4, 2, "Identifier"]])
7138 },
7139 {
7140 code: unIndent`
7141 var a = 1,
7142 B = class {
7143 constructor(){}
7144 a(){}
7145 get b(){}
7146 };
7147 `,
7148 output: unIndent`
7149 var a = 1,
7150 B = class {
7151 constructor(){}
7152 a(){}
7153 get b(){}
7154 };
7155 `,
7156 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }],
7157 errors: expectedErrors([[3, 6, 4, "Identifier"]])
7158 },
7159 {
7160 code: unIndent`
7161 {
7162 if(a){
7163 foo();
7164 }
7165 else{
7166 bar();
7167 }
7168 }
7169 `,
7170 output: unIndent`
7171 {
7172 if(a){
7173 foo();
7174 }
7175 else{
7176 bar();
7177 }
7178 }
7179 `,
7180 options: [4],
7181 errors: expectedErrors([[5, 4, 2, "Keyword"]])
7182 },
7183 {
7184 code: unIndent`
7185 {
7186 if(a){
7187 foo();
7188 }
7189 else
7190 bar();
7191
7192 }
7193 `,
7194 output: unIndent`
7195 {
7196 if(a){
7197 foo();
7198 }
7199 else
7200 bar();
7201
7202 }
7203 `,
7204 options: [4],
7205 errors: expectedErrors([[5, 4, 2, "Keyword"]])
7206 },
7207 {
7208 code: unIndent`
7209 {
7210 if(a)
7211 foo();
7212 else
7213 bar();
7214 }
7215 `,
7216 output: unIndent`
7217 {
7218 if(a)
7219 foo();
7220 else
7221 bar();
7222 }
7223 `,
7224 options: [4],
7225 errors: expectedErrors([[4, 4, 2, "Keyword"]])
7226 },
7227 {
7228 code: unIndent`
7229 (function(){
7230 function foo(x) {
7231 return x + 1;
7232 }
7233 })();
7234 `,
7235 output: unIndent`
7236 (function(){
7237 function foo(x) {
7238 return x + 1;
7239 }
7240 })();
7241 `,
7242 options: [2, { outerIIFEBody: 0 }],
7243 errors: expectedErrors([[2, 0, 2, "Keyword"], [3, 2, 4, "Keyword"], [4, 0, 2, "Punctuator"]])
7244 },
7245 {
7246 code: unIndent`
7247 (function(){
7248 function foo(x) {
7249 return x + 1;
7250 }
7251 })();
7252 `,
7253 output: unIndent`
7254 (function(){
7255 function foo(x) {
7256 return x + 1;
7257 }
7258 })();
7259 `,
7260 options: [4, { outerIIFEBody: 2 }],
7261 errors: expectedErrors([[2, 8, 4, "Keyword"], [3, 12, 8, "Keyword"], [4, 8, 4, "Punctuator"]])
7262 },
7263 {
7264 code: unIndent`
7265 if(data) {
7266 console.log('hi');
7267 }
7268 `,
7269 output: unIndent`
7270 if(data) {
7271 console.log('hi');
7272 }
7273 `,
7274 options: [2, { outerIIFEBody: 0 }],
7275 errors: expectedErrors([[2, 2, 0, "Identifier"]])
7276 },
7277 {
7278 code: unIndent`
7279 var ns = function(){
7280 function fooVar(x) {
7281 return x + 1;
7282 }
7283 }(x);
7284 `,
7285 output: unIndent`
7286 var ns = function(){
7287 function fooVar(x) {
7288 return x + 1;
7289 }
7290 }(x);
7291 `,
7292 options: [4, { outerIIFEBody: 2 }],
7293 errors: expectedErrors([[2, 8, 4, "Keyword"], [3, 12, 8, "Keyword"], [4, 8, 4, "Punctuator"]])
7294 },
7295 {
7296 code: unIndent`
7297 var obj = {
7298 foo: function() {
7299 return true;
7300 }()
7301 };
7302 `,
7303 output: unIndent`
7304 var obj = {
7305 foo: function() {
7306 return true;
7307 }()
7308 };
7309 `,
7310 options: [2, { outerIIFEBody: 0 }],
7311 errors: expectedErrors([[3, 4, 2, "Keyword"]])
7312 },
7313 {
7314 code: unIndent`
7315 typeof function() {
7316 function fooVar(x) {
7317 return x + 1;
7318 }
7319 }();
7320 `,
7321 output: unIndent`
7322 typeof function() {
7323 function fooVar(x) {
7324 return x + 1;
7325 }
7326 }();
7327 `,
7328 options: [2, { outerIIFEBody: 2 }],
7329 errors: expectedErrors([[2, 2, 4, "Keyword"], [3, 4, 6, "Keyword"], [4, 2, 4, "Punctuator"]])
7330 },
7331 {
7332 code: unIndent`
7333 {
7334 \t!function(x) {
7335 \t\t\t\treturn x + 1;
7336 \t}()
7337 };
7338 `,
7339 output: unIndent`
7340 {
7341 \t!function(x) {
7342 \t\treturn x + 1;
7343 \t}()
7344 };
7345 `,
7346 options: ["tab", { outerIIFEBody: 3 }],
7347 errors: expectedErrors("tab", [[3, 2, 4, "Keyword"]])
7348 },
7349 {
7350 code: unIndent`
7351 (function(){
7352 function foo(x) {
7353 return x + 1;
7354 }
7355 })();
7356 `,
7357 output: unIndent`
7358 (function(){
7359 function foo(x) {
7360 return x + 1;
7361 }
7362 })();
7363 `,
7364 options: [4, { outerIIFEBody: "off" }],
7365 errors: expectedErrors([[3, 8, 4, "Keyword"]])
7366 },
7367 {
7368 code: unIndent`
7369 (function(){
7370 function foo(x) {
7371 return x + 1;
7372 }
7373 })();
7374 `,
7375 output: unIndent`
7376 (function(){
7377 function foo(x) {
7378 return x + 1;
7379 }
7380 })();
7381 `,
7382 options: [4, { outerIIFEBody: "off" }],
7383 errors: expectedErrors([[3, 4, 0, "Keyword"]])
7384 },
7385 {
7386 code: unIndent`
7387 (() => {
7388 function foo(x) {
7389 return x + 1;
7390 }
7391 })();
7392 `,
7393 output: unIndent`
7394 (() => {
7395 function foo(x) {
7396 return x + 1;
7397 }
7398 })();
7399 `,
7400 options: [4, { outerIIFEBody: "off" }],
7401 errors: expectedErrors([[3, 8, 4, "Keyword"]])
7402 },
7403 {
7404 code: unIndent`
7405 (() => {
7406 function foo(x) {
7407 return x + 1;
7408 }
7409 })();
7410 `,
7411 output: unIndent`
7412 (() => {
7413 function foo(x) {
7414 return x + 1;
7415 }
7416 })();
7417 `,
7418 options: [4, { outerIIFEBody: "off" }],
7419 errors: expectedErrors([[3, 4, 0, "Keyword"]])
7420 },
7421 {
7422 code: unIndent`
7423 Buffer
7424 .toString()
7425 `,
7426 output: unIndent`
7427 Buffer
7428 .toString()
7429 `,
7430 options: [4, { MemberExpression: 1 }],
7431 errors: expectedErrors([[2, 4, 0, "Punctuator"]])
7432 },
7433 {
7434 code: unIndent`
7435 Buffer
7436 .indexOf('a')
7437 .toString()
7438 `,
7439 output: unIndent`
7440 Buffer
7441 .indexOf('a')
7442 .toString()
7443 `,
7444 options: [4, { MemberExpression: 1 }],
7445 errors: expectedErrors([[3, 4, 0, "Punctuator"]])
7446 },
7447 {
7448 code: unIndent`
7449 Buffer.
7450 length
7451 `,
7452 output: unIndent`
7453 Buffer.
7454 length
7455 `,
7456 options: [4, { MemberExpression: 1 }],
7457 errors: expectedErrors([[2, 4, 0, "Identifier"]])
7458 },
7459 {
7460 code: unIndent`
7461 Buffer.
7462 \t\tlength
7463 `,
7464 output: unIndent`
7465 Buffer.
7466 \tlength
7467 `,
7468 options: ["tab", { MemberExpression: 1 }],
7469 errors: expectedErrors("tab", [[2, 1, 2, "Identifier"]])
7470 },
7471 {
7472 code: unIndent`
7473 Buffer
7474 .foo
7475 .bar
7476 `,
7477 output: unIndent`
7478 Buffer
7479 .foo
7480 .bar
7481 `,
7482 options: [2, { MemberExpression: 2 }],
7483 errors: expectedErrors([[2, 4, 2, "Punctuator"], [3, 4, 2, "Punctuator"]])
7484 },
7485 {
7486 code: unIndent`
7487 function foo() {
7488 new
7489 .target
7490 }
7491 `,
7492 output: unIndent`
7493 function foo() {
7494 new
7495 .target
7496 }
7497 `,
7498 errors: expectedErrors([3, 8, 4, "Punctuator"])
7499 },
7500 {
7501 code: unIndent`
7502 function foo() {
7503 new.
7504 target
7505 }
7506 `,
7507 output: unIndent`
7508 function foo() {
7509 new.
7510 target
7511 }
7512 `,
7513 errors: expectedErrors([3, 8, 4, "Identifier"])
7514 },
7515 {
7516
7517 // Indentation with multiple else statements: https://github.com/eslint/eslint/issues/6956
7518
7519 code: unIndent`
7520 if (foo) bar();
7521 else if (baz) foobar();
7522 else if (qux) qux();
7523 `,
7524 output: unIndent`
7525 if (foo) bar();
7526 else if (baz) foobar();
7527 else if (qux) qux();
7528 `,
7529 options: [2],
7530 errors: expectedErrors([3, 0, 2, "Keyword"])
7531 },
7532 {
7533 code: unIndent`
7534 if (foo) bar();
7535 else if (baz) foobar();
7536 else qux();
7537 `,
7538 output: unIndent`
7539 if (foo) bar();
7540 else if (baz) foobar();
7541 else qux();
7542 `,
7543 options: [2],
7544 errors: expectedErrors([3, 0, 2, "Keyword"])
7545 },
7546 {
7547 code: unIndent`
7548 foo();
7549 if (baz) foobar();
7550 else qux();
7551 `,
7552 output: unIndent`
7553 foo();
7554 if (baz) foobar();
7555 else qux();
7556 `,
7557 options: [2],
7558 errors: expectedErrors([[2, 0, 2, "Keyword"], [3, 0, 2, "Keyword"]])
7559 },
7560 {
7561 code: unIndent`
7562 if (foo) bar();
7563 else if (baz) foobar();
7564 else if (bip) {
7565 qux();
7566 }
7567 `,
7568 output: unIndent`
7569 if (foo) bar();
7570 else if (baz) foobar();
7571 else if (bip) {
7572 qux();
7573 }
7574 `,
7575 options: [2],
7576 errors: expectedErrors([[3, 0, 5, "Keyword"], [4, 2, 7, "Identifier"], [5, 0, 5, "Punctuator"]])
7577 },
7578 {
7579 code: unIndent`
7580 if (foo) bar();
7581 else if (baz) {
7582 foobar();
7583 } else if (boop) {
7584 qux();
7585 }
7586 `,
7587 output: unIndent`
7588 if (foo) bar();
7589 else if (baz) {
7590 foobar();
7591 } else if (boop) {
7592 qux();
7593 }
7594 `,
7595 options: [2],
7596 errors: expectedErrors([[3, 2, 4, "Identifier"], [4, 0, 5, "Punctuator"], [5, 2, 7, "Identifier"], [6, 0, 5, "Punctuator"]])
7597 },
7598 {
7599 code: unIndent`
7600 function foo(aaa,
7601 bbb, ccc, ddd) {
7602 bar();
7603 }
7604 `,
7605 output: unIndent`
7606 function foo(aaa,
7607 bbb, ccc, ddd) {
7608 bar();
7609 }
7610 `,
7611 options: [2, { FunctionDeclaration: { parameters: 1, body: 2 } }],
7612 errors: expectedErrors([[2, 2, 4, "Identifier"], [3, 4, 6, "Identifier"]])
7613 },
7614 {
7615 code: unIndent`
7616 function foo(aaa, bbb,
7617 ccc, ddd) {
7618 bar();
7619 }
7620 `,
7621 output: unIndent`
7622 function foo(aaa, bbb,
7623 ccc, ddd) {
7624 bar();
7625 }
7626 `,
7627 options: [2, { FunctionDeclaration: { parameters: 3, body: 1 } }],
7628 errors: expectedErrors([[2, 6, 2, "Identifier"], [3, 2, 0, "Identifier"]])
7629 },
7630 {
7631 code: unIndent`
7632 function foo(aaa,
7633 bbb,
7634 ccc) {
7635 bar();
7636 }
7637 `,
7638 output: unIndent`
7639 function foo(aaa,
7640 bbb,
7641 ccc) {
7642 bar();
7643 }
7644 `,
7645 options: [4, { FunctionDeclaration: { parameters: 1, body: 3 } }],
7646 errors: expectedErrors([[2, 4, 8, "Identifier"], [3, 4, 2, "Identifier"], [4, 12, 6, "Identifier"]])
7647 },
7648 {
7649 code: unIndent`
7650 function foo(aaa,
7651 bbb, ccc,
7652 ddd, eee, fff) {
7653 bar();
7654 }
7655 `,
7656 output: unIndent`
7657 function foo(aaa,
7658 bbb, ccc,
7659 ddd, eee, fff) {
7660 bar();
7661 }
7662 `,
7663 options: [2, { FunctionDeclaration: { parameters: "first", body: 1 } }],
7664 errors: expectedErrors([[2, 13, 2, "Identifier"], [3, 13, 19, "Identifier"], [4, 2, 3, "Identifier"]])
7665 },
7666 {
7667 code: unIndent`
7668 function foo(aaa, bbb)
7669 {
7670 bar();
7671 }
7672 `,
7673 output: unIndent`
7674 function foo(aaa, bbb)
7675 {
7676 bar();
7677 }
7678 `,
7679 options: [2, { FunctionDeclaration: { body: 3 } }],
7680 errors: expectedErrors([3, 6, 0, "Identifier"])
7681 },
7682 {
7683 code: unIndent`
7684 function foo(
7685 aaa,
7686 bbb) {
7687 bar();
7688 }
7689 `,
7690 output: unIndent`
7691 function foo(
7692 aaa,
7693 bbb) {
7694 bar();
7695 }
7696 `,
7697 options: [2, { FunctionDeclaration: { parameters: "first", body: 2 } }],
7698 errors: expectedErrors([[2, 2, 0, "Identifier"], [3, 2, 4, "Identifier"], [4, 4, 0, "Identifier"]])
7699 },
7700 {
7701 code: unIndent`
7702 var foo = function(aaa,
7703 bbb,
7704 ccc,
7705 ddd) {
7706 bar();
7707 }
7708 `,
7709 output: unIndent`
7710 var foo = function(aaa,
7711 bbb,
7712 ccc,
7713 ddd) {
7714 bar();
7715 }
7716 `,
7717 options: [2, { FunctionExpression: { parameters: 2, body: 0 } }],
7718 errors: expectedErrors([[2, 4, 2, "Identifier"], [4, 4, 6, "Identifier"], [5, 0, 2, "Identifier"]])
7719 },
7720 {
7721 code: unIndent`
7722 var foo = function(aaa,
7723 bbb,
7724 ccc) {
7725 bar();
7726 }
7727 `,
7728 output: unIndent`
7729 var foo = function(aaa,
7730 bbb,
7731 ccc) {
7732 bar();
7733 }
7734 `,
7735 options: [2, { FunctionExpression: { parameters: 1, body: 10 } }],
7736 errors: expectedErrors([[2, 2, 3, "Identifier"], [3, 2, 1, "Identifier"], [4, 20, 2, "Identifier"]])
7737 },
7738 {
7739 code: unIndent`
7740 var foo = function(aaa,
7741 bbb, ccc, ddd,
7742 eee, fff) {
7743 bar();
7744 }
7745 `,
7746 output: unIndent`
7747 var foo = function(aaa,
7748 bbb, ccc, ddd,
7749 eee, fff) {
7750 bar();
7751 }
7752 `,
7753 options: [4, { FunctionExpression: { parameters: "first", body: 1 } }],
7754 errors: expectedErrors([[2, 19, 2, "Identifier"], [3, 19, 24, "Identifier"], [4, 4, 8, "Identifier"]])
7755 },
7756 {
7757 code: unIndent`
7758 var foo = function(
7759 aaa, bbb, ccc,
7760 ddd, eee) {
7761 bar();
7762 }
7763 `,
7764 output: unIndent`
7765 var foo = function(
7766 aaa, bbb, ccc,
7767 ddd, eee) {
7768 bar();
7769 }
7770 `,
7771 options: [2, { FunctionExpression: { parameters: "first", body: 3 } }],
7772 errors: expectedErrors([[2, 2, 0, "Identifier"], [3, 2, 4, "Identifier"], [4, 6, 2, "Identifier"]])
7773 },
7774 {
7775 code: unIndent`
7776 var foo = bar;
7777 \t\t\tvar baz = qux;
7778 `,
7779 output: unIndent`
7780 var foo = bar;
7781 var baz = qux;
7782 `,
7783 options: [2],
7784 errors: expectedErrors([2, "0 spaces", "3 tabs", "Keyword"])
7785 },
7786 {
7787 code: unIndent`
7788 function foo() {
7789 \tbar();
7790 baz();
7791 qux();
7792 }
7793 `,
7794 output: unIndent`
7795 function foo() {
7796 \tbar();
7797 \tbaz();
7798 \tqux();
7799 }
7800 `,
7801 options: ["tab"],
7802 errors: expectedErrors("tab", [[3, "1 tab", "2 spaces", "Identifier"], [4, "1 tab", "14 spaces", "Identifier"]])
7803 },
7804 {
7805 code: unIndent`
7806 function foo() {
7807 bar();
7808 \t\t}
7809 `,
7810 output: unIndent`
7811 function foo() {
7812 bar();
7813 }
7814 `,
7815 options: [2],
7816 errors: expectedErrors([[3, "0 spaces", "2 tabs", "Punctuator"]])
7817 },
7818 {
7819 code: unIndent`
7820 function foo() {
7821 function bar() {
7822 baz();
7823 }
7824 }
7825 `,
7826 output: unIndent`
7827 function foo() {
7828 function bar() {
7829 baz();
7830 }
7831 }
7832 `,
7833 options: [2, { FunctionDeclaration: { body: 1 } }],
7834 errors: expectedErrors([3, 4, 8, "Identifier"])
7835 },
7836 {
7837 code: unIndent`
7838 function foo() {
7839 function bar(baz,
7840 qux) {
7841 foobar();
7842 }
7843 }
7844 `,
7845 output: unIndent`
7846 function foo() {
7847 function bar(baz,
7848 qux) {
7849 foobar();
7850 }
7851 }
7852 `,
7853 options: [2, { FunctionDeclaration: { body: 1, parameters: 2 } }],
7854 errors: expectedErrors([3, 6, 4, "Identifier"])
7855 },
7856 {
7857 code: unIndent`
7858 function foo() {
7859 var bar = function(baz,
7860 qux) {
7861 foobar();
7862 };
7863 }
7864 `,
7865 output: unIndent`
7866 function foo() {
7867 var bar = function(baz,
7868 qux) {
7869 foobar();
7870 };
7871 }
7872 `,
7873 options: [2, { FunctionExpression: { parameters: 3 } }],
7874 errors: expectedErrors([3, 8, 10, "Identifier"])
7875 },
7876 {
7877 code: unIndent`
7878 foo.bar(
7879 baz, qux, function() {
7880 qux;
7881 }
7882 );
7883 `,
7884 output: unIndent`
7885 foo.bar(
7886 baz, qux, function() {
7887 qux;
7888 }
7889 );
7890 `,
7891 options: [2, { FunctionExpression: { body: 3 }, CallExpression: { arguments: 3 } }],
7892 errors: expectedErrors([3, 12, 8, "Identifier"])
7893 },
7894 {
7895 code: unIndent`
7896 {
7897 try {
7898 }
7899 catch (err) {
7900 }
7901 finally {
7902 }
7903 }
7904 `,
7905 output: unIndent`
7906 {
7907 try {
7908 }
7909 catch (err) {
7910 }
7911 finally {
7912 }
7913 }
7914 `,
7915 errors: expectedErrors([
7916 [4, 4, 0, "Keyword"],
7917 [6, 4, 0, "Keyword"]
7918 ])
7919 },
7920 {
7921 code: unIndent`
7922 {
7923 do {
7924 }
7925 while (true)
7926 }
7927 `,
7928 output: unIndent`
7929 {
7930 do {
7931 }
7932 while (true)
7933 }
7934 `,
7935 errors: expectedErrors([4, 4, 0, "Keyword"])
7936 },
7937 {
7938 code: unIndent`
7939 function foo() {
7940 return (
7941 1
7942 )
7943 }
7944 `,
7945 output: unIndent`
7946 function foo() {
7947 return (
7948 1
7949 )
7950 }
7951 `,
7952 options: [2],
7953 errors: expectedErrors([[4, 2, 4, "Punctuator"]])
7954 },
7955 {
7956 code: unIndent`
7957 function foo() {
7958 return (
7959 1
7960 );
7961 }
7962 `,
7963 output: unIndent`
7964 function foo() {
7965 return (
7966 1
7967 );
7968 }
7969 `,
7970 options: [2],
7971 errors: expectedErrors([[4, 2, 4, "Punctuator"]])
7972 },
7973 {
7974 code: unIndent`
7975 function test(){
7976 switch(length){
7977 case 1: return function(a){
7978 return fn.call(that, a);
7979 };
7980 }
7981 }
7982 `,
7983 output: unIndent`
7984 function test(){
7985 switch(length){
7986 case 1: return function(a){
7987 return fn.call(that, a);
7988 };
7989 }
7990 }
7991 `,
7992 options: [2, { VariableDeclarator: 2, SwitchCase: 1 }],
7993 errors: expectedErrors([[4, 6, 4, "Keyword"]])
7994 },
7995 {
7996 code: unIndent`
7997 function foo() {
7998 return 1
7999 }
8000 `,
8001 output: unIndent`
8002 function foo() {
8003 return 1
8004 }
8005 `,
8006 options: [2],
8007 errors: expectedErrors([[2, 2, 3, "Keyword"]])
8008 },
8009 {
8010 code: unIndent`
8011 foo(
8012 bar,
8013 baz,
8014 qux);
8015 `,
8016 output: unIndent`
8017 foo(
8018 bar,
8019 baz,
8020 qux);
8021 `,
8022 options: [2, { CallExpression: { arguments: 1 } }],
8023 errors: expectedErrors([[2, 2, 0, "Identifier"], [4, 2, 4, "Identifier"]])
8024 },
8025 {
8026 code: unIndent`
8027 foo(
8028 \tbar,
8029 \tbaz);
8030 `,
8031 output: unIndent`
8032 foo(
8033 bar,
8034 baz);
8035 `,
8036 options: [2, { CallExpression: { arguments: 2 } }],
8037 errors: expectedErrors([[2, "4 spaces", "1 tab", "Identifier"], [3, "4 spaces", "1 tab", "Identifier"]])
8038 },
8039 {
8040 code: unIndent`
8041 foo(bar,
8042 \t\tbaz,
8043 \t\tqux);
8044 `,
8045 output: unIndent`
8046 foo(bar,
8047 \tbaz,
8048 \tqux);
8049 `,
8050 options: ["tab", { CallExpression: { arguments: 1 } }],
8051 errors: expectedErrors("tab", [[2, 1, 2, "Identifier"], [3, 1, 2, "Identifier"]])
8052 },
8053 {
8054 code: unIndent`
8055 foo(bar, baz,
8056 qux);
8057 `,
8058 output: unIndent`
8059 foo(bar, baz,
8060 qux);
8061 `,
8062 options: [2, { CallExpression: { arguments: "first" } }],
8063 errors: expectedErrors([2, 4, 9, "Identifier"])
8064 },
8065 {
8066 code: unIndent`
8067 foo(
8068 bar,
8069 baz);
8070 `,
8071 output: unIndent`
8072 foo(
8073 bar,
8074 baz);
8075 `,
8076 options: [2, { CallExpression: { arguments: "first" } }],
8077 errors: expectedErrors([[2, 2, 10, "Identifier"], [3, 2, 4, "Identifier"]])
8078 },
8079 {
8080 code: unIndent`
8081 foo(bar,
8082 1 + 2,
8083 !baz,
8084 new Car('!')
8085 );
8086 `,
8087 output: unIndent`
8088 foo(bar,
8089 1 + 2,
8090 !baz,
8091 new Car('!')
8092 );
8093 `,
8094 options: [2, { CallExpression: { arguments: 3 } }],
8095 errors: expectedErrors([[2, 6, 2, "Numeric"], [3, 6, 14, "Punctuator"], [4, 6, 8, "Keyword"]])
8096 },
8097
8098 // https://github.com/eslint/eslint/issues/7573
8099 {
8100 code: unIndent`
8101 return (
8102 foo
8103 );
8104 `,
8105 output: unIndent`
8106 return (
8107 foo
8108 );
8109 `,
8110 parserOptions: { ecmaFeatures: { globalReturn: true } },
8111 errors: expectedErrors([3, 0, 4, "Punctuator"])
8112 },
8113 {
8114 code: unIndent`
8115 return (
8116 foo
8117 )
8118 `,
8119 output: unIndent`
8120 return (
8121 foo
8122 )
8123 `,
8124 parserOptions: { ecmaFeatures: { globalReturn: true } },
8125 errors: expectedErrors([3, 0, 4, "Punctuator"])
8126 },
8127
8128 // https://github.com/eslint/eslint/issues/7604
8129 {
8130 code: unIndent`
8131 if (foo) {
8132 /* comment */bar();
8133 }
8134 `,
8135 output: unIndent`
8136 if (foo) {
8137 /* comment */bar();
8138 }
8139 `,
8140 errors: expectedErrors([2, 4, 8, "Block"])
8141 },
8142 {
8143 code: unIndent`
8144 foo('bar',
8145 /** comment */{
8146 ok: true
8147 });
8148 `,
8149 output: unIndent`
8150 foo('bar',
8151 /** comment */{
8152 ok: true
8153 });
8154 `,
8155 errors: expectedErrors([2, 4, 8, "Block"])
8156 },
8157 {
8158 code: unIndent`
8159 foo(
8160 (bar)
8161 );
8162 `,
8163 output: unIndent`
8164 foo(
8165 (bar)
8166 );
8167 `,
8168 options: [4, { CallExpression: { arguments: 1 } }],
8169 errors: expectedErrors([2, 4, 0, "Punctuator"])
8170 },
8171 {
8172 code: unIndent`
8173 ((
8174 foo
8175 ))
8176 `,
8177 output: unIndent`
8178 ((
8179 foo
8180 ))
8181 `,
8182 options: [4],
8183 errors: expectedErrors([2, 4, 0, "Identifier"])
8184 },
8185
8186 // ternary expressions (https://github.com/eslint/eslint/issues/7420)
8187 {
8188 code: unIndent`
8189 foo
8190 ? bar
8191 : baz
8192 `,
8193 output: unIndent`
8194 foo
8195 ? bar
8196 : baz
8197 `,
8198 options: [2],
8199 errors: expectedErrors([[2, 2, 0, "Punctuator"], [3, 2, 4, "Punctuator"]])
8200 },
8201 {
8202 code: unIndent`
8203 [
8204 foo ?
8205 bar :
8206 baz,
8207 qux
8208 ]
8209 `,
8210 output: unIndent`
8211 [
8212 foo ?
8213 bar :
8214 baz,
8215 qux
8216 ]
8217 `,
8218 errors: expectedErrors([5, 4, 8, "Identifier"])
8219 },
8220 {
8221 code: unIndent`
8222 condition
8223 ? () => {
8224 return true
8225 }
8226 : condition2
8227 ? () => {
8228 return true
8229 }
8230 : () => {
8231 return false
8232 }
8233 `,
8234 output: unIndent`
8235 condition
8236 ? () => {
8237 return true
8238 }
8239 : condition2
8240 ? () => {
8241 return true
8242 }
8243 : () => {
8244 return false
8245 }
8246 `,
8247 options: [2, { offsetTernaryExpressions: true }],
8248 errors: expectedErrors([
8249 [2, 2, 0, "Punctuator"],
8250 [3, 6, 0, "Keyword"],
8251 [4, 4, 0, "Punctuator"],
8252 [5, 2, 0, "Punctuator"],
8253 [6, 4, 0, "Punctuator"],
8254 [7, 8, 0, "Keyword"],
8255 [8, 6, 0, "Punctuator"],
8256 [9, 4, 0, "Punctuator"],
8257 [10, 8, 0, "Keyword"],
8258 [11, 6, 0, "Punctuator"]
8259 ])
8260 },
8261 {
8262 code: unIndent`
8263 condition
8264 ? () => {
8265 return true
8266 }
8267 : condition2
8268 ? () => {
8269 return true
8270 }
8271 : () => {
8272 return false
8273 }
8274 `,
8275 output: unIndent`
8276 condition
8277 ? () => {
8278 return true
8279 }
8280 : condition2
8281 ? () => {
8282 return true
8283 }
8284 : () => {
8285 return false
8286 }
8287 `,
8288 options: [2, { offsetTernaryExpressions: false }],
8289 errors: expectedErrors([
8290 [2, 2, 0, "Punctuator"],
8291 [3, 4, 0, "Keyword"],
8292 [4, 2, 0, "Punctuator"],
8293 [5, 2, 0, "Punctuator"],
8294 [6, 4, 0, "Punctuator"],
8295 [7, 6, 0, "Keyword"],
8296 [8, 4, 0, "Punctuator"],
8297 [9, 4, 0, "Punctuator"],
8298 [10, 6, 0, "Keyword"],
8299 [11, 4, 0, "Punctuator"]
8300 ])
8301 },
8302 {
8303
8304 /*
8305 * Checking comments:
8306 * https://github.com/eslint/eslint/issues/6571
8307 */
8308 code: unIndent`
8309 foo();
8310 // comment
8311 /* multiline
8312 comment */
8313 bar();
8314 // trailing comment
8315 `,
8316 output: unIndent`
8317 foo();
8318 // comment
8319 /* multiline
8320 comment */
8321 bar();
8322 // trailing comment
8323 `,
8324 options: [2],
8325 errors: expectedErrors([[2, 0, 2, "Line"], [3, 0, 4, "Block"], [6, 0, 1, "Line"]])
8326 },
8327 {
8328 code: " // comment",
8329 output: "// comment",
8330 errors: expectedErrors([1, 0, 2, "Line"])
8331 },
8332 {
8333 code: unIndent`
8334 foo
8335 // comment
8336 `,
8337 output: unIndent`
8338 foo
8339 // comment
8340 `,
8341 errors: expectedErrors([2, 0, 2, "Line"])
8342 },
8343 {
8344 code: unIndent`
8345 // comment
8346 foo
8347 `,
8348 output: unIndent`
8349 // comment
8350 foo
8351 `,
8352 errors: expectedErrors([1, 0, 2, "Line"])
8353 },
8354 {
8355 code: unIndent`
8356 [
8357 // no elements
8358 ]
8359 `,
8360 output: unIndent`
8361 [
8362 // no elements
8363 ]
8364 `,
8365 errors: expectedErrors([2, 4, 8, "Line"])
8366 },
8367 {
8368
8369 /*
8370 * Destructuring assignments:
8371 * https://github.com/eslint/eslint/issues/6813
8372 */
8373 code: unIndent`
8374 var {
8375 foo,
8376 bar,
8377 baz: qux,
8378 foobar: baz = foobar
8379 } = qux;
8380 `,
8381 output: unIndent`
8382 var {
8383 foo,
8384 bar,
8385 baz: qux,
8386 foobar: baz = foobar
8387 } = qux;
8388 `,
8389 options: [2],
8390 errors: expectedErrors([[2, 2, 0, "Identifier"], [4, 2, 4, "Identifier"], [5, 2, 6, "Identifier"], [6, 0, 2, "Punctuator"]])
8391 },
8392 {
8393 code: unIndent`
8394 const {
8395 a
8396 } = {
8397 a: 1
8398 }
8399 `,
8400 output: unIndent`
8401 const {
8402 a
8403 } = {
8404 a: 1
8405 }
8406 `,
8407 options: [2],
8408 errors: expectedErrors([[4, 2, 4, "Identifier"], [5, 0, 2, "Punctuator"]])
8409 },
8410 {
8411 code: unIndent`
8412 var foo = [
8413 bar,
8414 baz
8415 ]
8416 `,
8417 output: unIndent`
8418 var foo = [
8419 bar,
8420 baz
8421 ]
8422 `,
8423 errors: expectedErrors([[2, 4, 11, "Identifier"], [3, 4, 2, "Identifier"], [4, 0, 10, "Punctuator"]])
8424 },
8425 {
8426 code: unIndent`
8427 var foo = [bar,
8428 baz,
8429 qux
8430 ]
8431 `,
8432 output: unIndent`
8433 var foo = [bar,
8434 baz,
8435 qux
8436 ]
8437 `,
8438 errors: expectedErrors([2, 4, 0, "Identifier"])
8439 },
8440 {
8441 code: unIndent`
8442 var foo = [bar,
8443 baz,
8444 qux
8445 ]
8446 `,
8447 output: unIndent`
8448 var foo = [bar,
8449 baz,
8450 qux
8451 ]
8452 `,
8453 options: [2, { ArrayExpression: 0 }],
8454 errors: expectedErrors([[2, 0, 2, "Identifier"], [3, 0, 2, "Identifier"]])
8455 },
8456 {
8457 code: unIndent`
8458 var foo = [bar,
8459 baz,
8460 qux
8461 ]
8462 `,
8463 output: unIndent`
8464 var foo = [bar,
8465 baz,
8466 qux
8467 ]
8468 `,
8469 options: [2, { ArrayExpression: 8 }],
8470 errors: expectedErrors([[2, 16, 2, "Identifier"], [3, 16, 2, "Identifier"]])
8471 },
8472 {
8473 code: unIndent`
8474 var foo = [bar,
8475 baz,
8476 qux
8477 ]
8478 `,
8479 output: unIndent`
8480 var foo = [bar,
8481 baz,
8482 qux
8483 ]
8484 `,
8485 options: [2, { ArrayExpression: "first" }],
8486 errors: expectedErrors([[2, 11, 4, "Identifier"], [3, 11, 4, "Identifier"]])
8487 },
8488 {
8489 code: unIndent`
8490 var foo = [bar,
8491 baz, qux
8492 ]
8493 `,
8494 output: unIndent`
8495 var foo = [bar,
8496 baz, qux
8497 ]
8498 `,
8499 options: [2, { ArrayExpression: "first" }],
8500 errors: expectedErrors([2, 11, 4, "Identifier"])
8501 },
8502 {
8503 code: unIndent`
8504 var foo = [
8505 { bar: 1,
8506 baz: 2 },
8507 { bar: 3,
8508 qux: 4 }
8509 ]
8510 `,
8511 output: unIndent`
8512 var foo = [
8513 { bar: 1,
8514 baz: 2 },
8515 { bar: 3,
8516 qux: 4 }
8517 ]
8518 `,
8519 options: [4, { ArrayExpression: 2, ObjectExpression: "first" }],
8520 errors: expectedErrors([[3, 10, 12, "Identifier"], [5, 10, 12, "Identifier"]])
8521 },
8522 {
8523 code: unIndent`
8524 var foo = {
8525 bar: 1,
8526 baz: 2
8527 };
8528 `,
8529 output: unIndent`
8530 var foo = {
8531 bar: 1,
8532 baz: 2
8533 };
8534 `,
8535 options: [2, { ObjectExpression: 0 }],
8536 errors: expectedErrors([[2, 0, 2, "Identifier"], [3, 0, 2, "Identifier"]])
8537 },
8538 {
8539 code: unIndent`
8540 var quux = { foo: 1, bar: 2,
8541 baz: 3 }
8542 `,
8543 output: unIndent`
8544 var quux = { foo: 1, bar: 2,
8545 baz: 3 }
8546 `,
8547 options: [2, { ObjectExpression: "first" }],
8548 errors: expectedErrors([2, 13, 0, "Identifier"])
8549 },
8550 {
8551 code: unIndent`
8552 function foo() {
8553 [
8554 foo
8555 ]
8556 }
8557 `,
8558 output: unIndent`
8559 function foo() {
8560 [
8561 foo
8562 ]
8563 }
8564 `,
8565 options: [2, { ArrayExpression: 4 }],
8566 errors: expectedErrors([[2, 2, 4, "Punctuator"], [3, 10, 12, "Identifier"], [4, 2, 4, "Punctuator"]])
8567 },
8568 {
8569 code: unIndent`
8570 var [
8571 foo,
8572 bar,
8573 baz,
8574 foobar = baz
8575 ] = qux;
8576 `,
8577 output: unIndent`
8578 var [
8579 foo,
8580 bar,
8581 baz,
8582 foobar = baz
8583 ] = qux;
8584 `,
8585 options: [2],
8586 errors: expectedErrors([[2, 2, 0, "Identifier"], [4, 2, 4, "Identifier"], [5, 2, 6, "Identifier"], [6, 0, 2, "Punctuator"]])
8587 },
8588 {
8589 code: unIndent`
8590 import {
8591 foo,
8592 bar,
8593 baz
8594 } from 'qux';
8595 `,
8596 output: unIndent`
8597 import {
8598 foo,
8599 bar,
8600 baz
8601 } from 'qux';
8602 `,
8603 parserOptions: { ecmaVersion: 6, sourceType: "module" },
8604 errors: expectedErrors([[2, 4, 0, "Identifier"], [3, 4, 2, "Identifier"]])
8605 },
8606 {
8607 code: unIndent`
8608 import { foo,
8609 bar,
8610 baz,
8611 } from 'qux';
8612 `,
8613 output: unIndent`
8614 import { foo,
8615 bar,
8616 baz,
8617 } from 'qux';
8618 `,
8619 options: [4, { ImportDeclaration: "first" }],
8620 parserOptions: { ecmaVersion: 6, sourceType: "module" },
8621 errors: expectedErrors([[3, 9, 10, "Identifier"]])
8622 },
8623 {
8624 code: unIndent`
8625 import { foo,
8626 bar,
8627 baz,
8628 } from 'qux';
8629 `,
8630 output: unIndent`
8631 import { foo,
8632 bar,
8633 baz,
8634 } from 'qux';
8635 `,
8636 options: [2, { ImportDeclaration: 2 }],
8637 parserOptions: { ecmaVersion: 6, sourceType: "module" },
8638 errors: expectedErrors([[3, 4, 5, "Identifier"]])
8639 },
8640 {
8641 code: unIndent`
8642 var foo = 0, bar = 0, baz = 0;
8643 export {
8644 foo,
8645 bar,
8646 baz
8647 };
8648 `,
8649 output: unIndent`
8650 var foo = 0, bar = 0, baz = 0;
8651 export {
8652 foo,
8653 bar,
8654 baz
8655 };
8656 `,
8657 parserOptions: { ecmaVersion: 6, sourceType: "module" },
8658 errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 2, "Identifier"]])
8659 },
8660 {
8661 code: unIndent`
8662 var foo = 0, bar = 0, baz = 0;
8663 export {
8664 foo,
8665 bar,
8666 baz
8667 } from 'qux';
8668 `,
8669 output: unIndent`
8670 var foo = 0, bar = 0, baz = 0;
8671 export {
8672 foo,
8673 bar,
8674 baz
8675 } from 'qux';
8676 `,
8677 parserOptions: { ecmaVersion: 6, sourceType: "module" },
8678 errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 2, "Identifier"]])
8679 },
8680 {
8681
8682 // https://github.com/eslint/eslint/issues/7233
8683 code: unIndent`
8684 var folder = filePath
8685 .foo()
8686 .bar;
8687 `,
8688 output: unIndent`
8689 var folder = filePath
8690 .foo()
8691 .bar;
8692 `,
8693 options: [2, { MemberExpression: 2 }],
8694 errors: expectedErrors([[2, 4, 2, "Punctuator"], [3, 4, 6, "Punctuator"]])
8695 },
8696 {
8697 code: unIndent`
8698 for (const foo of bar)
8699 baz();
8700 `,
8701 output: unIndent`
8702 for (const foo of bar)
8703 baz();
8704 `,
8705 options: [2],
8706 errors: expectedErrors([2, 2, 4, "Identifier"])
8707 },
8708 {
8709 code: unIndent`
8710 var x = () =>
8711 5;
8712 `,
8713 output: unIndent`
8714 var x = () =>
8715 5;
8716 `,
8717 options: [2],
8718 errors: expectedErrors([2, 2, 4, "Numeric"])
8719 },
8720 {
8721
8722 // BinaryExpressions with parens
8723 code: unIndent`
8724 foo && (
8725 bar
8726 )
8727 `,
8728 output: unIndent`
8729 foo && (
8730 bar
8731 )
8732 `,
8733 options: [4],
8734 errors: expectedErrors([2, 4, 8, "Identifier"])
8735 },
8736 {
8737 code: unIndent`
8738 foo &&
8739 !bar(
8740 )
8741 `,
8742 output: unIndent`
8743 foo &&
8744 !bar(
8745 )
8746 `,
8747 errors: expectedErrors([3, 4, 0, "Punctuator"])
8748 },
8749 {
8750 code: unIndent`
8751 foo &&
8752 ![].map(() => {
8753 bar();
8754 })
8755 `,
8756 output: unIndent`
8757 foo &&
8758 ![].map(() => {
8759 bar();
8760 })
8761 `,
8762 errors: expectedErrors([[3, 8, 4, "Identifier"], [4, 4, 0, "Punctuator"]])
8763 },
8764 {
8765 code: unIndent`
8766 [
8767 ] || [
8768 ]
8769 `,
8770 output: unIndent`
8771 [
8772 ] || [
8773 ]
8774 `,
8775 errors: expectedErrors([3, 0, 4, "Punctuator"])
8776 },
8777 {
8778 code: unIndent`
8779 foo
8780 || (
8781 bar
8782 )
8783 `,
8784 output: unIndent`
8785 foo
8786 || (
8787 bar
8788 )
8789 `,
8790 errors: expectedErrors([[3, 12, 16, "Identifier"], [4, 8, 12, "Punctuator"]])
8791 },
8792 {
8793 code: unIndent`
8794 1
8795 + (
8796 1
8797 )
8798 `,
8799 output: unIndent`
8800 1
8801 + (
8802 1
8803 )
8804 `,
8805 errors: expectedErrors([[3, 4, 8, "Numeric"], [4, 0, 4, "Punctuator"]])
8806 },
8807
8808 // Template curlies
8809 {
8810 code: unIndent`
8811 \`foo\${
8812 bar}\`
8813 `,
8814 output: unIndent`
8815 \`foo\${
8816 bar}\`
8817 `,
8818 options: [2],
8819 errors: expectedErrors([2, 2, 0, "Identifier"])
8820 },
8821 {
8822 code: unIndent`
8823 \`foo\${
8824 \`bar\${
8825 baz}\`}\`
8826 `,
8827 output: unIndent`
8828 \`foo\${
8829 \`bar\${
8830 baz}\`}\`
8831 `,
8832 options: [2],
8833 errors: expectedErrors([[2, 2, 4, "Template"], [3, 4, 0, "Identifier"]])
8834 },
8835 {
8836 code: unIndent`
8837 \`foo\${
8838 \`bar\${
8839 baz
8840 }\`
8841 }\`
8842 `,
8843 output: unIndent`
8844 \`foo\${
8845 \`bar\${
8846 baz
8847 }\`
8848 }\`
8849 `,
8850 options: [2],
8851 errors: expectedErrors([[2, 2, 4, "Template"], [3, 4, 2, "Identifier"], [4, 2, 4, "Template"], [5, 0, 2, "Template"]])
8852 },
8853 {
8854 code: unIndent`
8855 \`foo\${
8856 (
8857 bar
8858 )
8859 }\`
8860 `,
8861 output: unIndent`
8862 \`foo\${
8863 (
8864 bar
8865 )
8866 }\`
8867 `,
8868 options: [2],
8869 errors: expectedErrors([[2, 2, 0, "Punctuator"], [3, 4, 2, "Identifier"], [4, 2, 0, "Punctuator"]])
8870 },
8871 {
8872 code: unIndent`
8873 function foo() {
8874 \`foo\${bar}baz\${
8875 qux}foo\${
8876 bar}baz\`
8877 }
8878 `,
8879 output: unIndent`
8880 function foo() {
8881 \`foo\${bar}baz\${
8882 qux}foo\${
8883 bar}baz\`
8884 }
8885 `,
8886 errors: expectedErrors([[3, 8, 0, "Identifier"], [4, 8, 2, "Identifier"]])
8887 },
8888 {
8889 code: unIndent`
8890 function foo() {
8891 const template = \`the indentation of
8892 a curly element in a \${
8893 node.type
8894 } node is checked.\`;
8895 }
8896 `,
8897 output: unIndent`
8898 function foo() {
8899 const template = \`the indentation of
8900 a curly element in a \${
8901 node.type
8902 } node is checked.\`;
8903 }
8904 `,
8905 errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Template"]])
8906 },
8907 {
8908 code: unIndent`
8909 function foo() {
8910 const template = \`this time the
8911 closing curly is at the end of the line \${
8912 foo}
8913 so the spaces before this line aren't removed.\`;
8914 }
8915 `,
8916 output: unIndent`
8917 function foo() {
8918 const template = \`this time the
8919 closing curly is at the end of the line \${
8920 foo}
8921 so the spaces before this line aren't removed.\`;
8922 }
8923 `,
8924 errors: expectedErrors([4, 4, 12, "Identifier"])
8925 },
8926 {
8927
8928 /*
8929 * https://github.com/eslint/eslint/issues/1801
8930 * Note: This issue also mentioned checking the indentation for the 2 below. However,
8931 * this is intentionally ignored because everyone seems to have a different idea of how
8932 * BinaryExpressions should be indented.
8933 */
8934 code: unIndent`
8935 if (true) {
8936 a = (
8937 1 +
8938 2);
8939 }
8940 `,
8941 output: unIndent`
8942 if (true) {
8943 a = (
8944 1 +
8945 2);
8946 }
8947 `,
8948 errors: expectedErrors([3, 8, 0, "Numeric"])
8949 },
8950 {
8951
8952 // https://github.com/eslint/eslint/issues/3737
8953 code: unIndent`
8954 if (true) {
8955 for (;;) {
8956 b();
8957 }
8958 }
8959 `,
8960 output: unIndent`
8961 if (true) {
8962 for (;;) {
8963 b();
8964 }
8965 }
8966 `,
8967 options: [2],
8968 errors: expectedErrors([[2, 2, 4, "Keyword"], [3, 4, 6, "Identifier"]])
8969 },
8970 {
8971
8972 // https://github.com/eslint/eslint/issues/6670
8973 code: unIndent`
8974 function f() {
8975 return asyncCall()
8976 .then(
8977 'some string',
8978 [
8979 1,
8980 2,
8981 3
8982 ]
8983 );
8984 }
8985 `,
8986 output: unIndent`
8987 function f() {
8988 return asyncCall()
8989 .then(
8990 'some string',
8991 [
8992 1,
8993 2,
8994 3
8995 ]
8996 );
8997 }
8998 `,
8999 options: [4, { MemberExpression: 1, CallExpression: { arguments: 1 } }],
9000 errors: expectedErrors([
9001 [3, 8, 4, "Punctuator"],
9002 [4, 12, 15, "String"],
9003 [5, 12, 14, "Punctuator"],
9004 [6, 16, 14, "Numeric"],
9005 [7, 16, 9, "Numeric"],
9006 [8, 16, 35, "Numeric"],
9007 [9, 12, 22, "Punctuator"],
9008 [10, 8, 0, "Punctuator"],
9009 [11, 0, 1, "Punctuator"]
9010 ])
9011 },
9012
9013 // https://github.com/eslint/eslint/issues/7242
9014 {
9015 code: unIndent`
9016 var x = [
9017 [1],
9018 [2]
9019 ]
9020 `,
9021 output: unIndent`
9022 var x = [
9023 [1],
9024 [2]
9025 ]
9026 `,
9027 errors: expectedErrors([[2, 4, 6, "Punctuator"], [3, 4, 2, "Punctuator"]])
9028 },
9029 {
9030 code: unIndent`
9031 var y = [
9032 {a: 1},
9033 {b: 2}
9034 ]
9035 `,
9036 output: unIndent`
9037 var y = [
9038 {a: 1},
9039 {b: 2}
9040 ]
9041 `,
9042 errors: expectedErrors([[2, 4, 6, "Punctuator"], [3, 4, 2, "Punctuator"]])
9043 },
9044 {
9045 code: unIndent`
9046 echo = spawn('cmd.exe',
9047 ['foo', 'bar',
9048 'baz']);
9049 `,
9050 output: unIndent`
9051 echo = spawn('cmd.exe',
9052 ['foo', 'bar',
9053 'baz']);
9054 `,
9055 options: [2, { ArrayExpression: "first", CallExpression: { arguments: "first" } }],
9056 errors: expectedErrors([[2, 13, 12, "Punctuator"], [3, 14, 13, "String"]])
9057 },
9058 {
9059
9060 // https://github.com/eslint/eslint/issues/7522
9061 code: unIndent`
9062 foo(
9063 )
9064 `,
9065 output: unIndent`
9066 foo(
9067 )
9068 `,
9069 errors: expectedErrors([2, 0, 2, "Punctuator"])
9070 },
9071 {
9072
9073 // https://github.com/eslint/eslint/issues/7616
9074 code: unIndent`
9075 foo(
9076 bar,
9077 {
9078 baz: 1
9079 }
9080 )
9081 `,
9082 output: unIndent`
9083 foo(
9084 bar,
9085 {
9086 baz: 1
9087 }
9088 )
9089 `,
9090 options: [4, { CallExpression: { arguments: "first" } }],
9091 errors: expectedErrors([[2, 4, 8, "Identifier"]])
9092 },
9093 {
9094 code: " new Foo",
9095 output: "new Foo",
9096 errors: expectedErrors([1, 0, 2, "Keyword"])
9097 },
9098 {
9099 code: unIndent`
9100 var foo = 0, bar = 0, baz = 0;
9101 export {
9102 foo,
9103 bar,
9104 baz
9105 }
9106 `,
9107 output: unIndent`
9108 var foo = 0, bar = 0, baz = 0;
9109 export {
9110 foo,
9111 bar,
9112 baz
9113 }
9114 `,
9115 parserOptions: { ecmaVersion: 6, sourceType: "module" },
9116 errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 8, "Identifier"], [5, 4, 2, "Identifier"]])
9117 },
9118 {
9119 code: unIndent`
9120 foo
9121 ? bar
9122 : baz
9123 `,
9124 output: unIndent`
9125 foo
9126 ? bar
9127 : baz
9128 `,
9129 options: [4, { flatTernaryExpressions: true }],
9130 errors: expectedErrors([3, 4, 0, "Punctuator"])
9131 },
9132 {
9133 code: unIndent`
9134 foo ?
9135 bar :
9136 baz
9137 `,
9138 output: unIndent`
9139 foo ?
9140 bar :
9141 baz
9142 `,
9143 options: [4, { flatTernaryExpressions: true }],
9144 errors: expectedErrors([3, 4, 0, "Identifier"])
9145 },
9146 {
9147 code: unIndent`
9148 foo ?
9149 bar
9150 : baz
9151 `,
9152 output: unIndent`
9153 foo ?
9154 bar
9155 : baz
9156 `,
9157 options: [4, { flatTernaryExpressions: true }],
9158 errors: expectedErrors([3, 4, 2, "Punctuator"])
9159 },
9160 {
9161 code: unIndent`
9162 foo
9163 ? bar :
9164 baz
9165 `,
9166 output: unIndent`
9167 foo
9168 ? bar :
9169 baz
9170 `,
9171 options: [4, { flatTernaryExpressions: true }],
9172 errors: expectedErrors([3, 4, 0, "Identifier"])
9173 },
9174 {
9175 code: unIndent`
9176 foo ? bar
9177 : baz ? qux
9178 : foobar ? boop
9179 : beep
9180 `,
9181 output: unIndent`
9182 foo ? bar
9183 : baz ? qux
9184 : foobar ? boop
9185 : beep
9186 `,
9187 options: [4, { flatTernaryExpressions: true }],
9188 errors: expectedErrors([
9189 [3, 4, 8, "Punctuator"],
9190 [4, 4, 12, "Punctuator"]
9191 ])
9192 },
9193 {
9194 code: unIndent`
9195 foo ? bar :
9196 baz ? qux :
9197 foobar ? boop :
9198 beep
9199 `,
9200 output: unIndent`
9201 foo ? bar :
9202 baz ? qux :
9203 foobar ? boop :
9204 beep
9205 `,
9206 options: [4, { flatTernaryExpressions: true }],
9207 errors: expectedErrors([
9208 [3, 4, 8, "Identifier"],
9209 [4, 4, 12, "Identifier"]
9210 ])
9211 },
9212 {
9213 code: unIndent`
9214 var a =
9215 foo ? bar :
9216 baz ? qux :
9217 foobar ? boop :
9218 /*else*/ beep
9219 `,
9220 output: unIndent`
9221 var a =
9222 foo ? bar :
9223 baz ? qux :
9224 foobar ? boop :
9225 /*else*/ beep
9226 `,
9227 options: [4, { flatTernaryExpressions: true }],
9228 errors: expectedErrors([
9229 [3, 4, 6, "Identifier"],
9230 [4, 4, 2, "Identifier"]
9231 ])
9232 },
9233 {
9234 code: unIndent`
9235 var a =
9236 foo
9237 ? bar
9238 : baz
9239 `,
9240 output: unIndent`
9241 var a =
9242 foo
9243 ? bar
9244 : baz
9245 `,
9246 options: [4, { flatTernaryExpressions: true }],
9247 errors: expectedErrors([
9248 [3, 8, 4, "Punctuator"],
9249 [4, 8, 4, "Punctuator"]
9250 ])
9251 },
9252 {
9253 code: unIndent`
9254 foo ? bar
9255 : baz ? qux
9256 : foobar ? boop
9257 : beep
9258 `,
9259 output: unIndent`
9260 foo ? bar
9261 : baz ? qux
9262 : foobar ? boop
9263 : beep
9264 `,
9265 options: [4, { flatTernaryExpressions: false }],
9266 errors: expectedErrors([
9267 [3, 8, 4, "Punctuator"],
9268 [4, 12, 4, "Punctuator"]
9269 ])
9270 },
9271 {
9272 code: unIndent`
9273 foo ? bar :
9274 baz ? qux :
9275 foobar ? boop :
9276 beep
9277 `,
9278 output: unIndent`
9279 foo ? bar :
9280 baz ? qux :
9281 foobar ? boop :
9282 beep
9283 `,
9284 options: [4, { flatTernaryExpressions: false }],
9285 errors: expectedErrors([
9286 [3, 8, 4, "Identifier"],
9287 [4, 12, 4, "Identifier"]
9288 ])
9289 },
9290 {
9291 code: unIndent`
9292 foo
9293 ? bar
9294 : baz
9295 ? qux
9296 : foobar
9297 ? boop
9298 : beep
9299 `,
9300 output: unIndent`
9301 foo
9302 ? bar
9303 : baz
9304 ? qux
9305 : foobar
9306 ? boop
9307 : beep
9308 `,
9309 options: [4, { flatTernaryExpressions: false }],
9310 errors: expectedErrors([
9311 [4, 8, 4, "Punctuator"],
9312 [5, 8, 4, "Punctuator"],
9313 [6, 12, 4, "Punctuator"],
9314 [7, 12, 4, "Punctuator"]
9315 ])
9316 },
9317 {
9318 code: unIndent`
9319 foo ?
9320 bar :
9321 baz ?
9322 qux :
9323 foobar ?
9324 boop :
9325 beep
9326 `,
9327 output: unIndent`
9328 foo ?
9329 bar :
9330 baz ?
9331 qux :
9332 foobar ?
9333 boop :
9334 beep
9335 `,
9336 options: [4, { flatTernaryExpressions: false }],
9337 errors: expectedErrors([
9338 [4, 8, 4, "Identifier"],
9339 [5, 8, 4, "Identifier"],
9340 [6, 12, 4, "Identifier"],
9341 [7, 12, 4, "Identifier"]
9342 ])
9343 },
9344 {
9345 code: unIndent`
9346 foo.bar('baz', function(err) {
9347 qux;
9348 });
9349 `,
9350 output: unIndent`
9351 foo.bar('baz', function(err) {
9352 qux;
9353 });
9354 `,
9355 options: [2, { CallExpression: { arguments: "first" } }],
9356 errors: expectedErrors([2, 2, 10, "Identifier"])
9357 },
9358 {
9359 code: unIndent`
9360 foo.bar(function() {
9361 cookies;
9362 }).baz(function() {
9363 cookies;
9364 });
9365 `,
9366 output: unIndent`
9367 foo.bar(function() {
9368 cookies;
9369 }).baz(function() {
9370 cookies;
9371 });
9372 `,
9373 options: [2, { MemberExpression: 1 }],
9374 errors: expectedErrors([[4, 2, 4, "Identifier"], [5, 0, 2, "Punctuator"]])
9375 },
9376 {
9377 code: unIndent`
9378 foo.bar().baz(function() {
9379 cookies;
9380 }).qux(function() {
9381 cookies;
9382 });
9383 `,
9384 output: unIndent`
9385 foo.bar().baz(function() {
9386 cookies;
9387 }).qux(function() {
9388 cookies;
9389 });
9390 `,
9391 options: [2, { MemberExpression: 1 }],
9392 errors: expectedErrors([[4, 2, 4, "Identifier"], [5, 0, 2, "Punctuator"]])
9393 },
9394 {
9395 code: unIndent`
9396 [ foo,
9397 bar ].forEach(function() {
9398 baz;
9399 })
9400 `,
9401 output: unIndent`
9402 [ foo,
9403 bar ].forEach(function() {
9404 baz;
9405 })
9406 `,
9407 options: [2, { ArrayExpression: "first", MemberExpression: 1 }],
9408 errors: expectedErrors([[3, 2, 4, "Identifier"], [4, 0, 2, "Punctuator"]])
9409 },
9410 {
9411 code: unIndent`
9412 foo[
9413 bar
9414 ];
9415 `,
9416 output: unIndent`
9417 foo[
9418 bar
9419 ];
9420 `,
9421 options: [4, { MemberExpression: 1 }],
9422 errors: expectedErrors([3, 0, 4, "Punctuator"])
9423 },
9424 {
9425 code: unIndent`
9426 foo({
9427 bar: 1,
9428 baz: 2
9429 })
9430 `,
9431 output: unIndent`
9432 foo({
9433 bar: 1,
9434 baz: 2
9435 })
9436 `,
9437 options: [4, { ObjectExpression: "first" }],
9438 errors: expectedErrors([[2, 4, 0, "Identifier"], [3, 4, 0, "Identifier"]])
9439 },
9440 {
9441 code: unIndent`
9442 foo(
9443 bar, baz,
9444 qux);
9445 `,
9446 output: unIndent`
9447 foo(
9448 bar, baz,
9449 qux);
9450 `,
9451 options: [2, { CallExpression: { arguments: "first" } }],
9452 errors: expectedErrors([[2, 2, 24, "Identifier"], [3, 2, 24, "Identifier"]])
9453 },
9454 {
9455 code: unIndent`
9456 if (foo) bar()
9457
9458 ; [1, 2, 3].map(baz)
9459 `,
9460 output: unIndent`
9461 if (foo) bar()
9462
9463 ; [1, 2, 3].map(baz)
9464 `,
9465 errors: expectedErrors([3, 0, 4, "Punctuator"])
9466 },
9467 {
9468 code: unIndent`
9469 if (foo)
9470 ;
9471 `,
9472 output: unIndent`
9473 if (foo)
9474 ;
9475 `,
9476 errors: expectedErrors([2, 4, 0, "Punctuator"])
9477 },
9478 {
9479 code: unIndent`
9480 import {foo}
9481 from 'bar';
9482 `,
9483 output: unIndent`
9484 import {foo}
9485 from 'bar';
9486 `,
9487 parserOptions: { ecmaVersion: 6, sourceType: "module" },
9488 errors: expectedErrors([2, 4, 0, "Identifier"])
9489 },
9490 {
9491 code: unIndent`
9492 export {foo}
9493 from 'bar';
9494 `,
9495 output: unIndent`
9496 export {foo}
9497 from 'bar';
9498 `,
9499 parserOptions: { ecmaVersion: 6, sourceType: "module" },
9500 errors: expectedErrors([2, 4, 0, "Identifier"])
9501 },
9502 {
9503 code: unIndent`
9504 (
9505 a
9506 ) => b => {
9507 c
9508 }
9509 `,
9510 output: unIndent`
9511 (
9512 a
9513 ) => b => {
9514 c
9515 }
9516 `,
9517 errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
9518 },
9519 {
9520 code: unIndent`
9521 (
9522 a
9523 ) => b => c => d => {
9524 e
9525 }
9526 `,
9527 output: unIndent`
9528 (
9529 a
9530 ) => b => c => d => {
9531 e
9532 }
9533 `,
9534 errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
9535 },
9536 {
9537 code: unIndent`
9538 if (
9539 foo
9540 ) bar(
9541 baz
9542 );
9543 `,
9544 output: unIndent`
9545 if (
9546 foo
9547 ) bar(
9548 baz
9549 );
9550 `,
9551 errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
9552 },
9553 {
9554 code: unIndent`
9555 (
9556 foo
9557 )(
9558 bar
9559 )
9560 `,
9561 output: unIndent`
9562 (
9563 foo
9564 )(
9565 bar
9566 )
9567 `,
9568 errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
9569 },
9570 {
9571 code: unIndent`
9572 (() =>
9573 foo
9574 )(
9575 bar
9576 )
9577 `,
9578 output: unIndent`
9579 (() =>
9580 foo
9581 )(
9582 bar
9583 )
9584 `,
9585 errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
9586 },
9587 {
9588 code: unIndent`
9589 (() => {
9590 foo();
9591 })(
9592 bar
9593 )
9594 `,
9595 output: unIndent`
9596 (() => {
9597 foo();
9598 })(
9599 bar
9600 )
9601 `,
9602 errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
9603 },
9604 {
9605 code: unIndent`
9606 foo.
9607 bar.
9608 baz
9609 `,
9610 output: unIndent`
9611 foo.
9612 bar.
9613 baz
9614 `,
9615 errors: expectedErrors([[2, 4, 2, "Identifier"], [3, 4, 6, "Identifier"]])
9616 },
9617 {
9618 code: unIndent`
9619 const foo = a.b(),
9620 longName
9621 = (baz(
9622 'bar',
9623 'bar'
9624 ));
9625 `,
9626 output: unIndent`
9627 const foo = a.b(),
9628 longName
9629 = (baz(
9630 'bar',
9631 'bar'
9632 ));
9633 `,
9634 errors: expectedErrors([[4, 8, 12, "String"], [5, 8, 12, "String"], [6, 4, 8, "Punctuator"]])
9635 },
9636 {
9637 code: unIndent`
9638 const foo = a.b(),
9639 longName =
9640 (baz(
9641 'bar',
9642 'bar'
9643 ));
9644 `,
9645 output: unIndent`
9646 const foo = a.b(),
9647 longName =
9648 (baz(
9649 'bar',
9650 'bar'
9651 ));
9652 `,
9653 errors: expectedErrors([[4, 8, 12, "String"], [5, 8, 12, "String"], [6, 4, 8, "Punctuator"]])
9654 },
9655 {
9656 code: unIndent`
9657 const foo = a.b(),
9658 longName
9659 =baz(
9660 'bar',
9661 'bar'
9662 );
9663 `,
9664 output: unIndent`
9665 const foo = a.b(),
9666 longName
9667 =baz(
9668 'bar',
9669 'bar'
9670 );
9671 `,
9672 errors: expectedErrors([[6, 8, 4, "Punctuator"]])
9673 },
9674 {
9675 code: unIndent`
9676 const foo = a.b(),
9677 longName
9678 =(
9679 'fff'
9680 );
9681 `,
9682 output: unIndent`
9683 const foo = a.b(),
9684 longName
9685 =(
9686 'fff'
9687 );
9688 `,
9689 errors: expectedErrors([[4, 12, 8, "String"]])
9690 },
9691
9692 //----------------------------------------------------------------------
9693 // Ignore Unknown Nodes
9694 //----------------------------------------------------------------------
9695
9696 {
9697 code: unIndent`
9698 namespace Foo {
9699 const bar = 3,
9700 baz = 2;
9701
9702 if (true) {
9703 const bax = 3;
9704 }
9705 }
9706 `,
9707 output: unIndent`
9708 namespace Foo {
9709 const bar = 3,
9710 baz = 2;
9711
9712 if (true) {
9713 const bax = 3;
9714 }
9715 }
9716 `,
9717 parser: parser("unknown-nodes/namespace-invalid"),
9718 errors: expectedErrors([[3, 8, 4, "Identifier"], [6, 8, 4, "Keyword"]])
9719 },
9720 {
9721 code: unIndent`
9722 abstract class Foo {
9723 public bar() {
9724 let aaa = 4,
9725 boo;
9726
9727 if (true) {
9728 boo = 3;
9729 }
9730
9731 boo = 3 + 2;
9732 }
9733 }
9734 `,
9735 output: unIndent`
9736 abstract class Foo {
9737 public bar() {
9738 let aaa = 4,
9739 boo;
9740
9741 if (true) {
9742 boo = 3;
9743 }
9744
9745 boo = 3 + 2;
9746 }
9747 }
9748 `,
9749 parser: parser("unknown-nodes/abstract-class-invalid"),
9750 errors: expectedErrors([[4, 12, 8, "Identifier"], [7, 12, 8, "Identifier"], [10, 8, 4, "Identifier"]])
9751 },
9752 {
9753 code: unIndent`
9754 function foo() {
9755 function bar() {
9756 abstract class X {
9757 public baz() {
9758 if (true) {
9759 qux();
9760 }
9761 }
9762 }
9763 }
9764 }
9765 `,
9766 output: unIndent`
9767 function foo() {
9768 function bar() {
9769 abstract class X {
9770 public baz() {
9771 if (true) {
9772 qux();
9773 }
9774 }
9775 }
9776 }
9777 }
9778 `,
9779 parser: parser("unknown-nodes/functions-with-abstract-class-invalid"),
9780 errors: expectedErrors([
9781 [4, 12, 8, "Keyword"],
9782 [5, 16, 8, "Keyword"],
9783 [6, 20, 8, "Identifier"],
9784 [7, 16, 8, "Punctuator"],
9785 [8, 12, 8, "Punctuator"]
9786 ])
9787 },
9788 {
9789 code: unIndent`
9790 namespace Unknown {
9791 function foo() {
9792 function bar() {
9793 abstract class X {
9794 public baz() {
9795 if (true) {
9796 qux();
9797 }
9798 }
9799 }
9800 }
9801 }
9802 }
9803 `,
9804 output: unIndent`
9805 namespace Unknown {
9806 function foo() {
9807 function bar() {
9808 abstract class X {
9809 public baz() {
9810 if (true) {
9811 qux();
9812 }
9813 }
9814 }
9815 }
9816 }
9817 }
9818 `,
9819 parser: parser("unknown-nodes/namespace-with-functions-with-abstract-class-invalid"),
9820 errors: expectedErrors([
9821 [3, 8, 4, "Keyword"],
9822 [7, 24, 20, "Identifier"]
9823 ])
9824 },
9825
9826 //----------------------------------------------------------------------
9827 // JSX tests
9828 // Some of the following tests are adapted from the the tests in eslint-plugin-react.
9829 // License: https://github.com/yannickcr/eslint-plugin-react/blob/7ca9841f22d599f447a27ef5b2a97def9229d6c8/LICENSE
9830 //----------------------------------------------------------------------
9831
9832 {
9833 code: unIndent`
9834 <App>
9835 <Foo />
9836 </App>
9837 `,
9838 output: unIndent`
9839 <App>
9840 <Foo />
9841 </App>
9842 `,
9843 errors: expectedErrors([2, 4, 2, "Punctuator"])
9844 },
9845 {
9846 code: unIndent`
9847 <App>
9848 <Foo />
9849 </App>
9850 `,
9851 output: unIndent`
9852 <App>
9853 <Foo />
9854 </App>
9855 `,
9856 options: [2],
9857 errors: expectedErrors([2, 2, 4, "Punctuator"])
9858 },
9859 {
9860 code: unIndent`
9861 <App>
9862 <Foo />
9863 </App>
9864 `,
9865 output: unIndent`
9866 <App>
9867 \t<Foo />
9868 </App>
9869 `,
9870 options: ["tab"],
9871 errors: expectedErrors([2, "1 tab", "4 spaces", "Punctuator"])
9872 },
9873 {
9874 code: unIndent`
9875 function App() {
9876 return <App>
9877 <Foo />
9878 </App>;
9879 }
9880 `,
9881 output: unIndent`
9882 function App() {
9883 return <App>
9884 <Foo />
9885 </App>;
9886 }
9887 `,
9888 options: [2],
9889 errors: expectedErrors([4, 2, 9, "Punctuator"])
9890 },
9891 {
9892 code: unIndent`
9893 function App() {
9894 return (<App>
9895 <Foo />
9896 </App>);
9897 }
9898 `,
9899 output: unIndent`
9900 function App() {
9901 return (<App>
9902 <Foo />
9903 </App>);
9904 }
9905 `,
9906 options: [2],
9907 errors: expectedErrors([4, 2, 4, "Punctuator"])
9908 },
9909 {
9910 code: unIndent`
9911 function App() {
9912 return (
9913 <App>
9914 <Foo />
9915 </App>
9916 );
9917 }
9918 `,
9919 output: unIndent`
9920 function App() {
9921 return (
9922 <App>
9923 <Foo />
9924 </App>
9925 );
9926 }
9927 `,
9928 options: [2],
9929 errors: expectedErrors([[3, 4, 0, "Punctuator"], [4, 6, 2, "Punctuator"], [5, 4, 0, "Punctuator"]])
9930 },
9931 {
9932 code: unIndent`
9933 <App>
9934 {test}
9935 </App>
9936 `,
9937 output: unIndent`
9938 <App>
9939 {test}
9940 </App>
9941 `,
9942 errors: expectedErrors([2, 4, 1, "Punctuator"])
9943 },
9944 {
9945 code: unIndent`
9946 <App>
9947 {options.map((option, index) => (
9948 <option key={index} value={option.key}>
9949 {option.name}
9950 </option>
9951 ))}
9952 </App>
9953 `,
9954 output: unIndent`
9955 <App>
9956 {options.map((option, index) => (
9957 <option key={index} value={option.key}>
9958 {option.name}
9959 </option>
9960 ))}
9961 </App>
9962 `,
9963 errors: expectedErrors([4, 12, 11, "Punctuator"])
9964 },
9965 {
9966 code: unIndent`
9967 [
9968 <div />,
9969 <div />
9970 ]
9971 `,
9972 output: unIndent`
9973 [
9974 <div />,
9975 <div />
9976 ]
9977 `,
9978 options: [2],
9979 errors: expectedErrors([3, 2, 4, "Punctuator"])
9980 },
9981 {
9982 code: unIndent`
9983 <App>
9984
9985 <Foo />
9986
9987 </App>
9988 `,
9989 output: unIndent`
9990 <App>
9991
9992 \t<Foo />
9993
9994 </App>
9995 `,
9996 options: ["tab"],
9997 errors: expectedErrors([3, "1 tab", "1 space", "Punctuator"])
9998 },
9999 {
10000
10001 /*
10002 * Multiline ternary
10003 * (colon at the end of the first expression)
10004 */
10005 code: unIndent`
10006 foo ?
10007 <Foo /> :
10008 <Bar />
10009 `,
10010 output: unIndent`
10011 foo ?
10012 <Foo /> :
10013 <Bar />
10014 `,
10015 errors: expectedErrors([3, 4, 0, "Punctuator"])
10016 },
10017 {
10018
10019 /*
10020 * Multiline ternary
10021 * (colon on its own line)
10022 */
10023 code: unIndent`
10024 foo ?
10025 <Foo />
10026 :
10027 <Bar />
10028 `,
10029 output: unIndent`
10030 foo ?
10031 <Foo />
10032 :
10033 <Bar />
10034 `,
10035 errors: expectedErrors([[3, 4, 0, "Punctuator"], [4, 4, 0, "Punctuator"]])
10036 },
10037 {
10038
10039 /*
10040 * Multiline ternary
10041 * (colon at the end of the first expression, parenthesized first expression)
10042 */
10043 code: unIndent`
10044 foo ? (
10045 <Foo />
10046 ) :
10047 <Bar />
10048 `,
10049 output: unIndent`
10050 foo ? (
10051 <Foo />
10052 ) :
10053 <Bar />
10054 `,
10055 errors: expectedErrors([4, 4, 0, "Punctuator"])
10056 },
10057 {
10058 code: unIndent`
10059 <App
10060 foo
10061 />
10062 `,
10063 output: unIndent`
10064 <App
10065 foo
10066 />
10067 `,
10068 errors: expectedErrors([2, 4, 2, "JSXIdentifier"])
10069 },
10070 {
10071 code: unIndent`
10072 <App
10073 foo
10074 />
10075 `,
10076 output: unIndent`
10077 <App
10078 foo
10079 />
10080 `,
10081 options: [2],
10082 errors: expectedErrors([3, 0, 2, "Punctuator"])
10083 },
10084 {
10085 code: unIndent`
10086 <App
10087 foo
10088 ></App>
10089 `,
10090 output: unIndent`
10091 <App
10092 foo
10093 ></App>
10094 `,
10095 options: [2],
10096 errors: expectedErrors([3, 0, 2, "Punctuator"])
10097 },
10098 {
10099 code: unIndent`
10100 const Button = function(props) {
10101 return (
10102 <Button
10103 size={size}
10104 onClick={onClick}
10105 >
10106 Button Text
10107 </Button>
10108 );
10109 };
10110 `,
10111 output: unIndent`
10112 const Button = function(props) {
10113 return (
10114 <Button
10115 size={size}
10116 onClick={onClick}
10117 >
10118 Button Text
10119 </Button>
10120 );
10121 };
10122 `,
10123 options: [2],
10124 errors: expectedErrors([6, 4, 36, "Punctuator"])
10125 },
10126 {
10127 code: unIndent`
10128 var x = function() {
10129 return <App
10130 foo
10131 />
10132 }
10133 `,
10134 output: unIndent`
10135 var x = function() {
10136 return <App
10137 foo
10138 />
10139 }
10140 `,
10141 options: [2],
10142 errors: expectedErrors([4, 2, 9, "Punctuator"])
10143 },
10144 {
10145 code: unIndent`
10146 var x = <App
10147 foo
10148 />
10149 `,
10150 output: unIndent`
10151 var x = <App
10152 foo
10153 />
10154 `,
10155 options: [2],
10156 errors: expectedErrors([3, 0, 8, "Punctuator"])
10157 },
10158 {
10159 code: unIndent`
10160 var x = (
10161 <Something
10162 />
10163 )
10164 `,
10165 output: unIndent`
10166 var x = (
10167 <Something
10168 />
10169 )
10170 `,
10171 options: [2],
10172 errors: expectedErrors([3, 2, 4, "Punctuator"])
10173 },
10174 {
10175 code: unIndent`
10176 <App
10177 \tfoo
10178 \t/>
10179 `,
10180 output: unIndent`
10181 <App
10182 \tfoo
10183 />
10184 `,
10185 options: ["tab"],
10186 errors: expectedErrors("tab", [3, 0, 1, "Punctuator"])
10187 },
10188 {
10189 code: unIndent`
10190 <App
10191 \tfoo
10192 \t></App>
10193 `,
10194 output: unIndent`
10195 <App
10196 \tfoo
10197 ></App>
10198 `,
10199 options: ["tab"],
10200 errors: expectedErrors("tab", [3, 0, 1, "Punctuator"])
10201 },
10202 {
10203 code: unIndent`
10204 <
10205 foo
10206 .bar
10207 .baz
10208 >
10209 foo
10210 </
10211 foo.
10212 bar.
10213 baz
10214 >
10215 `,
10216 output: unIndent`
10217 <
10218 foo
10219 .bar
10220 .baz
10221 >
10222 foo
10223 </
10224 foo.
10225 bar.
10226 baz
10227 >
10228 `,
10229 errors: expectedErrors([
10230 [3, 8, 4, "Punctuator"],
10231 [4, 8, 4, "Punctuator"],
10232 [9, 8, 4, "JSXIdentifier"],
10233 [10, 8, 4, "JSXIdentifier"]
10234 ])
10235 },
10236 {
10237 code: unIndent`
10238 <
10239 input
10240 type=
10241 "number"
10242 />
10243 `,
10244 output: unIndent`
10245 <
10246 input
10247 type=
10248 "number"
10249 />
10250 `,
10251 errors: expectedErrors([4, 8, 4, "JSXText"])
10252 },
10253 {
10254 code: unIndent`
10255 <
10256 input
10257 type=
10258 {'number'}
10259 />
10260 `,
10261 output: unIndent`
10262 <
10263 input
10264 type=
10265 {'number'}
10266 />
10267 `,
10268 errors: expectedErrors([4, 8, 4, "Punctuator"])
10269 },
10270 {
10271 code: unIndent`
10272 <
10273 input
10274 type
10275 ="number"
10276 />
10277 `,
10278 output: unIndent`
10279 <
10280 input
10281 type
10282 ="number"
10283 />
10284 `,
10285 errors: expectedErrors([4, 8, 4, "Punctuator"])
10286 },
10287 {
10288 code: unIndent`
10289 foo ? (
10290 bar
10291 ) : (
10292 baz
10293 )
10294 `,
10295 output: unIndent`
10296 foo ? (
10297 bar
10298 ) : (
10299 baz
10300 )
10301 `,
10302 errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
10303 },
10304 {
10305 code: unIndent`
10306 foo ? (
10307 <div>
10308 </div>
10309 ) : (
10310 <span>
10311 </span>
10312 )
10313 `,
10314 output: unIndent`
10315 foo ? (
10316 <div>
10317 </div>
10318 ) : (
10319 <span>
10320 </span>
10321 )
10322 `,
10323 errors: expectedErrors([[5, 4, 8, "Punctuator"], [6, 4, 8, "Punctuator"], [7, 0, 4, "Punctuator"]])
10324 },
10325 {
10326 code: unIndent`
10327 <div>
10328 {
10329 (
10330 1
10331 )
10332 }
10333 </div>
10334 `,
10335 output: unIndent`
10336 <div>
10337 {
10338 (
10339 1
10340 )
10341 }
10342 </div>
10343 `,
10344 errors: expectedErrors([[3, 8, 4, "Punctuator"], [4, 12, 8, "Numeric"], [5, 8, 4, "Punctuator"]])
10345 },
10346 {
10347 code: unIndent`
10348 <div>
10349 {
10350 /* foo */
10351 }
10352 </div>
10353 `,
10354 output: unIndent`
10355 <div>
10356 {
10357 /* foo */
10358 }
10359 </div>
10360 `,
10361 errors: expectedErrors([3, 8, 6, "Block"])
10362 },
10363 {
10364 code: unIndent`
10365 <div
10366 {...props}
10367 />
10368 `,
10369 output: unIndent`
10370 <div
10371 {...props}
10372 />
10373 `,
10374 errors: expectedErrors([2, 4, 0, "Punctuator"])
10375 },
10376 {
10377 code: unIndent`
10378 <div
10379 {
10380 ...props
10381 }
10382 />
10383 `,
10384 output: unIndent`
10385 <div
10386 {
10387 ...props
10388 }
10389 />
10390 `,
10391 errors: expectedErrors([3, 8, 6, "Punctuator"])
10392 },
10393 {
10394 code: unIndent`
10395 <div>foo
10396 <div>bar</div>
10397 </div>
10398 `,
10399 output: unIndent`
10400 <div>foo
10401 <div>bar</div>
10402 </div>
10403 `,
10404 errors: expectedErrors([2, 4, 0, "Punctuator"])
10405 },
10406 {
10407 code: unIndent`
10408 <small>Foo bar&nbsp;
10409 <a>baz qux</a>.
10410 </small>
10411 `,
10412 output: unIndent`
10413 <small>Foo bar&nbsp;
10414 <a>baz qux</a>.
10415 </small>
10416 `,
10417 errors: expectedErrors([2, 4, 0, "Punctuator"])
10418 },
10419
10420 /*
10421 * JSX Fragments
10422 * https://github.com/eslint/eslint/issues/12208
10423 */
10424 {
10425 code: unIndent`
10426 <>
10427 <A />
10428 </>
10429 `,
10430 output: unIndent`
10431 <>
10432 <A />
10433 </>
10434 `,
10435 errors: expectedErrors([2, 4, 0, "Punctuator"])
10436 },
10437 {
10438 code: unIndent`
10439 <
10440 >
10441 <A />
10442 </>
10443 `,
10444 output: unIndent`
10445 <
10446 >
10447 <A />
10448 </>
10449 `,
10450 errors: expectedErrors([2, 0, 4, "Punctuator"])
10451 },
10452 {
10453 code: unIndent`
10454 <>
10455 <A />
10456 <
10457 />
10458 `,
10459 output: unIndent`
10460 <>
10461 <A />
10462 <
10463 />
10464 `,
10465 errors: expectedErrors([4, 0, 4, "Punctuator"])
10466 },
10467 {
10468 code: unIndent`
10469 <>
10470 <A />
10471 </
10472 >
10473 `,
10474 output: unIndent`
10475 <>
10476 <A />
10477 </
10478 >
10479 `,
10480 errors: expectedErrors([4, 0, 4, "Punctuator"])
10481 },
10482 {
10483 code: unIndent`
10484 <
10485 >
10486 <A />
10487 </
10488 >
10489 `,
10490 output: unIndent`
10491 <
10492 >
10493 <A />
10494 </
10495 >
10496 `,
10497 errors: expectedErrors([
10498 [2, 0, 4, "Punctuator"],
10499 [5, 0, 4, "Punctuator"]
10500 ])
10501 },
10502 {
10503 code: unIndent`
10504 <
10505 >
10506 <A />
10507 <
10508 />
10509 `,
10510 output: unIndent`
10511 <
10512 >
10513 <A />
10514 <
10515 />
10516 `,
10517 errors: expectedErrors([
10518 [2, 0, 4, "Punctuator"],
10519 [5, 0, 4, "Punctuator"]
10520 ])
10521 },
10522 {
10523 code: unIndent`
10524 < // Comment
10525 >
10526 <A />
10527 </>
10528 `,
10529 output: unIndent`
10530 < // Comment
10531 >
10532 <A />
10533 </>
10534 `,
10535 errors: expectedErrors([2, 0, 4, "Punctuator"])
10536 },
10537 {
10538 code: unIndent`
10539 <>
10540 <A />
10541 < // Comment
10542 />
10543 `,
10544 output: unIndent`
10545 <>
10546 <A />
10547 < // Comment
10548 />
10549 `,
10550 errors: expectedErrors([4, 0, 4, "Punctuator"])
10551 },
10552 {
10553 code: unIndent`
10554 <>
10555 <A />
10556 </ // Comment
10557 >
10558 `,
10559 output: unIndent`
10560 <>
10561 <A />
10562 </ // Comment
10563 >
10564 `,
10565 errors: expectedErrors([4, 0, 4, "Punctuator"])
10566 },
10567 {
10568 code: unIndent`
10569 < /* Comment */
10570 >
10571 <A />
10572 </>
10573 `,
10574 output: unIndent`
10575 < /* Comment */
10576 >
10577 <A />
10578 </>
10579 `,
10580 errors: expectedErrors([2, 0, 4, "Punctuator"])
10581 },
10582 {
10583 code: unIndent`
10584 <>
10585 <A />
10586 < /* Comment */
10587 />
10588 `,
10589 output: unIndent`
10590 <>
10591 <A />
10592 < /* Comment */
10593 />
10594 `,
10595 errors: expectedErrors([4, 0, 4, "Punctuator"])
10596 },
10597 {
10598 code: unIndent`
10599 <>
10600 <A />
10601 </ /* Comment */
10602 >
10603 `,
10604 output: unIndent`
10605 <>
10606 <A />
10607 </ /* Comment */
10608 >
10609 `,
10610 errors: expectedErrors([4, 0, 4, "Punctuator"])
10611 },
10612
10613 {
10614 code: unIndent`
10615 ({
10616 foo
10617 }: bar) => baz
10618 `,
10619 output: unIndent`
10620 ({
10621 foo
10622 }: bar) => baz
10623 `,
10624 parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-annotation"),
10625 errors: expectedErrors([3, 0, 4, "Punctuator"])
10626 },
10627 {
10628 code: unIndent`
10629 ([
10630 foo
10631 ]: bar) => baz
10632 `,
10633 output: unIndent`
10634 ([
10635 foo
10636 ]: bar) => baz
10637 `,
10638 parser: require.resolve("../../fixtures/parsers/babel-eslint7/array-pattern-with-annotation"),
10639 errors: expectedErrors([3, 0, 4, "Punctuator"])
10640 },
10641 {
10642 code: unIndent`
10643 ({
10644 foo
10645 }: {}) => baz
10646 `,
10647 output: unIndent`
10648 ({
10649 foo
10650 }: {}) => baz
10651 `,
10652 parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-object-annotation"),
10653 errors: expectedErrors([3, 0, 4, "Punctuator"])
10654 },
10655 {
10656 code: unIndent`
10657 class Foo {
10658 foo() {
10659 bar();
10660 }
10661 }
10662 `,
10663 output: unIndent`
10664 class Foo {
10665 foo() {
10666 bar();
10667 }
10668 }
10669 `,
10670 options: [4, { ignoredNodes: ["ClassBody"] }],
10671 errors: expectedErrors([3, 4, 0, "Identifier"])
10672 },
10673 {
10674 code: unIndent`
10675 $(function() {
10676
10677 foo();
10678 bar();
10679
10680 foo(function() {
10681 baz();
10682 });
10683
10684 });
10685 `,
10686 output: unIndent`
10687 $(function() {
10688
10689 foo();
10690 bar();
10691
10692 foo(function() {
10693 baz();
10694 });
10695
10696 });
10697 `,
10698 options: [4, {
10699 ignoredNodes: ["ExpressionStatement > CallExpression[callee.name='$'] > FunctionExpression > BlockStatement"]
10700 }],
10701 errors: expectedErrors([7, 4, 0, "Identifier"])
10702 },
10703 {
10704 code: unIndent`
10705 (function($) {
10706 $(function() {
10707 foo;
10708 });
10709 })()
10710 `,
10711 output: unIndent`
10712 (function($) {
10713 $(function() {
10714 foo;
10715 });
10716 })()
10717 `,
10718 options: [4, {
10719 ignoredNodes: ["ExpressionStatement > CallExpression > FunctionExpression.callee > BlockStatement"]
10720 }],
10721 errors: expectedErrors([3, 4, 0, "Identifier"])
10722 },
10723 {
10724 code: unIndent`
10725 if (foo) {
10726 doSomething();
10727
10728 // Intentionally unindented comment
10729 doSomethingElse();
10730 }
10731 `,
10732 output: unIndent`
10733 if (foo) {
10734 doSomething();
10735
10736 // Intentionally unindented comment
10737 doSomethingElse();
10738 }
10739 `,
10740 options: [4, { ignoreComments: false }],
10741 errors: expectedErrors([4, 4, 0, "Line"])
10742 },
10743 {
10744 code: unIndent`
10745 if (foo) {
10746 doSomething();
10747
10748 /* Intentionally unindented comment */
10749 doSomethingElse();
10750 }
10751 `,
10752 output: unIndent`
10753 if (foo) {
10754 doSomething();
10755
10756 /* Intentionally unindented comment */
10757 doSomethingElse();
10758 }
10759 `,
10760 options: [4, { ignoreComments: false }],
10761 errors: expectedErrors([4, 4, 0, "Block"])
10762 },
10763 {
10764 code: unIndent`
10765 const obj = {
10766 foo () {
10767 return condition ? // comment
10768 1 :
10769 2
10770 }
10771 }
10772 `,
10773 output: unIndent`
10774 const obj = {
10775 foo () {
10776 return condition ? // comment
10777 1 :
10778 2
10779 }
10780 }
10781 `,
10782 errors: expectedErrors([4, 12, 8, "Numeric"])
10783 },
10784
10785 //----------------------------------------------------------------------
10786 // Comment alignment tests
10787 //----------------------------------------------------------------------
10788 {
10789 code: unIndent`
10790 if (foo) {
10791
10792 // Comment cannot align with code immediately above if there is a whitespace gap
10793 doSomething();
10794 }
10795 `,
10796 output: unIndent`
10797 if (foo) {
10798
10799 // Comment cannot align with code immediately above if there is a whitespace gap
10800 doSomething();
10801 }
10802 `,
10803 errors: expectedErrors([3, 4, 0, "Line"])
10804 },
10805 {
10806 code: unIndent`
10807 if (foo) {
10808 foo(
10809 bar);
10810 // Comment cannot align with code immediately below if there is a whitespace gap
10811
10812 }
10813 `,
10814 output: unIndent`
10815 if (foo) {
10816 foo(
10817 bar);
10818 // Comment cannot align with code immediately below if there is a whitespace gap
10819
10820 }
10821 `,
10822 errors: expectedErrors([4, 4, 0, "Line"])
10823 },
10824 {
10825 code: unIndent`
10826 [{
10827 foo
10828 },
10829
10830 // Comment between nodes
10831
10832 {
10833 bar
10834 }];
10835 `,
10836 output: unIndent`
10837 [{
10838 foo
10839 },
10840
10841 // Comment between nodes
10842
10843 {
10844 bar
10845 }];
10846 `,
10847 errors: expectedErrors([5, 0, 4, "Line"])
10848 },
10849 {
10850 code: unIndent`
10851 let foo
10852
10853 // comment
10854
10855 ;(async () => {})()
10856 `,
10857 output: unIndent`
10858 let foo
10859
10860 // comment
10861
10862 ;(async () => {})()
10863 `,
10864 errors: expectedErrors([3, 0, 4, "Line"])
10865 },
10866 {
10867 code: unIndent`
10868 let foo
10869 // comment
10870 ;(async () => {})()
10871 `,
10872 output: unIndent`
10873 let foo
10874 // comment
10875 ;(async () => {})()
10876 `,
10877 errors: expectedErrors([2, 0, 4, "Line"])
10878 },
10879 {
10880 code: unIndent`
10881 let foo
10882
10883 /* comment */;
10884
10885 (async () => {})()
10886 `,
10887 output: unIndent`
10888 let foo
10889
10890 /* comment */;
10891
10892 (async () => {})()
10893 `,
10894 errors: expectedErrors([3, 4, 0, "Block"])
10895 },
10896 {
10897 code: unIndent`
10898 // comment
10899
10900 ;(async () => {})()
10901 `,
10902 output: unIndent`
10903 // comment
10904
10905 ;(async () => {})()
10906 `,
10907 errors: expectedErrors([1, 0, 4, "Line"])
10908 },
10909 {
10910 code: unIndent`
10911 // comment
10912 ;(async () => {})()
10913 `,
10914 output: unIndent`
10915 // comment
10916 ;(async () => {})()
10917 `,
10918 errors: expectedErrors([1, 0, 4, "Line"])
10919 },
10920 {
10921 code: unIndent`
10922 {
10923 let foo
10924
10925 // comment
10926
10927 ;(async () => {})()
10928
10929 }
10930 `,
10931 output: unIndent`
10932 {
10933 let foo
10934
10935 // comment
10936
10937 ;(async () => {})()
10938
10939 }
10940 `,
10941 errors: expectedErrors([4, 4, 8, "Line"])
10942 },
10943 {
10944 code: unIndent`
10945 {
10946 let foo
10947 // comment
10948 ;(async () => {})()
10949
10950 }
10951 `,
10952 output: unIndent`
10953 {
10954 let foo
10955 // comment
10956 ;(async () => {})()
10957
10958 }
10959 `,
10960 errors: expectedErrors([3, 4, 8, "Line"])
10961 },
10962 {
10963 code: unIndent`
10964 {
10965 let foo
10966
10967 /* comment */;
10968
10969 (async () => {})()
10970
10971 }
10972 `,
10973 output: unIndent`
10974 {
10975 let foo
10976
10977 /* comment */;
10978
10979 (async () => {})()
10980
10981 }
10982 `,
10983 errors: expectedErrors([4, 8, 4, "Block"])
10984 },
10985 {
10986 code: unIndent`
10987 const foo = 1
10988 const bar = foo
10989
10990 /* comment */
10991
10992 ;[1, 2, 3].forEach(() => {})
10993 `,
10994 output: unIndent`
10995 const foo = 1
10996 const bar = foo
10997
10998 /* comment */
10999
11000 ;[1, 2, 3].forEach(() => {})
11001 `,
11002 errors: expectedErrors([4, 0, 4, "Block"])
11003 },
11004 {
11005 code: unIndent`
11006 const foo = 1
11007 const bar = foo
11008 /* comment */
11009 ;[1, 2, 3].forEach(() => {})
11010 `,
11011 output: unIndent`
11012 const foo = 1
11013 const bar = foo
11014 /* comment */
11015 ;[1, 2, 3].forEach(() => {})
11016 `,
11017 errors: expectedErrors([3, 0, 4, "Block"])
11018 },
11019 {
11020 code: unIndent`
11021 const foo = 1
11022 const bar = foo
11023
11024 /* comment */;
11025
11026 [1, 2, 3].forEach(() => {})
11027 `,
11028 output: unIndent`
11029 const foo = 1
11030 const bar = foo
11031
11032 /* comment */;
11033
11034 [1, 2, 3].forEach(() => {})
11035 `,
11036 errors: expectedErrors([4, 4, 0, "Block"])
11037 },
11038 {
11039 code: unIndent`
11040 /* comment */
11041
11042 ;[1, 2, 3].forEach(() => {})
11043 `,
11044 output: unIndent`
11045 /* comment */
11046
11047 ;[1, 2, 3].forEach(() => {})
11048 `,
11049 errors: expectedErrors([1, 0, 4, "Block"])
11050 },
11051 {
11052 code: unIndent`
11053 /* comment */
11054 ;[1, 2, 3].forEach(() => {})
11055 `,
11056 output: unIndent`
11057 /* comment */
11058 ;[1, 2, 3].forEach(() => {})
11059 `,
11060 errors: expectedErrors([1, 0, 4, "Block"])
11061 },
11062 {
11063 code: unIndent`
11064 {
11065 const foo = 1
11066 const bar = foo
11067
11068 /* comment */
11069
11070 ;[1, 2, 3].forEach(() => {})
11071
11072 }
11073 `,
11074 output: unIndent`
11075 {
11076 const foo = 1
11077 const bar = foo
11078
11079 /* comment */
11080
11081 ;[1, 2, 3].forEach(() => {})
11082
11083 }
11084 `,
11085 errors: expectedErrors([5, 4, 8, "Block"])
11086 },
11087 {
11088 code: unIndent`
11089 {
11090 const foo = 1
11091 const bar = foo
11092 /* comment */
11093 ;[1, 2, 3].forEach(() => {})
11094
11095 }
11096 `,
11097 output: unIndent`
11098 {
11099 const foo = 1
11100 const bar = foo
11101 /* comment */
11102 ;[1, 2, 3].forEach(() => {})
11103
11104 }
11105 `,
11106 errors: expectedErrors([4, 4, 8, "Block"])
11107 },
11108 {
11109 code: unIndent`
11110 {
11111 const foo = 1
11112 const bar = foo
11113
11114 /* comment */;
11115
11116 [1, 2, 3].forEach(() => {})
11117
11118 }
11119 `,
11120 output: unIndent`
11121 {
11122 const foo = 1
11123 const bar = foo
11124
11125 /* comment */;
11126
11127 [1, 2, 3].forEach(() => {})
11128
11129 }
11130 `,
11131 errors: expectedErrors([5, 8, 4, "Block"])
11132 },
11133
11134 // import expressions
11135 {
11136 code: unIndent`
11137 import(
11138 source
11139 )
11140 `,
11141 output: unIndent`
11142 import(
11143 source
11144 )
11145 `,
11146 parserOptions: { ecmaVersion: 2020 },
11147 errors: expectedErrors([
11148 [2, 4, 0, "Identifier"],
11149 [3, 0, 4, "Punctuator"]
11150 ])
11151 },
11152
11153 // https://github.com/eslint/eslint/issues/12122
11154 {
11155 code: unIndent`
11156 foo(() => {
11157 tag\`
11158 multiline
11159 template\${a} \${b}
11160 literal
11161 \`(() => {
11162 bar();
11163 });
11164 });
11165 `,
11166 output: unIndent`
11167 foo(() => {
11168 tag\`
11169 multiline
11170 template\${a} \${b}
11171 literal
11172 \`(() => {
11173 bar();
11174 });
11175 });
11176 `,
11177 parserOptions: { ecmaVersion: 2015 },
11178 errors: expectedErrors([
11179 [7, 8, 4, "Identifier"]
11180 ])
11181 },
11182 {
11183 code: unIndent`
11184 {
11185 tag\`
11186 multiline
11187 template
11188 literal
11189 \${a} \${b}\`(() => {
11190 bar();
11191 });
11192 }
11193 `,
11194 output: unIndent`
11195 {
11196 tag\`
11197 multiline
11198 template
11199 literal
11200 \${a} \${b}\`(() => {
11201 bar();
11202 });
11203 }
11204 `,
11205 parserOptions: { ecmaVersion: 2015 },
11206 errors: expectedErrors([
11207 [2, 4, 8, "Identifier"],
11208 [7, 8, 12, "Identifier"],
11209 [8, 4, 8, "Punctuator"]
11210 ])
11211 },
11212 {
11213 code: unIndent`
11214 foo(() => {
11215 tagOne\`\${a} \${b}
11216 multiline
11217 template
11218 literal
11219 \`(() => {
11220 tagTwo\`
11221 multiline
11222 template
11223 literal
11224 \`(() => {
11225 bar();
11226 });
11227
11228 baz();
11229 });
11230 });
11231 `,
11232 output: unIndent`
11233 foo(() => {
11234 tagOne\`\${a} \${b}
11235 multiline
11236 template
11237 literal
11238 \`(() => {
11239 tagTwo\`
11240 multiline
11241 template
11242 literal
11243 \`(() => {
11244 bar();
11245 });
11246
11247 baz();
11248 });
11249 });
11250 `,
11251 parserOptions: { ecmaVersion: 2015 },
11252 errors: expectedErrors([
11253 [7, 8, 12, "Identifier"],
11254 [15, 8, 12, "Identifier"],
11255 [16, 4, 0, "Punctuator"]
11256 ])
11257 },
11258 {
11259 code: unIndent`
11260 {
11261 tagOne\`
11262 multiline
11263 template
11264 literal
11265 \${a} \${b}\`(() => {
11266 tagTwo\`
11267 multiline
11268 template
11269 literal
11270 \`(() => {
11271 bar();
11272 });
11273
11274 baz();
11275 });
11276 }
11277 `,
11278 output: unIndent`
11279 {
11280 tagOne\`
11281 multiline
11282 template
11283 literal
11284 \${a} \${b}\`(() => {
11285 tagTwo\`
11286 multiline
11287 template
11288 literal
11289 \`(() => {
11290 bar();
11291 });
11292
11293 baz();
11294 });
11295 }
11296 `,
11297 parserOptions: { ecmaVersion: 2015 },
11298 errors: expectedErrors([
11299 [7, 8, 12, "Identifier"],
11300 [15, 8, 12, "Identifier"],
11301 [16, 4, 0, "Punctuator"]
11302 ])
11303 },
11304 {
11305 code: unIndent`
11306 tagOne\`multiline \${a} \${b}
11307 template
11308 literal
11309 \`(() => {
11310 foo();
11311
11312 tagTwo\`multiline
11313 template
11314 literal
11315 \`({
11316 bar: 1,
11317 baz: 2
11318 });
11319 });
11320 `,
11321 output: unIndent`
11322 tagOne\`multiline \${a} \${b}
11323 template
11324 literal
11325 \`(() => {
11326 foo();
11327
11328 tagTwo\`multiline
11329 template
11330 literal
11331 \`({
11332 bar: 1,
11333 baz: 2
11334 });
11335 });
11336 `,
11337 parserOptions: { ecmaVersion: 2015 },
11338 errors: expectedErrors([
11339 [5, 4, 0, "Identifier"],
11340 [11, 8, 4, "Identifier"]
11341 ])
11342 },
11343 {
11344 code: unIndent`
11345 tagOne\`multiline
11346 template \${a} \${b}
11347 literal\`({
11348 foo: 1,
11349 bar: tagTwo\`multiline
11350 template
11351 literal\`(() => {
11352
11353 baz();
11354 })
11355 });
11356 `,
11357 output: unIndent`
11358 tagOne\`multiline
11359 template \${a} \${b}
11360 literal\`({
11361 foo: 1,
11362 bar: tagTwo\`multiline
11363 template
11364 literal\`(() => {
11365
11366 baz();
11367 })
11368 });
11369 `,
11370 parserOptions: { ecmaVersion: 2015 },
11371 errors: expectedErrors([
11372 [4, 4, 8, "Identifier"],
11373 [5, 4, 0, "Identifier"],
11374 [9, 8, 0, "Identifier"]
11375 ])
11376 },
11377 {
11378 code: unIndent`
11379 foo.bar\` template literal \`(() => {
11380 baz();
11381 })
11382 `,
11383 output: unIndent`
11384 foo.bar\` template literal \`(() => {
11385 baz();
11386 })
11387 `,
11388 parserOptions: { ecmaVersion: 2015 },
11389 errors: expectedErrors([
11390 [2, 4, 8, "Identifier"]
11391 ])
11392 },
11393 {
11394 code: unIndent`
11395 foo.bar.baz\` template literal \`(() => {
11396 baz();
11397 })
11398 `,
11399 output: unIndent`
11400 foo.bar.baz\` template literal \`(() => {
11401 baz();
11402 })
11403 `,
11404 parserOptions: { ecmaVersion: 2015 },
11405 errors: expectedErrors([
11406 [2, 4, 0, "Identifier"],
11407 [3, 0, 4, "Punctuator"]
11408 ])
11409 },
11410 {
11411 code: unIndent`
11412 foo
11413 .bar\` template
11414 literal \`(() => {
11415 baz();
11416 })
11417 `,
11418 output: unIndent`
11419 foo
11420 .bar\` template
11421 literal \`(() => {
11422 baz();
11423 })
11424 `,
11425 parserOptions: { ecmaVersion: 2015 },
11426 errors: expectedErrors([
11427 [5, 4, 0, "Punctuator"]
11428 ])
11429 },
11430 {
11431 code: unIndent`
11432 foo
11433 .test\`
11434 \${a} \${b}
11435 \`(() => {
11436 bar();
11437 })
11438 `,
11439 output: unIndent`
11440 foo
11441 .test\`
11442 \${a} \${b}
11443 \`(() => {
11444 bar();
11445 })
11446 `,
11447 parserOptions: { ecmaVersion: 2015 },
11448 errors: expectedErrors([
11449 [5, 8, 0, "Identifier"]
11450 ])
11451 },
11452 {
11453 code: unIndent`
11454 foo
11455 .test\`
11456 \${a} \${b}
11457 \`(() => {
11458 bar();
11459 })
11460 `,
11461 output: unIndent`
11462 foo
11463 .test\`
11464 \${a} \${b}
11465 \`(() => {
11466 bar();
11467 })
11468 `,
11469 options: [4, { MemberExpression: 0 }],
11470 parserOptions: { ecmaVersion: 2015 },
11471 errors: expectedErrors([
11472 [2, 0, 4, "Punctuator"],
11473 [5, 4, 0, "Identifier"],
11474 [6, 0, 4, "Punctuator"]
11475 ])
11476 },
11477
11478 // Optional chaining
11479 {
11480 code: unIndent`
11481 obj
11482 ?.prop
11483 ?.[key]
11484 ?.
11485 [key]
11486 `,
11487 output: unIndent`
11488 obj
11489 ?.prop
11490 ?.[key]
11491 ?.
11492 [key]
11493 `,
11494 options: [4],
11495 parserOptions: { ecmaVersion: 2020 },
11496 errors: expectedErrors([
11497 [2, 4, 0, "Punctuator"],
11498 [3, 4, 0, "Punctuator"],
11499 [4, 4, 0, "Punctuator"],
11500 [5, 8, 0, "Punctuator"]
11501 ])
11502 },
11503 {
11504 code: unIndent`
11505 (
11506 longSomething
11507 ?.prop
11508 ?.[key]
11509 )
11510 ?.prop
11511 ?.[key]
11512 `,
11513 output: unIndent`
11514 (
11515 longSomething
11516 ?.prop
11517 ?.[key]
11518 )
11519 ?.prop
11520 ?.[key]
11521 `,
11522 options: [4],
11523 parserOptions: { ecmaVersion: 2020 },
11524 errors: expectedErrors([
11525 [6, 4, 0, "Punctuator"],
11526 [7, 4, 0, "Punctuator"]
11527 ])
11528 },
11529 {
11530 code: unIndent`
11531 obj
11532 ?.(arg)
11533 ?.
11534 (arg)
11535 `,
11536 output: unIndent`
11537 obj
11538 ?.(arg)
11539 ?.
11540 (arg)
11541 `,
11542 options: [4],
11543 parserOptions: { ecmaVersion: 2020 },
11544 errors: expectedErrors([
11545 [2, 4, 0, "Punctuator"],
11546 [3, 4, 0, "Punctuator"],
11547 [4, 4, 0, "Punctuator"]
11548 ])
11549 },
11550 {
11551 code: unIndent`
11552 (
11553 longSomething
11554 ?.(arg)
11555 ?.(arg)
11556 )
11557 ?.(arg)
11558 ?.(arg)
11559 `,
11560 output: unIndent`
11561 (
11562 longSomething
11563 ?.(arg)
11564 ?.(arg)
11565 )
11566 ?.(arg)
11567 ?.(arg)
11568 `,
11569 options: [4],
11570 parserOptions: { ecmaVersion: 2020 },
11571 errors: expectedErrors([
11572 [6, 4, 0, "Punctuator"],
11573 [7, 4, 0, "Punctuator"]
11574 ])
11575 },
11576 {
11577 code: unIndent`
11578 const foo = async (arg1,
11579 arg2) =>
11580 {
11581 return arg1 + arg2;
11582 }
11583 `,
11584 output: unIndent`
11585 const foo = async (arg1,
11586 arg2) =>
11587 {
11588 return arg1 + arg2;
11589 }
11590 `,
11591 options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }],
11592 parserOptions: { ecmaVersion: 2020 },
11593 errors: expectedErrors([
11594 [2, 19, 20, "Identifier"]
11595 ])
11596 },
11597 {
11598 code: unIndent`
11599 const a = async
11600 b => {}
11601 `,
11602 output: unIndent`
11603 const a = async
11604 b => {}
11605 `,
11606 options: [2],
11607 errors: expectedErrors([
11608 [2, 0, 1, "Identifier"]
11609 ])
11610 }
11611 ]
11612 });