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