]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/computed-property-spacing.js
bump version to 8.41.0-3
[pve-eslint.git] / eslint / tests / lib / rules / computed-property-spacing.js
1 /**
2 * @fileoverview Disallows or enforces spaces inside computed properties.
3 * @author Jamund Ferguson
4 */
5 "use strict";
6
7 //------------------------------------------------------------------------------
8 // Requirements
9 //------------------------------------------------------------------------------
10
11 const rule = require("../../../lib/rules/computed-property-spacing"),
12 { RuleTester } = require("../../../lib/rule-tester");
13
14 //------------------------------------------------------------------------------
15 // Tests
16 //------------------------------------------------------------------------------
17
18 const ruleTester = new RuleTester();
19
20 ruleTester.run("computed-property-spacing", rule, {
21
22 valid: [
23
24 // default - never
25 "obj[foo]",
26 "obj['foo']",
27 { code: "var x = {[b]: a}", parserOptions: { ecmaVersion: 6 } },
28
29 // always
30 { code: "obj[ foo ]", options: ["always"] },
31 { code: "obj[\nfoo\n]", options: ["always"] },
32 { code: "obj[ 'foo' ]", options: ["always"] },
33 { code: "obj[ 'foo' + 'bar' ]", options: ["always"] },
34 { code: "obj[ obj2[ foo ] ]", options: ["always"] },
35 { code: "obj.map(function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["always"] },
36 { code: "obj[ 'map' ](function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["always"] },
37 { code: "obj[ 'for' + 'Each' ](function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["always"] },
38 { code: "var foo = obj[ 1 ]", options: ["always"] },
39 { code: "var foo = obj[ 'foo' ];", options: ["always"] },
40 { code: "var foo = obj[ [1, 1] ];", options: ["always"] },
41
42 // always - objectLiteralComputedProperties
43 { code: "var x = {[ \"a\" ]: a}", options: ["always"], parserOptions: { ecmaVersion: 6 } },
44 { code: "var y = {[ x ]: a}", options: ["always"], parserOptions: { ecmaVersion: 6 } },
45 { code: "var x = {[ \"a\" ]() {}}", options: ["always"], parserOptions: { ecmaVersion: 6 } },
46 { code: "var y = {[ x ]() {}}", options: ["always"], parserOptions: { ecmaVersion: 6 } },
47
48 // always - unrelated cases
49 { code: "var foo = {};", options: ["always"] },
50 { code: "var foo = [];", options: ["always"] },
51
52 // never
53 { code: "obj[foo]", options: ["never"] },
54 { code: "obj['foo']", options: ["never"] },
55 { code: "obj['foo' + 'bar']", options: ["never"] },
56 { code: "obj['foo'+'bar']", options: ["never"] },
57 { code: "obj[obj2[foo]]", options: ["never"] },
58 { code: "obj.map(function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["never"] },
59 { code: "obj['map'](function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["never"] },
60 { code: "obj['for' + 'Each'](function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["never"] },
61 { code: "obj[\nfoo]", options: ["never"] },
62 { code: "obj[foo\n]", options: ["never"] },
63 { code: "var foo = obj[1]", options: ["never"] },
64 { code: "var foo = obj['foo'];", options: ["never"] },
65 { code: "var foo = obj[[ 1, 1 ]];", options: ["never"] },
66
67 // never - objectLiteralComputedProperties
68 { code: "var x = {[\"a\"]: a}", options: ["never"], parserOptions: { ecmaVersion: 6 } },
69 { code: "var y = {[x]: a}", options: ["never"], parserOptions: { ecmaVersion: 6 } },
70 { code: "var x = {[\"a\"]() {}}", options: ["never"], parserOptions: { ecmaVersion: 6 } },
71 { code: "var y = {[x]() {}}", options: ["never"], parserOptions: { ecmaVersion: 6 } },
72
73 // never - unrelated cases
74 { code: "var foo = {};", options: ["never"] },
75 { code: "var foo = [];", options: ["never"] },
76
77 //------------------------------------------------------------------------------
78 // Classes
79 //------------------------------------------------------------------------------
80
81 // explicitly disabled option
82 {
83 code: "class A { [ a ](){} }",
84 options: ["never", { enforceForClassMembers: false }],
85 parserOptions: { ecmaVersion: 6 }
86 },
87 {
88 code: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }",
89 options: ["never", { enforceForClassMembers: false }],
90 parserOptions: { ecmaVersion: 6 }
91 },
92 {
93 code: "A = class { [a](){} }",
94 options: ["always", { enforceForClassMembers: false }],
95 parserOptions: { ecmaVersion: 6 }
96 },
97 {
98 code: "class A { [a](){} get [b](){} set [b](foo){} static [c](){} static get [d](){} static set [d](bar){} }",
99 options: ["always", { enforceForClassMembers: false }],
100 parserOptions: { ecmaVersion: 6 }
101 },
102 {
103 code: "class A { [ a ]; }",
104 options: ["never", { enforceForClassMembers: false }],
105 parserOptions: { ecmaVersion: 2022 }
106 },
107 {
108 code: "class A { [a]; }",
109 options: ["always", { enforceForClassMembers: false }],
110 parserOptions: { ecmaVersion: 2022 }
111 },
112
113 // valid spacing
114 {
115 code: "A = class { [a](){} }",
116 options: ["never", { enforceForClassMembers: true }],
117 parserOptions: { ecmaVersion: 6 }
118 },
119 {
120 code: "class A { [a] ( ) { } }",
121 options: ["never", { enforceForClassMembers: true }],
122 parserOptions: { ecmaVersion: 6 }
123 },
124 {
125 code: "A = class { [ \n a \n ](){} }",
126 options: ["never", { enforceForClassMembers: true }],
127 parserOptions: { ecmaVersion: 6 }
128 },
129 {
130 code: "class A { [a](){} get [b](){} set [b](foo){} static [c](){} static get [d](){} static set [d](bar){} }",
131 options: ["never", { enforceForClassMembers: true }],
132 parserOptions: { ecmaVersion: 6 }
133 },
134 {
135 code: "class A { [ a ](){} }",
136 options: ["always", { enforceForClassMembers: true }],
137 parserOptions: { ecmaVersion: 6 }
138 },
139 {
140 code: "class A { [ a ](){}[ b ](){} }",
141 options: ["always", { enforceForClassMembers: true }],
142 parserOptions: { ecmaVersion: 6 }
143 },
144 {
145 code: "A = class { [\na\n](){} }",
146 options: ["always", { enforceForClassMembers: true }],
147 parserOptions: { ecmaVersion: 6 }
148 },
149 {
150 code: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }",
151 options: ["always", { enforceForClassMembers: true }],
152 parserOptions: { ecmaVersion: 6 }
153 },
154 {
155 code: "A = class { [a]; static [a]; [a] = 0; static [a] = 0; }",
156 options: ["never", { enforceForClassMembers: true }],
157 parserOptions: { ecmaVersion: 2022 }
158 },
159 {
160 code: "A = class { [ a ]; static [ a ]; [ a ] = 0; static [ a ] = 0; }",
161 options: ["always", { enforceForClassMembers: true }],
162 parserOptions: { ecmaVersion: 2022 }
163 },
164
165 // non-computed
166 {
167 code: "class A { a ( ) { } get b(){} set b ( foo ){} static c (){} static get d() {} static set d( bar ) {} }",
168 options: ["never", { enforceForClassMembers: true }],
169 parserOptions: { ecmaVersion: 6 }
170 },
171 {
172 code: "A = class {a(){}get b(){}set b(foo){}static c(){}static get d(){}static set d(bar){}}",
173 options: ["always", { enforceForClassMembers: true }],
174 parserOptions: { ecmaVersion: 6 }
175 },
176 {
177 code: "A = class { foo; #a; static #b; #c = 0; static #d = 0; }",
178 options: ["never", { enforceForClassMembers: true }],
179 parserOptions: { ecmaVersion: 2022 }
180 },
181 {
182 code: "A = class { foo; #a; static #b; #c = 0; static #d = 0; }",
183 options: ["always", { enforceForClassMembers: true }],
184 parserOptions: { ecmaVersion: 2022 }
185 },
186
187 // handling of parens and comments
188 {
189 code: [
190 "const foo = {",
191 " [ (a) ]: 1",
192 "}"
193 ].join("\n"),
194 options: ["always"],
195 parserOptions: { ecmaVersion: 6 }
196 },
197 {
198 code: [
199 "const foo = {",
200 " [ ( a ) ]: 1",
201 "}"
202 ].join("\n"),
203 options: ["always"],
204 parserOptions: { ecmaVersion: 6 }
205 },
206 {
207 code: [
208 "const foo = {",
209 " [( a )]: 1",
210 "}"
211 ].join("\n"),
212 options: ["never"],
213 parserOptions: { ecmaVersion: 6 }
214 },
215 {
216 code: [
217 "const foo = {",
218 " [ /**/ a /**/ ]: 1",
219 "}"
220 ].join("\n"),
221 options: ["always"],
222 parserOptions: { ecmaVersion: 6 }
223 },
224 {
225 code: [
226 "const foo = {",
227 " [/**/ a /**/]: 1",
228 "}"
229 ].join("\n"),
230 options: ["never"],
231 parserOptions: { ecmaVersion: 6 }
232 },
233 {
234 code: [
235 "const foo = {",
236 " [ a[ b ] ]: 1",
237 "}"
238 ].join("\n"),
239 options: ["always"],
240 parserOptions: { ecmaVersion: 6 }
241 },
242 {
243 code: [
244 "const foo = {",
245 " [a[b]]: 1",
246 "}"
247 ].join("\n"),
248 options: ["never"],
249 parserOptions: { ecmaVersion: 6 }
250 },
251 {
252 code: [
253 "const foo = {",
254 " [ a[ /**/ b ]/**/ ]: 1",
255 "}"
256 ].join("\n"),
257 options: ["always"],
258 parserOptions: { ecmaVersion: 6 }
259 },
260 {
261 code: [
262 "const foo = {",
263 " [/**/a[b /**/] /**/]: 1",
264 "}"
265 ].join("\n"),
266 options: ["never"],
267 parserOptions: { ecmaVersion: 6 }
268 },
269
270 // Destructuring Assignment
271 {
272 code: "const { [a]: someProp } = obj;",
273 options: ["never"],
274 parserOptions: { ecmaVersion: 6 }
275 },
276 {
277 code: "({ [a]: someProp } = obj);",
278 options: ["never"],
279 parserOptions: { ecmaVersion: 6 }
280 },
281 {
282 code: "const { [ a ]: someProp } = obj;",
283 options: ["always"],
284 parserOptions: { ecmaVersion: 6 }
285 },
286 {
287 code: "({ [ a ]: someProp } = obj);",
288 options: ["always"],
289 parserOptions: { ecmaVersion: 6 }
290 }
291
292 ],
293
294 invalid: [
295 {
296 code: "var foo = obj[ 1];",
297 output: "var foo = obj[ 1 ];",
298 options: ["always"],
299 errors: [
300 {
301 messageId: "missingSpaceBefore",
302 data: { tokenValue: "]" },
303 type: "MemberExpression",
304 line: 1,
305 column: 17,
306 endLine: 1,
307 endColumn: 18
308
309 }
310 ]
311 },
312 {
313 code: "var foo = obj[1 ];",
314 output: "var foo = obj[ 1 ];",
315 options: ["always"],
316 errors: [
317 {
318 messageId: "missingSpaceAfter",
319 data: { tokenValue: "[" },
320 type: "MemberExpression",
321 line: 1,
322 column: 14,
323 endLine: 1,
324 endColumn: 15
325 }
326 ]
327 },
328 {
329 code: "var foo = obj[ 1];",
330 output: "var foo = obj[1];",
331 options: ["never"],
332 errors: [
333 {
334 messageId: "unexpectedSpaceAfter",
335 data: { tokenValue: "[" },
336 type: "MemberExpression",
337 line: 1,
338 column: 15,
339 endLine: 1,
340 endColumn: 16
341 }
342 ]
343 },
344 {
345 code: "var foo = obj[1 ];",
346 output: "var foo = obj[1];",
347 options: ["never"],
348 errors: [
349 {
350 messageId: "unexpectedSpaceBefore",
351 data: { tokenValue: "]" },
352 type: "MemberExpression",
353 line: 1,
354 column: 16,
355 endLine: 1,
356 endColumn: 17
357 }
358 ]
359 },
360 {
361 code: "obj[ foo ]",
362 output: "obj[foo]",
363 options: ["never"],
364 errors: [
365 {
366 messageId: "unexpectedSpaceAfter",
367 data: { tokenValue: "[" },
368 type: "MemberExpression",
369 line: 1,
370 column: 5,
371 endLine: 1,
372 endColumn: 6
373 },
374 {
375 messageId: "unexpectedSpaceBefore",
376 data: { tokenValue: "]" },
377 type: "MemberExpression",
378 line: 1,
379 column: 9,
380 endLine: 1,
381 endColumn: 10
382 }
383 ]
384 },
385 {
386 code: "obj[foo ]",
387 output: "obj[foo]",
388 options: ["never"],
389 errors: [
390 {
391 messageId: "unexpectedSpaceBefore",
392 data: { tokenValue: "]" },
393 type: "MemberExpression",
394 line: 1,
395 column: 8,
396 endLine: 1,
397 endColumn: 9
398 }
399 ]
400 },
401 {
402 code: "obj[ foo]",
403 output: "obj[foo]",
404 options: ["never"],
405 errors: [
406 {
407 messageId: "unexpectedSpaceAfter",
408 data: { tokenValue: "[" },
409 type: "MemberExpression",
410 line: 1,
411 column: 5,
412 endLine: 1,
413 endColumn: 6
414 }
415 ]
416 },
417 {
418 code: "var foo = obj[1]",
419 output: "var foo = obj[ 1 ]",
420 options: ["always"],
421 errors: [
422 {
423 messageId: "missingSpaceAfter",
424 data: { tokenValue: "[" },
425 type: "MemberExpression",
426 line: 1,
427 column: 14,
428 endLine: 1,
429 endColumn: 15
430 },
431 {
432 messageId: "missingSpaceBefore",
433 data: { tokenValue: "]" },
434 type: "MemberExpression",
435 line: 1,
436 column: 16,
437 endLine: 1,
438 endColumn: 17
439 }
440 ]
441 },
442
443 // multiple spaces
444 {
445 code: "obj[ foo]",
446 output: "obj[foo]",
447 options: ["never"],
448 errors: [
449 {
450 messageId: "unexpectedSpaceAfter",
451 data: { tokenValue: "[" },
452 type: "MemberExpression",
453 line: 1,
454 column: 5,
455 endLine: 1,
456 endColumn: 9
457 }
458 ]
459 },
460 {
461 code: "obj[ foo ]",
462 output: "obj[foo]",
463 options: ["never"],
464 errors: [
465 {
466 messageId: "unexpectedSpaceAfter",
467 data: { tokenValue: "[" },
468 type: "MemberExpression",
469 line: 1,
470 column: 5,
471 endLine: 1,
472 endColumn: 7
473 },
474 {
475 messageId: "unexpectedSpaceBefore",
476 data: { tokenValue: "]" },
477 type: "MemberExpression",
478 line: 1,
479 column: 10,
480 endLine: 1,
481 endColumn: 12
482 }
483 ]
484 },
485 {
486 code: "obj[ foo ]",
487 output: "obj[foo]",
488 options: ["never"],
489 errors: [
490 {
491 messageId: "unexpectedSpaceAfter",
492 data: { tokenValue: "[" },
493 type: "MemberExpression",
494 line: 1,
495 column: 5,
496 endLine: 1,
497 endColumn: 8
498 },
499 {
500 messageId: "unexpectedSpaceBefore",
501 data: { tokenValue: "]" },
502 type: "MemberExpression",
503 line: 1,
504 column: 11,
505 endLine: 1,
506 endColumn: 12
507 }
508 ]
509 },
510 {
511 code: "obj[ foo + \n bar ]",
512 output: "obj[foo + \n bar]",
513 options: ["never"],
514 errors: [
515 {
516 messageId: "unexpectedSpaceAfter",
517 data: { tokenValue: "[" },
518 type: "MemberExpression",
519 line: 1,
520 column: 5,
521 endLine: 1,
522 endColumn: 6
523 },
524 {
525 messageId: "unexpectedSpaceBefore",
526 data: { tokenValue: "]" },
527 type: "MemberExpression",
528 line: 2,
529 column: 6,
530 endLine: 2,
531 endColumn: 9
532 }
533 ]
534 },
535 {
536 code: "obj[\n foo ]",
537 output: "obj[\n foo]",
538 options: ["never"],
539 errors: [
540 {
541 messageId: "unexpectedSpaceBefore",
542 data: { tokenValue: "]" },
543 type: "MemberExpression",
544 line: 2,
545 column: 5,
546 endLine: 2,
547 endColumn: 7
548 }
549 ]
550 },
551
552 // always - objectLiteralComputedProperties
553 {
554 code: "var x = {[a]: b}",
555 output: "var x = {[ a ]: b}",
556 options: ["always"],
557 parserOptions: { ecmaVersion: 6 },
558 errors: [
559 {
560 messageId: "missingSpaceAfter",
561 data: { tokenValue: "[" },
562 type: "Property",
563 line: 1,
564 column: 10,
565 endLine: 1,
566 endColumn: 11
567 },
568 {
569 messageId: "missingSpaceBefore",
570 data: { tokenValue: "]" },
571 type: "Property",
572 line: 1,
573 column: 12,
574 endLine: 1,
575 endColumn: 13
576 }
577 ]
578 },
579 {
580 code: "var x = {[a ]: b}",
581 output: "var x = {[ a ]: b}",
582 options: ["always"],
583 parserOptions: { ecmaVersion: 6 },
584 errors: [
585 {
586 messageId: "missingSpaceAfter",
587 data: { tokenValue: "[" },
588 type: "Property",
589 line: 1,
590 column: 10,
591 endLine: 1,
592 endColumn: 11
593 }
594 ]
595 },
596 {
597 code: "var x = {[ a]: b}",
598 output: "var x = {[ a ]: b}",
599 options: ["always"],
600 parserOptions: { ecmaVersion: 6 },
601 errors: [
602 {
603 messageId: "missingSpaceBefore",
604 data: { tokenValue: "]" },
605 type: "Property",
606 line: 1,
607 column: 13,
608 endLine: 1,
609 endColumn: 14
610 }
611 ]
612 },
613
614 // never - objectLiteralComputedProperties
615 {
616 code: "var x = {[ a ]: b}",
617 output: "var x = {[a]: b}",
618 options: ["never"],
619 parserOptions: { ecmaVersion: 6 },
620 errors: [
621 {
622 messageId: "unexpectedSpaceAfter",
623 data: { tokenValue: "[" },
624 type: "Property",
625 line: 1,
626 column: 11,
627 endLine: 1,
628 endColumn: 12
629 },
630 {
631 messageId: "unexpectedSpaceBefore",
632 data: { tokenValue: "]" },
633 type: "Property",
634 line: 1,
635 column: 13,
636 endLine: 1,
637 endColumn: 14
638 }
639 ]
640 },
641 {
642 code: "var x = {[a ]: b}",
643 output: "var x = {[a]: b}",
644 options: ["never"],
645 parserOptions: { ecmaVersion: 6 },
646 errors: [
647 {
648 messageId: "unexpectedSpaceBefore",
649 data: { tokenValue: "]" },
650 type: "Property",
651 line: 1,
652 column: 12,
653 endLine: 1,
654 endColumn: 13
655 }
656 ]
657 },
658 {
659 code: "var x = {[ a]: b}",
660 output: "var x = {[a]: b}",
661 options: ["never"],
662 parserOptions: { ecmaVersion: 6 },
663 errors: [
664 {
665 messageId: "unexpectedSpaceAfter",
666 data: { tokenValue: "[" },
667 type: "Property",
668 line: 1,
669 column: 11,
670 endLine: 1,
671 endColumn: 12
672 }
673 ]
674 },
675 {
676 code: "var x = {[ a\n]: b}",
677 output: "var x = {[a\n]: b}",
678 options: ["never"],
679 parserOptions: { ecmaVersion: 6 },
680 errors: [
681 {
682 messageId: "unexpectedSpaceAfter",
683 data: { tokenValue: "[" },
684 type: "Property",
685 line: 1,
686 column: 11,
687 endLine: 1,
688 endColumn: 12
689 }
690 ]
691 },
692
693 // test default settings for classes
694 {
695 code: "class A { [ a ](){} }",
696 output: "class A { [a](){} }",
697 parserOptions: { ecmaVersion: 6 },
698 errors: [
699 {
700 messageId: "unexpectedSpaceAfter",
701 data: { tokenValue: "[" },
702 type: "MethodDefinition",
703 line: 1,
704 column: 12,
705 endLine: 1,
706 endColumn: 13
707 },
708 {
709 messageId: "unexpectedSpaceBefore",
710 data: { tokenValue: "]" },
711 type: "MethodDefinition",
712 line: 1,
713 column: 14,
714 endLine: 1,
715 endColumn: 15
716 }
717 ]
718 },
719 {
720 code: "class A { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }",
721 output: "class A { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }",
722 options: ["never"],
723 parserOptions: { ecmaVersion: 6 },
724 errors: [
725 {
726 messageId: "unexpectedSpaceAfter",
727 data: { tokenValue: "[" },
728 type: "MethodDefinition",
729 line: 1,
730 column: 12,
731 endLine: 1,
732 endColumn: 13
733 },
734 {
735 messageId: "unexpectedSpaceBefore",
736 data: { tokenValue: "]" },
737 type: "MethodDefinition",
738 line: 1,
739 column: 14,
740 endLine: 1,
741 endColumn: 15
742 },
743 {
744 messageId: "unexpectedSpaceAfter",
745 data: { tokenValue: "[" },
746 type: "MethodDefinition",
747 line: 1,
748 column: 26,
749 endLine: 1,
750 endColumn: 27
751 },
752 {
753 messageId: "unexpectedSpaceBefore",
754 data: { tokenValue: "]" },
755 type: "MethodDefinition",
756 line: 1,
757 column: 28,
758 endLine: 1,
759 endColumn: 29
760 },
761 {
762 messageId: "unexpectedSpaceAfter",
763 data: { tokenValue: "[" },
764 type: "MethodDefinition",
765 line: 1,
766 column: 40,
767 endLine: 1,
768 endColumn: 41
769 },
770 {
771 messageId: "unexpectedSpaceBefore",
772 data: { tokenValue: "]" },
773 type: "MethodDefinition",
774 line: 1,
775 column: 42,
776 endLine: 1,
777 endColumn: 43
778 },
779 {
780 messageId: "unexpectedSpaceAfter",
781 data: { tokenValue: "[" },
782 type: "MethodDefinition",
783 line: 1,
784 column: 60,
785 endLine: 1,
786 endColumn: 61
787 },
788 {
789 messageId: "unexpectedSpaceBefore",
790 data: { tokenValue: "]" },
791 type: "MethodDefinition",
792 line: 1,
793 column: 62,
794 endLine: 1,
795 endColumn: 63
796 },
797 {
798 messageId: "unexpectedSpaceAfter",
799 data: { tokenValue: "[" },
800 type: "MethodDefinition",
801 line: 1,
802 column: 81,
803 endLine: 1,
804 endColumn: 82
805 },
806 {
807 messageId: "unexpectedSpaceBefore",
808 data: { tokenValue: "]" },
809 type: "MethodDefinition",
810 line: 1,
811 column: 83,
812 endLine: 1,
813 endColumn: 84
814 },
815 {
816 messageId: "unexpectedSpaceAfter",
817 data: { tokenValue: "[" },
818 type: "MethodDefinition",
819 line: 1,
820 column: 102,
821 endLine: 1,
822 endColumn: 103
823 },
824 {
825 messageId: "unexpectedSpaceBefore",
826 data: { tokenValue: "]" },
827 type: "MethodDefinition",
828 line: 1,
829 column: 104,
830 endLine: 1,
831 endColumn: 105
832 }
833 ]
834 },
835 {
836 code: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }",
837 output: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }",
838 options: ["never", {}],
839 parserOptions: { ecmaVersion: 6 },
840 errors: [
841 {
842 messageId: "unexpectedSpaceAfter",
843 data: { tokenValue: "[" },
844 type: "MethodDefinition",
845 line: 1,
846 column: 14,
847 endLine: 1,
848 endColumn: 15
849 },
850 {
851 messageId: "unexpectedSpaceBefore",
852 data: { tokenValue: "]" },
853 type: "MethodDefinition",
854 line: 1,
855 column: 16,
856 endLine: 1,
857 endColumn: 17
858 },
859 {
860 messageId: "unexpectedSpaceAfter",
861 data: { tokenValue: "[" },
862 type: "MethodDefinition",
863 line: 1,
864 column: 28,
865 endLine: 1,
866 endColumn: 29
867 },
868 {
869 messageId: "unexpectedSpaceBefore",
870 data: { tokenValue: "]" },
871 type: "MethodDefinition",
872 line: 1,
873 column: 30,
874 endLine: 1,
875 endColumn: 31
876 },
877 {
878 messageId: "unexpectedSpaceAfter",
879 data: { tokenValue: "[" },
880 type: "MethodDefinition",
881 line: 1,
882 column: 42,
883 endLine: 1,
884 endColumn: 43
885 },
886 {
887 messageId: "unexpectedSpaceBefore",
888 data: { tokenValue: "]" },
889 type: "MethodDefinition",
890 line: 1,
891 column: 44,
892 endLine: 1,
893 endColumn: 45
894 },
895 {
896 messageId: "unexpectedSpaceAfter",
897 data: { tokenValue: "[" },
898 type: "MethodDefinition",
899 line: 1,
900 column: 62,
901 endLine: 1,
902 endColumn: 63
903 },
904 {
905 messageId: "unexpectedSpaceBefore",
906 data: { tokenValue: "]" },
907 type: "MethodDefinition",
908 line: 1,
909 column: 64,
910 endLine: 1,
911 endColumn: 65
912 },
913 {
914 messageId: "unexpectedSpaceAfter",
915 data: { tokenValue: "[" },
916 type: "MethodDefinition",
917 line: 1,
918 column: 83,
919 endLine: 1,
920 endColumn: 84
921 },
922 {
923 messageId: "unexpectedSpaceBefore",
924 data: { tokenValue: "]" },
925 type: "MethodDefinition",
926 line: 1,
927 column: 85,
928 endLine: 1,
929 endColumn: 86
930 },
931 {
932 messageId: "unexpectedSpaceAfter",
933 data: { tokenValue: "[" },
934 type: "MethodDefinition",
935 line: 1,
936 column: 104,
937 endLine: 1,
938 endColumn: 105
939 },
940 {
941 messageId: "unexpectedSpaceBefore",
942 data: { tokenValue: "]" },
943 type: "MethodDefinition",
944 line: 1,
945 column: 106,
946 endLine: 1,
947 endColumn: 107
948 }
949 ]
950 },
951 {
952 code: "A = class { [a](){} }",
953 output: "A = class { [ a ](){} }",
954 options: ["always"],
955 parserOptions: { ecmaVersion: 6 },
956 errors: [
957 {
958 messageId: "missingSpaceAfter",
959 data: { tokenValue: "[" },
960 type: "MethodDefinition",
961 line: 1,
962 column: 13,
963 endLine: 1,
964 endColumn: 14
965 },
966 {
967 messageId: "missingSpaceBefore",
968 data: { tokenValue: "]" },
969 type: "MethodDefinition",
970 line: 1,
971 column: 15,
972 endLine: 1,
973 endColumn: 16
974 }
975 ]
976 },
977 {
978 code: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }",
979 output: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }",
980 options: ["always"],
981 parserOptions: { ecmaVersion: 6 },
982 errors: [
983 {
984 messageId: "missingSpaceAfter",
985 data: { tokenValue: "[" },
986 type: "MethodDefinition",
987 line: 1,
988 column: 13,
989 endLine: 1,
990 endColumn: 14
991 },
992 {
993 messageId: "missingSpaceBefore",
994 data: { tokenValue: "]" },
995 type: "MethodDefinition",
996 line: 1,
997 column: 15,
998 endLine: 1,
999 endColumn: 16
1000 },
1001 {
1002 messageId: "missingSpaceAfter",
1003 data: { tokenValue: "[" },
1004 type: "MethodDefinition",
1005 line: 1,
1006 column: 25,
1007 endLine: 1,
1008 endColumn: 26
1009 },
1010 {
1011 messageId: "missingSpaceBefore",
1012 data: { tokenValue: "]" },
1013 type: "MethodDefinition",
1014 line: 1,
1015 column: 27,
1016 endLine: 1,
1017 endColumn: 28
1018 },
1019 {
1020 messageId: "missingSpaceAfter",
1021 data: { tokenValue: "[" },
1022 type: "MethodDefinition",
1023 line: 1,
1024 column: 37,
1025 endLine: 1,
1026 endColumn: 38
1027 },
1028 {
1029 messageId: "missingSpaceBefore",
1030 data: { tokenValue: "]" },
1031 type: "MethodDefinition",
1032 line: 1,
1033 column: 39,
1034 endLine: 1,
1035 endColumn: 40
1036 },
1037 {
1038 messageId: "missingSpaceAfter",
1039 data: { tokenValue: "[" },
1040 type: "MethodDefinition",
1041 line: 1,
1042 column: 55,
1043 endLine: 1,
1044 endColumn: 56
1045 },
1046 {
1047 messageId: "missingSpaceBefore",
1048 data: { tokenValue: "]" },
1049 type: "MethodDefinition",
1050 line: 1,
1051 column: 57,
1052 endLine: 1,
1053 endColumn: 58
1054 },
1055 {
1056 messageId: "missingSpaceAfter",
1057 data: { tokenValue: "[" },
1058 type: "MethodDefinition",
1059 line: 1,
1060 column: 74,
1061 endLine: 1,
1062 endColumn: 75
1063 },
1064 {
1065 messageId: "missingSpaceBefore",
1066 data: { tokenValue: "]" },
1067 type: "MethodDefinition",
1068 line: 1,
1069 column: 76,
1070 endLine: 1,
1071 endColumn: 77
1072 },
1073 {
1074 messageId: "missingSpaceAfter",
1075 data: { tokenValue: "[" },
1076 type: "MethodDefinition",
1077 line: 1,
1078 column: 93,
1079 endLine: 1,
1080 endColumn: 94
1081 },
1082 {
1083 messageId: "missingSpaceBefore",
1084 data: { tokenValue: "]" },
1085 type: "MethodDefinition",
1086 line: 1,
1087 column: 95,
1088 endLine: 1,
1089 endColumn: 96
1090 }
1091 ]
1092 },
1093 {
1094 code: "class A { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }",
1095 output: "class A { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }",
1096 options: ["always", {}],
1097 parserOptions: { ecmaVersion: 6 },
1098 errors: [
1099 {
1100 messageId: "missingSpaceAfter",
1101 data: { tokenValue: "[" },
1102 type: "MethodDefinition",
1103 line: 1,
1104 column: 11,
1105 endLine: 1,
1106 endColumn: 12
1107 },
1108 {
1109 messageId: "missingSpaceBefore",
1110 data: { tokenValue: "]" },
1111 type: "MethodDefinition",
1112 line: 1,
1113 column: 13,
1114 endLine: 1,
1115 endColumn: 14
1116 },
1117 {
1118 messageId: "missingSpaceAfter",
1119 data: { tokenValue: "[" },
1120 type: "MethodDefinition",
1121 line: 1,
1122 column: 23,
1123 endLine: 1,
1124 endColumn: 24
1125 },
1126 {
1127 messageId: "missingSpaceBefore",
1128 data: { tokenValue: "]" },
1129 type: "MethodDefinition",
1130 line: 1,
1131 column: 25,
1132 endLine: 1,
1133 endColumn: 26
1134 },
1135 {
1136 messageId: "missingSpaceAfter",
1137 data: { tokenValue: "[" },
1138 type: "MethodDefinition",
1139 line: 1,
1140 column: 35,
1141 endLine: 1,
1142 endColumn: 36
1143 },
1144 {
1145 messageId: "missingSpaceBefore",
1146 data: { tokenValue: "]" },
1147 type: "MethodDefinition",
1148 line: 1,
1149 column: 37,
1150 endLine: 1,
1151 endColumn: 38
1152 },
1153 {
1154 messageId: "missingSpaceAfter",
1155 data: { tokenValue: "[" },
1156 type: "MethodDefinition",
1157 line: 1,
1158 column: 53,
1159 endLine: 1,
1160 endColumn: 54
1161 },
1162 {
1163 messageId: "missingSpaceBefore",
1164 data: { tokenValue: "]" },
1165 type: "MethodDefinition",
1166 line: 1,
1167 column: 55,
1168 endLine: 1,
1169 endColumn: 56
1170 },
1171 {
1172 messageId: "missingSpaceAfter",
1173 data: { tokenValue: "[" },
1174 type: "MethodDefinition",
1175 line: 1,
1176 column: 72,
1177 endLine: 1,
1178 endColumn: 73
1179 },
1180 {
1181 messageId: "missingSpaceBefore",
1182 data: { tokenValue: "]" },
1183 type: "MethodDefinition",
1184 line: 1,
1185 column: 74,
1186 endLine: 1,
1187 endColumn: 75
1188 },
1189 {
1190 messageId: "missingSpaceAfter",
1191 data: { tokenValue: "[" },
1192 type: "MethodDefinition",
1193 line: 1,
1194 column: 91,
1195 endLine: 1,
1196 endColumn: 92
1197 },
1198 {
1199 messageId: "missingSpaceBefore",
1200 data: { tokenValue: "]" },
1201 type: "MethodDefinition",
1202 line: 1,
1203 column: 93,
1204 endLine: 1,
1205 endColumn: 94
1206 }
1207 ]
1208 },
1209
1210 // never - classes
1211 {
1212 code: "class A { [ a](){} }",
1213 output: "class A { [a](){} }",
1214 options: ["never", { enforceForClassMembers: true }],
1215 parserOptions: { ecmaVersion: 6 },
1216 errors: [
1217 {
1218 messageId: "unexpectedSpaceAfter",
1219 data: { tokenValue: "[" },
1220 type: "MethodDefinition",
1221 line: 1,
1222 column: 12,
1223 endLine: 1,
1224 endColumn: 13
1225 }
1226 ]
1227 },
1228 {
1229 code: "A = class { [a](){} b(){} static [c ](){} static [d](){}}",
1230 output: "A = class { [a](){} b(){} static [c](){} static [d](){}}",
1231 options: ["never", { enforceForClassMembers: true }],
1232 parserOptions: { ecmaVersion: 6 },
1233 errors: [
1234 {
1235 messageId: "unexpectedSpaceBefore",
1236 data: { tokenValue: "]" },
1237 type: "MethodDefinition",
1238 line: 1,
1239 column: 36,
1240 endLine: 1,
1241 endColumn: 37
1242 }
1243 ]
1244 },
1245 {
1246 code: "class A { get [a ](){} set [ a](foo){} get b(){} static set b(bar){} static get [ a](){} static set [a ](baz){} }",
1247 output: "class A { get [a](){} set [a](foo){} get b(){} static set b(bar){} static get [a](){} static set [a](baz){} }",
1248 options: ["never", { enforceForClassMembers: true }],
1249 parserOptions: { ecmaVersion: 6 },
1250 errors: [
1251 {
1252 messageId: "unexpectedSpaceBefore",
1253 data: { tokenValue: "]" },
1254 type: "MethodDefinition",
1255 line: 1,
1256 column: 17,
1257 endLine: 1,
1258 endColumn: 18
1259 },
1260 {
1261 messageId: "unexpectedSpaceAfter",
1262 data: { tokenValue: "[" },
1263 type: "MethodDefinition",
1264 line: 1,
1265 column: 29,
1266 endLine: 1,
1267 endColumn: 30
1268 },
1269 {
1270 messageId: "unexpectedSpaceAfter",
1271 data: { tokenValue: "[" },
1272 type: "MethodDefinition",
1273 line: 1,
1274 column: 82,
1275 endLine: 1,
1276 endColumn: 83
1277 },
1278 {
1279 messageId: "unexpectedSpaceBefore",
1280 data: { tokenValue: "]" },
1281 type: "MethodDefinition",
1282 line: 1,
1283 column: 103,
1284 endLine: 1,
1285 endColumn: 104
1286 }
1287 ]
1288 },
1289 {
1290 code: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }",
1291 output: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }",
1292 options: ["never", { enforceForClassMembers: true }],
1293 parserOptions: { ecmaVersion: 6 },
1294 errors: [
1295 {
1296 messageId: "unexpectedSpaceAfter",
1297 data: { tokenValue: "[" },
1298 type: "MethodDefinition",
1299 line: 1,
1300 column: 14,
1301 endLine: 1,
1302 endColumn: 15
1303 },
1304 {
1305 messageId: "unexpectedSpaceBefore",
1306 data: { tokenValue: "]" },
1307 type: "MethodDefinition",
1308 line: 1,
1309 column: 16,
1310 endLine: 1,
1311 endColumn: 17
1312 },
1313 {
1314 messageId: "unexpectedSpaceAfter",
1315 data: { tokenValue: "[" },
1316 type: "MethodDefinition",
1317 line: 1,
1318 column: 28,
1319 endLine: 1,
1320 endColumn: 29
1321 },
1322 {
1323 messageId: "unexpectedSpaceBefore",
1324 data: { tokenValue: "]" },
1325 type: "MethodDefinition",
1326 line: 1,
1327 column: 30,
1328 endLine: 1,
1329 endColumn: 31
1330 },
1331 {
1332 messageId: "unexpectedSpaceAfter",
1333 data: { tokenValue: "[" },
1334 type: "MethodDefinition",
1335 line: 1,
1336 column: 42,
1337 endLine: 1,
1338 endColumn: 43
1339 },
1340 {
1341 messageId: "unexpectedSpaceBefore",
1342 data: { tokenValue: "]" },
1343 type: "MethodDefinition",
1344 line: 1,
1345 column: 44,
1346 endLine: 1,
1347 endColumn: 45
1348 },
1349 {
1350 messageId: "unexpectedSpaceAfter",
1351 data: { tokenValue: "[" },
1352 type: "MethodDefinition",
1353 line: 1,
1354 column: 62,
1355 endLine: 1,
1356 endColumn: 63
1357 },
1358 {
1359 messageId: "unexpectedSpaceBefore",
1360 data: { tokenValue: "]" },
1361 type: "MethodDefinition",
1362 line: 1,
1363 column: 64,
1364 endLine: 1,
1365 endColumn: 65
1366 },
1367 {
1368 messageId: "unexpectedSpaceAfter",
1369 data: { tokenValue: "[" },
1370 type: "MethodDefinition",
1371 line: 1,
1372 column: 83,
1373 endLine: 1,
1374 endColumn: 84
1375 },
1376 {
1377 messageId: "unexpectedSpaceBefore",
1378 data: { tokenValue: "]" },
1379 type: "MethodDefinition",
1380 line: 1,
1381 column: 85,
1382 endLine: 1,
1383 endColumn: 86
1384 },
1385 {
1386 messageId: "unexpectedSpaceAfter",
1387 data: { tokenValue: "[" },
1388 type: "MethodDefinition",
1389 line: 1,
1390 column: 104,
1391 endLine: 1,
1392 endColumn: 105
1393 },
1394 {
1395 messageId: "unexpectedSpaceBefore",
1396 data: { tokenValue: "]" },
1397 type: "MethodDefinition",
1398 line: 1,
1399 column: 106,
1400 endLine: 1,
1401 endColumn: 107
1402 }
1403 ]
1404 },
1405 {
1406 code: "class A { [ a]; [b ]; [ c ]; [ a] = 0; [b ] = 0; [ c ] = 0; }",
1407 output: "class A { [a]; [b]; [c]; [a] = 0; [b] = 0; [c] = 0; }",
1408 options: ["never", { enforceForClassMembers: true }],
1409 parserOptions: { ecmaVersion: 2022 },
1410 errors: [
1411 {
1412 messageId: "unexpectedSpaceAfter",
1413 data: { tokenValue: "[" },
1414 column: 12,
1415 endColumn: 13
1416 },
1417 {
1418 messageId: "unexpectedSpaceBefore",
1419 data: { tokenValue: "]" },
1420 column: 19,
1421 endColumn: 20
1422 },
1423 {
1424 messageId: "unexpectedSpaceAfter",
1425 data: { tokenValue: "[" },
1426 column: 24,
1427 endColumn: 25
1428 },
1429 {
1430 messageId: "unexpectedSpaceBefore",
1431 data: { tokenValue: "]" },
1432 column: 26,
1433 endColumn: 27
1434 },
1435 {
1436 messageId: "unexpectedSpaceAfter",
1437 data: { tokenValue: "[" },
1438 column: 31,
1439 endColumn: 32
1440 },
1441 {
1442 messageId: "unexpectedSpaceBefore",
1443 data: { tokenValue: "]" },
1444 column: 42,
1445 endColumn: 43
1446 },
1447 {
1448 messageId: "unexpectedSpaceAfter",
1449 data: { tokenValue: "[" },
1450 column: 51,
1451 endColumn: 52
1452 },
1453 {
1454 messageId: "unexpectedSpaceBefore",
1455 data: { tokenValue: "]" },
1456 column: 53,
1457 endColumn: 54
1458 }
1459 ]
1460 },
1461
1462 // always - classes
1463 {
1464 code: "class A { [ a](){} }",
1465 output: "class A { [ a ](){} }",
1466 options: ["always", { enforceForClassMembers: true }],
1467 parserOptions: { ecmaVersion: 6 },
1468 errors: [
1469 {
1470 messageId: "missingSpaceBefore",
1471 data: { tokenValue: "]" },
1472 type: "MethodDefinition",
1473 line: 1,
1474 column: 14,
1475 endLine: 1,
1476 endColumn: 15
1477 }
1478 ]
1479 },
1480 {
1481 code: "A = class { [ a ](){} b(){} static [c ](){} static [ d ](){}}",
1482 output: "A = class { [ a ](){} b(){} static [ c ](){} static [ d ](){}}",
1483 options: ["always", { enforceForClassMembers: true }],
1484 parserOptions: { ecmaVersion: 6 },
1485 errors: [
1486 {
1487 messageId: "missingSpaceAfter",
1488 data: { tokenValue: "[" },
1489 type: "MethodDefinition",
1490 line: 1,
1491 column: 36,
1492 endLine: 1,
1493 endColumn: 37
1494 }
1495 ]
1496 },
1497 {
1498 code: "class A { get [a ](){} set [ a](foo){} get b(){} static set b(bar){} static get [ a](){} static set [a ](baz){} }",
1499 output: "class A { get [ a ](){} set [ a ](foo){} get b(){} static set b(bar){} static get [ a ](){} static set [ a ](baz){} }",
1500 options: ["always", { enforceForClassMembers: true }],
1501 parserOptions: { ecmaVersion: 6 },
1502 errors: [
1503 {
1504 messageId: "missingSpaceAfter",
1505 data: { tokenValue: "[" },
1506 type: "MethodDefinition",
1507 line: 1,
1508 column: 15,
1509 endLine: 1,
1510 endColumn: 16
1511 },
1512 {
1513 messageId: "missingSpaceBefore",
1514 data: { tokenValue: "]" },
1515 type: "MethodDefinition",
1516 line: 1,
1517 column: 31,
1518 endLine: 1,
1519 endColumn: 32
1520 },
1521 {
1522 messageId: "missingSpaceBefore",
1523 data: { tokenValue: "]" },
1524 type: "MethodDefinition",
1525 line: 1,
1526 column: 84,
1527 endLine: 1,
1528 endColumn: 85
1529 },
1530 {
1531 messageId: "missingSpaceAfter",
1532 data: { tokenValue: "[" },
1533 type: "MethodDefinition",
1534 line: 1,
1535 column: 101,
1536 endLine: 1,
1537 endColumn: 102
1538 }
1539 ]
1540 },
1541 {
1542 code: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }",
1543 output: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }",
1544 options: ["always", { enforceForClassMembers: true }],
1545 parserOptions: { ecmaVersion: 6 },
1546 errors: [
1547 {
1548 messageId: "missingSpaceAfter",
1549 data: { tokenValue: "[" },
1550 type: "MethodDefinition",
1551 line: 1,
1552 column: 13,
1553 endLine: 1,
1554 endColumn: 14
1555 },
1556 {
1557 messageId: "missingSpaceBefore",
1558 data: { tokenValue: "]" },
1559 type: "MethodDefinition",
1560 line: 1,
1561 column: 15,
1562 endLine: 1,
1563 endColumn: 16
1564 },
1565 {
1566 messageId: "missingSpaceAfter",
1567 data: { tokenValue: "[" },
1568 type: "MethodDefinition",
1569 line: 1,
1570 column: 25,
1571 endLine: 1,
1572 endColumn: 26
1573 },
1574 {
1575 messageId: "missingSpaceBefore",
1576 data: { tokenValue: "]" },
1577 type: "MethodDefinition",
1578 line: 1,
1579 column: 27,
1580 endLine: 1,
1581 endColumn: 28
1582 },
1583 {
1584 messageId: "missingSpaceAfter",
1585 data: { tokenValue: "[" },
1586 type: "MethodDefinition",
1587 line: 1,
1588 column: 37,
1589 endLine: 1,
1590 endColumn: 38
1591 },
1592 {
1593 messageId: "missingSpaceBefore",
1594 data: { tokenValue: "]" },
1595 type: "MethodDefinition",
1596 line: 1,
1597 column: 39,
1598 endLine: 1,
1599 endColumn: 40
1600 },
1601 {
1602 messageId: "missingSpaceAfter",
1603 data: { tokenValue: "[" },
1604 type: "MethodDefinition",
1605 line: 1,
1606 column: 55,
1607 endLine: 1,
1608 endColumn: 56
1609 },
1610 {
1611 messageId: "missingSpaceBefore",
1612 data: { tokenValue: "]" },
1613 type: "MethodDefinition",
1614 line: 1,
1615 column: 57,
1616 endLine: 1,
1617 endColumn: 58
1618 },
1619 {
1620 messageId: "missingSpaceAfter",
1621 data: { tokenValue: "[" },
1622 type: "MethodDefinition",
1623 line: 1,
1624 column: 74,
1625 endLine: 1,
1626 endColumn: 75
1627 },
1628 {
1629 messageId: "missingSpaceBefore",
1630 data: { tokenValue: "]" },
1631 type: "MethodDefinition",
1632 line: 1,
1633 column: 76,
1634 endLine: 1,
1635 endColumn: 77
1636 },
1637 {
1638 messageId: "missingSpaceAfter",
1639 data: { tokenValue: "[" },
1640 type: "MethodDefinition",
1641 line: 1,
1642 column: 93,
1643 endLine: 1,
1644 endColumn: 94
1645 },
1646 {
1647 messageId: "missingSpaceBefore",
1648 data: { tokenValue: "]" },
1649 type: "MethodDefinition",
1650 line: 1,
1651 column: 95,
1652 endLine: 1,
1653 endColumn: 96
1654 }
1655 ]
1656 },
1657 {
1658 code: "class A { [ a]; [b ]; [c]; [ a] = 0; [b ] = 0; [c] = 0; }",
1659 output: "class A { [ a ]; [ b ]; [ c ]; [ a ] = 0; [ b ] = 0; [ c ] = 0; }",
1660 options: ["always", { enforceForClassMembers: true }],
1661 parserOptions: { ecmaVersion: 2022 },
1662 errors: [
1663 {
1664 messageId: "missingSpaceBefore",
1665 column: 14,
1666 endColumn: 15
1667 },
1668 {
1669 messageId: "missingSpaceAfter",
1670 column: 17,
1671 endColumn: 18
1672 },
1673 {
1674 messageId: "missingSpaceAfter",
1675 column: 23,
1676 endColumn: 24
1677 },
1678 {
1679 messageId: "missingSpaceBefore",
1680 column: 25,
1681 endColumn: 26
1682 },
1683 {
1684 messageId: "missingSpaceBefore",
1685 column: 31,
1686 endColumn: 32
1687 },
1688 {
1689 messageId: "missingSpaceAfter",
1690 column: 38,
1691 endColumn: 39
1692 },
1693 {
1694 messageId: "missingSpaceAfter",
1695 column: 48,
1696 endColumn: 49
1697 },
1698 {
1699 messageId: "missingSpaceBefore",
1700 column: 50,
1701 endColumn: 51
1702 }
1703 ]
1704 },
1705
1706 // handling of parens and comments
1707 {
1708 code: [
1709 "const foo = {",
1710 " [(a)]: 1",
1711 "}"
1712 ].join("\n"),
1713 output: [
1714 "const foo = {",
1715 " [ (a) ]: 1",
1716 "}"
1717 ].join("\n"),
1718 options: ["always"],
1719 parserOptions: { ecmaVersion: 6 },
1720 errors: [
1721 {
1722 messageId: "missingSpaceAfter",
1723 data: { tokenValue: "[" },
1724 type: "Property",
1725 line: 2,
1726 column: 3,
1727 endLine: 2,
1728 endColumn: 4
1729 },
1730 {
1731 messageId: "missingSpaceBefore",
1732 data: { tokenValue: "]" },
1733 type: "Property",
1734 line: 2,
1735 column: 7,
1736 endLine: 2,
1737 endColumn: 8
1738 }
1739 ]
1740 },
1741 {
1742 code: [
1743 "const foo = {",
1744 " [( a )]: 1",
1745 "}"
1746 ].join("\n"),
1747 output: [
1748 "const foo = {",
1749 " [ ( a ) ]: 1",
1750 "}"
1751 ].join("\n"),
1752 options: ["always"],
1753 parserOptions: { ecmaVersion: 6 },
1754 errors: [
1755 {
1756 messageId: "missingSpaceAfter",
1757 data: { tokenValue: "[" },
1758 type: "Property",
1759 line: 2,
1760 column: 3,
1761 endLine: 2,
1762 endColumn: 4
1763 },
1764 {
1765 messageId: "missingSpaceBefore",
1766 data: { tokenValue: "]" },
1767 type: "Property",
1768 line: 2,
1769 column: 9,
1770 endLine: 2,
1771 endColumn: 10
1772 }
1773 ]
1774 },
1775 {
1776 code: [
1777 "const foo = {",
1778 " [ ( a ) ]: 1",
1779 "}"
1780 ].join("\n"),
1781 output: [
1782 "const foo = {",
1783 " [( a )]: 1",
1784 "}"
1785 ].join("\n"),
1786 options: ["never"],
1787 parserOptions: { ecmaVersion: 6 },
1788 errors: [
1789 {
1790 messageId: "unexpectedSpaceAfter",
1791 data: { tokenValue: "[" },
1792 type: "Property",
1793 line: 2,
1794 column: 4,
1795 endLine: 2,
1796 endColumn: 5
1797 },
1798 {
1799 messageId: "unexpectedSpaceBefore",
1800 data: { tokenValue: "]" },
1801 type: "Property",
1802 line: 2,
1803 column: 10,
1804 endLine: 2,
1805 endColumn: 11
1806 }
1807 ]
1808 },
1809 {
1810 code: [
1811 "const foo = {",
1812 " [/**/ a /**/]: 1",
1813 "}"
1814 ].join("\n"),
1815 output: [
1816 "const foo = {",
1817 " [ /**/ a /**/ ]: 1",
1818 "}"
1819 ].join("\n"),
1820 options: ["always"],
1821 parserOptions: { ecmaVersion: 6 },
1822 errors: [
1823 {
1824 messageId: "missingSpaceAfter",
1825 data: { tokenValue: "[" },
1826 type: "Property",
1827 line: 2,
1828 column: 3,
1829 endLine: 2,
1830 endColumn: 4
1831 },
1832 {
1833 messageId: "missingSpaceBefore",
1834 data: { tokenValue: "]" },
1835 type: "Property",
1836 line: 2,
1837 column: 15,
1838 endLine: 2,
1839 endColumn: 16
1840 }
1841 ]
1842 },
1843 {
1844 code: [
1845 "const foo = {",
1846 " [ /**/ a /**/ ]: 1",
1847 "}"
1848 ].join("\n"),
1849 output: [
1850 "const foo = {",
1851 " [/**/ a /**/]: 1",
1852 "}"
1853 ].join("\n"),
1854 options: ["never"],
1855 parserOptions: { ecmaVersion: 6 },
1856 errors: [
1857 {
1858 messageId: "unexpectedSpaceAfter",
1859 data: { tokenValue: "[" },
1860 type: "Property",
1861 line: 2,
1862 column: 4,
1863 endLine: 2,
1864 endColumn: 5
1865 },
1866 {
1867 messageId: "unexpectedSpaceBefore",
1868 data: { tokenValue: "]" },
1869 type: "Property",
1870 line: 2,
1871 column: 16,
1872 endLine: 2,
1873 endColumn: 17
1874 }
1875 ]
1876 },
1877 {
1878 code: [
1879 "const foo = {",
1880 " [a[b]]: 1",
1881 "}"
1882 ].join("\n"),
1883 output: [
1884 "const foo = {",
1885 " [ a[ b ] ]: 1",
1886 "}"
1887 ].join("\n"),
1888 options: ["always"],
1889 parserOptions: { ecmaVersion: 6 },
1890 errors: [
1891 {
1892 messageId: "missingSpaceAfter",
1893 data: { tokenValue: "[" },
1894 type: "Property",
1895 line: 2,
1896 column: 3,
1897 endLine: 2,
1898 endColumn: 4
1899 },
1900 {
1901 messageId: "missingSpaceAfter",
1902 data: { tokenValue: "[" },
1903 type: "MemberExpression",
1904 line: 2,
1905 column: 5,
1906 endLine: 2,
1907 endColumn: 6
1908 },
1909 {
1910 messageId: "missingSpaceBefore",
1911 data: { tokenValue: "]" },
1912 type: "MemberExpression",
1913 line: 2,
1914 column: 7,
1915 endLine: 2,
1916 endColumn: 8
1917 },
1918 {
1919 messageId: "missingSpaceBefore",
1920 data: { tokenValue: "]" },
1921 type: "Property",
1922 line: 2,
1923 column: 8,
1924 endLine: 2,
1925 endColumn: 9
1926 }
1927 ]
1928 },
1929 {
1930 code: [
1931 "const foo = {",
1932 " [ a[ b ] ]: 1",
1933 "}"
1934 ].join("\n"),
1935 output: [
1936 "const foo = {",
1937 " [a[b]]: 1",
1938 "}"
1939 ].join("\n"),
1940 options: ["never"],
1941 parserOptions: { ecmaVersion: 6 },
1942 errors: [
1943 {
1944 messageId: "unexpectedSpaceAfter",
1945 data: { tokenValue: "[" },
1946 type: "Property",
1947 line: 2,
1948 column: 4,
1949 endLine: 2,
1950 endColumn: 5
1951 },
1952 {
1953 messageId: "unexpectedSpaceAfter",
1954 data: { tokenValue: "[" },
1955 type: "MemberExpression",
1956 line: 2,
1957 column: 7,
1958 endLine: 2,
1959 endColumn: 8
1960 },
1961 {
1962 messageId: "unexpectedSpaceBefore",
1963 data: { tokenValue: "]" },
1964 type: "MemberExpression",
1965 line: 2,
1966 column: 9,
1967 endLine: 2,
1968 endColumn: 10
1969 },
1970 {
1971 messageId: "unexpectedSpaceBefore",
1972 data: { tokenValue: "]" },
1973 type: "Property",
1974 line: 2,
1975 column: 11,
1976 endLine: 2,
1977 endColumn: 12
1978 }
1979 ]
1980 },
1981 {
1982 code: [
1983 "const foo = {",
1984 " [a[/**/ b ]/**/]: 1",
1985 "}"
1986 ].join("\n"),
1987 output: [
1988 "const foo = {",
1989 " [ a[ /**/ b ]/**/ ]: 1",
1990 "}"
1991 ].join("\n"),
1992 options: ["always"],
1993 parserOptions: { ecmaVersion: 6 },
1994 errors: [
1995 {
1996 messageId: "missingSpaceAfter",
1997 data: { tokenValue: "[" },
1998 type: "Property",
1999 line: 2,
2000 column: 3,
2001 endLine: 2,
2002 endColumn: 4
2003 },
2004 {
2005 messageId: "missingSpaceAfter",
2006 data: { tokenValue: "[" },
2007 type: "MemberExpression",
2008 line: 2,
2009 column: 5,
2010 endLine: 2,
2011 endColumn: 6
2012 },
2013 {
2014 messageId: "missingSpaceBefore",
2015 data: { tokenValue: "]" },
2016 type: "Property",
2017 line: 2,
2018 column: 18,
2019 endLine: 2,
2020 endColumn: 19
2021 }
2022 ]
2023 },
2024 {
2025 code: [
2026 "const foo = {",
2027 " [ /**/a[ b /**/ ] /**/]: 1",
2028 "}"
2029 ].join("\n"),
2030 output: [
2031 "const foo = {",
2032 " [/**/a[b /**/] /**/]: 1",
2033 "}"
2034 ].join("\n"),
2035 options: ["never"],
2036 parserOptions: { ecmaVersion: 6 },
2037 errors: [
2038 {
2039 messageId: "unexpectedSpaceAfter",
2040 data: { tokenValue: "[" },
2041 type: "Property",
2042 line: 2,
2043 column: 4,
2044 endLine: 2,
2045 endColumn: 5
2046 },
2047 {
2048 messageId: "unexpectedSpaceAfter",
2049 data: { tokenValue: "[" },
2050 type: "MemberExpression",
2051 line: 2,
2052 column: 11,
2053 endLine: 2,
2054 endColumn: 12
2055 },
2056 {
2057 messageId: "unexpectedSpaceBefore",
2058 data: { tokenValue: "]" },
2059 type: "MemberExpression",
2060 line: 2,
2061 column: 18,
2062 endLine: 2,
2063 endColumn: 19
2064 }
2065 ]
2066 },
2067
2068 // Optional chaining
2069 {
2070 code: "obj?.[1];",
2071 output: "obj?.[ 1 ];",
2072 options: ["always"],
2073 parserOptions: { ecmaVersion: 2020 },
2074 errors: [
2075 { messageId: "missingSpaceAfter", data: { tokenValue: "[" } },
2076 { messageId: "missingSpaceBefore", data: { tokenValue: "]" } }
2077 ]
2078 },
2079 {
2080 code: "obj?.[ 1 ];",
2081 output: "obj?.[1];",
2082 options: ["never"],
2083 parserOptions: { ecmaVersion: 2020 },
2084 errors: [
2085 { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } },
2086 { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } }
2087 ]
2088 },
2089
2090 // Destructuring Assignment
2091 {
2092 code: "const { [ a]: someProp } = obj;",
2093 output: "const { [a]: someProp } = obj;",
2094 options: ["never"],
2095 parserOptions: { ecmaVersion: 2022 },
2096 errors: [
2097 { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } }
2098 ]
2099 },
2100 {
2101 code: "const { [a ]: someProp } = obj;",
2102 output: "const { [a]: someProp } = obj;",
2103 options: ["never"],
2104 parserOptions: { ecmaVersion: 2022 },
2105 errors: [
2106 { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } }
2107 ]
2108 },
2109 {
2110 code: "const { [ a ]: someProp } = obj;",
2111 output: "const { [a]: someProp } = obj;",
2112 options: ["never"],
2113 parserOptions: { ecmaVersion: 2022 },
2114 errors: [
2115 { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } },
2116 { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } }
2117 ]
2118 },
2119 {
2120 code: "({ [ a ]: someProp } = obj);",
2121 output: "({ [a]: someProp } = obj);",
2122 options: ["never"],
2123 parserOptions: { ecmaVersion: 2022 },
2124 errors: [
2125 { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } },
2126 { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } }
2127 ]
2128 },
2129 {
2130 code: "const { [a]: someProp } = obj;",
2131 output: "const { [ a ]: someProp } = obj;",
2132 options: ["always"],
2133 parserOptions: { ecmaVersion: 2022 },
2134 errors: [
2135 { messageId: "missingSpaceAfter", data: { tokenValue: "[" } },
2136 { messageId: "missingSpaceBefore", data: { tokenValue: "]" } }
2137 ]
2138 },
2139 {
2140 code: "({ [a]: someProp } = obj);",
2141 output: "({ [ a ]: someProp } = obj);",
2142 options: ["always"],
2143 parserOptions: { ecmaVersion: 2022 },
2144 errors: [
2145 { messageId: "missingSpaceAfter", data: { tokenValue: "[" } },
2146 { messageId: "missingSpaceBefore", data: { tokenValue: "]" } }
2147 ]
2148 }
2149 ]
2150 });