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