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