UNPKG

32.1 kBJavaScriptView Raw
1/* eslint-disable */
2
3/**
4 * @fileoverview Disallows or enforces spaces inside of object literals.
5 * @author Jamund Ferguson
6 * @copyright 2014 Vignesh Anand. All rights reserved.
7 * @copyright 2015 Jamund Ferguson. All rights reserved.
8 * @copyright 2015 Mathieu M-Gosselin. All rights reserved.
9 */
10
11var rule = require('../../rules/object-curly-spacing'),
12 RuleTester = require('../RuleTester');
13
14var ruleTester = new RuleTester();
15ruleTester.run('babel/object-curly-spacing', rule, {
16
17 valid: [
18
19 // always - object literals
20 { code: "var obj = { foo: bar, baz: qux };", options: ["always"] },
21 { code: "var obj = { foo: { bar: quxx }, baz: qux };", options: ["always"] },
22 { code: "var obj = {\nfoo: bar,\nbaz: qux\n};", options: ["always"] },
23
24 // always - destructuring
25 { code: "var { x } = y", options: ["always"], ecmaFeatures: { destructuring: true } },
26 { code: "var { x, y } = y", options: ["always"], ecmaFeatures: { destructuring: true } },
27 { code: "var { x,y } = y", options: ["always"], ecmaFeatures: { destructuring: true } },
28 { code: "var {\nx,y } = y", options: ["always"], ecmaFeatures: { destructuring: true } },
29 { code: "var {\nx,y\n} = z", options: ["always"], ecmaFeatures: { destructuring: true } },
30 { code: "var { x = 10, y } = y", options: ["always"], ecmaFeatures: { destructuring: true } },
31 { code: "var { x: { z }, y } = y", options: ["always"], ecmaFeatures: { destructuring: true } },
32 { code: "var {\ny,\n} = x", options: ["always"], ecmaFeatures: { destructuring: true } },
33 { code: "var { y, } = x", options: ["always"], ecmaFeatures: { destructuring: true } },
34 { code: "var { y: x } = x", options: ["always"], ecmaFeatures: { destructuring: true } },
35
36 // always - import / export
37 { code: "import door from 'room'", options: ["always"], ecmaFeatures: { modules: true } },
38 { code: "import * as door from 'room'", options: ["always"], ecmaFeatures: { modules: true } },
39 { code: "import { door } from 'room'", options: ["always"], ecmaFeatures: { modules: true } },
40 { code: "import {\ndoor } from 'room'", options: ["always"], ecmaFeatures: { modules: true } },
41 { code: "export { door } from 'room'", options: ["always"], ecmaFeatures: { modules: true } },
42 { code: "import { house, mouse } from 'caravan'", options: ["always"], ecmaFeatures: { modules: true } },
43 { code: "import {\nhouse,\nmouse\n} from 'caravan'", options: ["always"], ecmaFeatures: { modules: true } },
44 { code: "import {\nhouse,\nmouse,\n} from 'caravan'", options: ["always"], ecmaFeatures: { modules: true } },
45 { code: "import house, { mouse } from 'caravan'", options: ["always"], ecmaFeatures: { modules: true } },
46 { code: "import door, { house, mouse } from 'caravan'", options: ["always"], ecmaFeatures: { modules: true } },
47 { code: "export { door }", options: ["always"], ecmaFeatures: { modules: true } },
48 { code: "export {\ndoor,\nhouse\n}", options: ["always"], ecmaFeatures: { modules: true } },
49 { code: "export {\ndoor,\nhouse,\n}", options: ["always"], ecmaFeatures: { modules: true } },
50 { code: "import 'room'", options: ["always"], ecmaFeatures: { modules: true } },
51 { code: "import { bar as x } from 'foo';", options: ["always"], ecmaFeatures: { modules: true } },
52 { code: "import { x, } from 'foo';", options: ["always"], ecmaFeatures: { modules: true } },
53 { code: "import {\nx,\n} from 'foo';", options: ["always"], ecmaFeatures: { modules: true } },
54 { code: "export { x, } from 'foo';", options: ["always"], ecmaFeatures: { modules: true } },
55 { code: "export {\nx,\n} from 'foo';", options: ["always"], ecmaFeatures: { modules: true } },
56
57 // always - empty object
58 { code: "var foo = {};", options: ["always"] },
59
60 // always - objectsInObjects
61 { code: "var obj = { 'foo': { 'bar': 1, 'baz': 2 }};", options: ["always", {"objectsInObjects": false}] },
62
63 // always - arraysInObjects
64 { code: "var obj = { 'foo': [ 1, 2 ]};", options: ["always", {"arraysInObjects": false}] },
65
66 // always - arraysInObjects, objectsInObjects
67 { code: "var obj = { 'qux': [ 1, 2 ], 'foo': { 'bar': 1, 'baz': 2 }};", options: ["always", {"arraysInObjects": false, "objectsInObjects": false}] },
68
69 // always - arraysInObjects, objectsInObjects (reverse)
70 { code: "var obj = { 'foo': { 'bar': 1, 'baz': 2 }, 'qux': [ 1, 2 ]};", options: ["always", {"arraysInObjects": false, "objectsInObjects": false}] },
71
72 // never
73 { code: "var obj = {foo: bar,\nbaz: qux\n};", options: ["never"] },
74 { code: "var obj = {\nfoo: bar,\nbaz: qux};", options: ["never"] },
75
76 // never - object literals
77 { code: "var obj = {foo: bar, baz: qux};", options: ["never"] },
78 { code: "var obj = {foo: {bar: quxx}, baz: qux};", options: ["never"] },
79 { code: "var obj = {foo: {\nbar: quxx}, baz: qux\n};", options: ["never"] },
80 { code: "var obj = {foo: {\nbar: quxx\n}, baz: qux};", options: ["never"] },
81 { code: "var obj = {\nfoo: bar,\nbaz: qux\n};", options: ["never"] },
82
83 // never - destructuring
84 { code: "var {x} = y", options: ["never"], ecmaFeatures: { destructuring: true } },
85 { code: "var {x, y} = y", options: ["never"], ecmaFeatures: { destructuring: true } },
86 { code: "var {x,y} = y", options: ["never"], ecmaFeatures: { destructuring: true } },
87 { code: "var {\nx,y\n} = y", options: ["never"], ecmaFeatures: { destructuring: true } },
88 { code: "var {x = 10} = y", options: ["never"], ecmaFeatures: { destructuring: true } },
89 { code: "var {x = 10, y} = y", options: ["never"], ecmaFeatures: { destructuring: true } },
90 { code: "var {x: {z}, y} = y", options: ["never"], ecmaFeatures: { destructuring: true } },
91 { code: "var {\nx: {z\n}, y} = y", options: ["never"], ecmaFeatures: { destructuring: true } },
92 { code: "var {\ny,\n} = x", options: ["never"], ecmaFeatures: { destructuring: true } },
93 { code: "var {y,} = x", options: ["never"], ecmaFeatures: { destructuring: true } },
94 { code: "var {y:x} = x", options: ["never"], ecmaFeatures: { destructuring: true } },
95
96 // never - import / export
97 { code: "import door from 'room'", options: ["never"], ecmaFeatures: { modules: true } },
98 { code: "import * as door from 'room'", options: ["never"], ecmaFeatures: { modules: true } },
99 { code: "import {door} from 'room'", options: ["never"], ecmaFeatures: { modules: true } },
100 { code: "export {door} from 'room'", options: ["never"], ecmaFeatures: { modules: true } },
101 { code: "import {\ndoor} from 'room'", options: ["never"], ecmaFeatures: { modules: true } },
102 { code: "export {\ndoor\n} from 'room'", options: ["never"], ecmaFeatures: { modules: true } },
103 { code: "import {house,mouse} from 'caravan'", options: ["never"], ecmaFeatures: { modules: true } },
104 { code: "import {house, mouse} from 'caravan'", options: ["never"], ecmaFeatures: { modules: true } },
105 { code: "import {\nhouse,\nmouse} from 'caravan'", options: ["never"], ecmaFeatures: { modules: true } },
106 { code: "import {\nhouse,\nmouse,\n} from 'caravan'", options: ["never"], ecmaFeatures: { modules: true } },
107 { code: "export {door}", options: ["never"], ecmaFeatures: { modules: true } },
108 { code: "export {\ndoor,\nmouse\n}", options: ["never"], ecmaFeatures: { modules: true } },
109 { code: "export {\ndoor,\nmouse,\n}", options: ["never"], ecmaFeatures: { modules: true } },
110 { code: "import 'room'", options: ["never"], ecmaFeatures: { modules: true } },
111 { code: "import x, {bar} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } },
112 { code: "import x, {bar, baz} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } },
113 { code: "import {bar as y} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } },
114 { code: "import {x,} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } },
115 { code: "import {\nx,\n} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } },
116 { code: "export {x,} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } },
117 { code: "export {\nx,\n} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } },
118
119
120 // never - empty object
121 { code: "var foo = {};", options: ["never"] },
122
123 // never - objectsInObjects
124 { code: "var obj = {'foo': {'bar': 1, 'baz': 2} };", options: ["never", {"objectsInObjects": true}]},
125
126 // https://github.com/eslint/eslint/issues/3658
127 // Empty cases.
128 { code: "var {} = foo;", ecmaFeatures: { destructuring: true }},
129 { code: "var [] = foo;", ecmaFeatures: { destructuring: true }},
130 { code: "var {a: {}} = foo;", ecmaFeatures: { destructuring: true }},
131 { code: "var {a: []} = foo;", ecmaFeatures: { destructuring: true }},
132 { code: "import {} from 'foo';", ecmaFeatures: { modules: true }},
133 { code: "export {} from 'foo';", ecmaFeatures: { modules: true }},
134 { code: "export {};", ecmaFeatures: { modules: true }},
135 { code: "var {} = foo;", options: ["never"], ecmaFeatures: { destructuring: true }},
136 { code: "var [] = foo;", options: ["never"], ecmaFeatures: { destructuring: true }},
137 { code: "var {a: {}} = foo;", options: ["never"], ecmaFeatures: { destructuring: true }},
138 { code: "var {a: []} = foo;", options: ["never"], ecmaFeatures: { destructuring: true }},
139 { code: "import {} from 'foo';", options: ["never"], ecmaFeatures: { modules: true }},
140 { code: "export {} from 'foo';", options: ["never"], ecmaFeatures: { modules: true }},
141 { code: "export {};", options: ["never"], ecmaFeatures: { modules: true }},
142
143 // Babel test cases.
144 { code: "export * as x from \"mod\";", parser: "babel-eslint", ecmaFeatures: { modules: true } },
145 { code: "export x from \"mod\";", parser: "babel-eslint", ecmaFeatures: { modules: true } },
146
147 // always - destructuring typed object param
148 { code: "function fn({ a,b }:Object){}", options: ["always"], parser: "babel-eslint", ecmaFeatures: { destructuring: true } },
149
150 // never - destructuring typed object param
151 { code: "function fn({a,b}: Object){}", options: ["never"], parser: "babel-eslint", ecmaFeatures: { destructuring: true } },
152 ],
153
154 invalid: [
155 {
156 code: "import {bar} from 'foo.js';",
157 output: "import { bar } from 'foo.js';",
158 options: ["always"],
159 ecmaFeatures: {
160 modules: true
161 },
162 errors: [
163 {
164 message: "A space is required after '{'.",
165 type: "ImportDeclaration",
166 line: 1,
167 column: 8
168 },
169 {
170 message: "A space is required before '}'.",
171 type: "ImportDeclaration",
172 line: 1,
173 column: 12
174 }
175 ]
176 },
177 {
178 code: "import { bar as y} from 'foo.js';",
179 output: "import { bar as y } from 'foo.js';",
180 options: ["always"],
181 ecmaFeatures: {
182 modules: true
183 },
184 errors: [
185 {
186 message: "A space is required before '}'.",
187 type: "ImportDeclaration",
188 line: 1,
189 column: 18
190 }
191 ]
192 },
193 {
194 code: "import {bar as y} from 'foo.js';",
195 output: "import { bar as y } from 'foo.js';",
196 options: ["always"],
197 ecmaFeatures: {
198 modules: true
199 },
200 errors: [
201 {
202 message: "A space is required after '{'.",
203 type: "ImportDeclaration",
204 line: 1,
205 column: 8
206 },
207 {
208 message: "A space is required before '}'.",
209 type: "ImportDeclaration",
210 line: 1,
211 column: 17
212 }
213 ]
214 },
215 {
216 code: "import { bar} from 'foo.js';",
217 output: "import { bar } from 'foo.js';",
218 options: ["always"],
219 ecmaFeatures: {
220 modules: true
221 },
222 errors: [
223 {
224 message: "A space is required before '}'.",
225 type: "ImportDeclaration",
226 line: 1,
227 column: 13
228 }
229 ]
230 },
231 {
232 code: "import x, { bar} from 'foo';",
233 output: "import x, { bar } from 'foo';",
234 options: ["always"],
235 ecmaFeatures: {
236 modules: true
237 },
238 errors: [
239 {
240 message: "A space is required before '}'.",
241 type: "ImportDeclaration",
242 line: 1,
243 column: 16
244 }
245
246 ]
247 },
248 {
249 code: "import x, { bar, baz} from 'foo';",
250 output: "import x, { bar, baz } from 'foo';",
251 options: ["always"],
252 ecmaFeatures: {
253 modules: true
254 },
255 errors: [
256 {
257 message: "A space is required before '}'.",
258 type: "ImportDeclaration",
259 line: 1,
260 column: 21
261 }
262
263 ]
264 },
265 {
266 code: "import x, {bar} from 'foo';",
267 output: "import x, { bar } from 'foo';",
268 options: ["always"],
269 ecmaFeatures: {
270 modules: true
271 },
272 errors: [
273 {
274 message: "A space is required after '{'.",
275 type: "ImportDeclaration",
276 line: 1,
277 column: 11
278 },
279 {
280 message: "A space is required before '}'.",
281 type: "ImportDeclaration",
282 line: 1,
283 column: 15
284 }
285
286 ]
287 },
288 {
289 code: "import x, {bar, baz} from 'foo';",
290 output: "import x, { bar, baz } from 'foo';",
291 options: ["always"],
292 ecmaFeatures: {
293 modules: true
294 },
295 errors: [
296 {
297 message: "A space is required after '{'.",
298 type: "ImportDeclaration",
299 line: 1,
300 column: 11
301 },
302 {
303 message: "A space is required before '}'.",
304 type: "ImportDeclaration",
305 line: 1,
306 column: 20
307 }
308 ]
309 },
310 {
311 code: "import {bar,} from 'foo';",
312 output: "import { bar, } from 'foo';",
313 options: ["always"],
314 ecmaFeatures: {
315 modules: true
316 },
317 errors: [
318 {
319 message: "A space is required after '{'.",
320 type: "ImportDeclaration",
321 line: 1,
322 column: 8
323 },
324 {
325 message: "A space is required before '}'.",
326 type: "ImportDeclaration",
327 line: 1,
328 column: 13
329 }
330
331 ]
332 },
333 {
334 code: "import { bar, } from 'foo';",
335 output: "import {bar,} from 'foo';",
336 options: ["never"],
337 ecmaFeatures: {
338 modules: true
339 },
340 errors: [
341 {
342 message: "There should be no space after '{'.",
343 type: "ImportDeclaration",
344 line: 1,
345 column: 8
346 },
347 {
348 message: "There should be no space before '}'.",
349 type: "ImportDeclaration",
350 line: 1,
351 column: 15
352 }
353 ]
354 },
355 {
356 code: "export {bar};",
357 output: "export { bar };",
358 options: ["always"],
359 ecmaFeatures: {
360 modules: true
361 },
362 errors: [
363 {
364 message: "A space is required after '{'.",
365 type: "ExportNamedDeclaration",
366 line: 1,
367 column: 8
368 },
369 {
370 message: "A space is required before '}'.",
371 type: "ExportNamedDeclaration",
372 line: 1,
373 column: 12
374 }
375 ]
376 },
377
378 // always - arraysInObjects
379 {
380 code: "var obj = { 'foo': [ 1, 2 ] };",
381 output: "var obj = { 'foo': [ 1, 2 ]};",
382 options: ["always", {"arraysInObjects": false}],
383 errors: [
384 {
385 message: "There should be no space before '}'.",
386 type: "ObjectExpression"
387 }
388 ]
389 },
390 {
391 code: "var obj = { 'foo': [ 1, 2 ] , 'bar': [ 'baz', 'qux' ] };",
392 output: "var obj = { 'foo': [ 1, 2 ] , 'bar': [ 'baz', 'qux' ]};",
393 options: ["always", {"arraysInObjects": false}],
394 errors: [
395 {
396 message: "There should be no space before '}'.",
397 type: "ObjectExpression"
398 }
399 ]
400 },
401
402 // always-objectsInObjects
403 {
404 code: "var obj = { 'foo': { 'bar': 1, 'baz': 2 } };",
405 output: "var obj = { 'foo': { 'bar': 1, 'baz': 2 }};",
406 options: ["always", {"objectsInObjects": false}],
407 errors: [
408 {
409 message: "There should be no space before '}'.",
410 type: "ObjectExpression",
411 line: 1,
412 column: 43
413 }
414 ]
415 },
416 {
417 code: "var obj = { 'foo': [ 1, 2 ] , 'bar': { 'baz': 1, 'qux': 2 } };",
418 output: "var obj = { 'foo': [ 1, 2 ] , 'bar': { 'baz': 1, 'qux': 2 }};",
419 options: ["always", {"objectsInObjects": false}],
420 errors: [
421 {
422 message: "There should be no space before '}'.",
423 type: "ObjectExpression",
424 line: 1,
425 column: 61
426 }
427 ]
428 },
429
430 // always-destructuring trailing comma
431 {
432 code: "var { a,} = x;",
433 output: "var { a, } = x;",
434 options: ["always"],
435 ecmaFeatures: { destructuring: true },
436 errors: [
437 {
438 message: "A space is required before '}'.",
439 type: "ObjectPattern",
440 line: 1,
441 column: 9
442 }
443 ]
444 },
445 {
446 code: "var {a, } = x;",
447 output: "var {a,} = x;",
448 options: ["never"],
449 ecmaFeatures: { destructuring: true },
450 errors: [
451 {
452 message: "There should be no space before '}'.",
453 type: "ObjectPattern",
454 line: 1,
455 column: 9
456 }
457 ]
458 },
459 {
460 code: "var {a:b } = x;",
461 output: "var {a:b} = x;",
462 options: ["never"],
463 ecmaFeatures: { destructuring: true },
464 errors: [
465 {
466 message: "There should be no space before '}'.",
467 type: "ObjectPattern",
468 line: 1,
469 column: 10
470 }
471 ]
472 },
473 {
474 code: "var { a:b } = x;",
475 output: "var {a:b} = x;",
476 options: ["never"],
477 ecmaFeatures: { destructuring: true },
478 errors: [
479 {
480 message: "There should be no space after '{'.",
481 type: "ObjectPattern",
482 line: 1,
483 column: 5
484 },
485 {
486 message: "There should be no space before '}'.",
487 type: "ObjectPattern",
488 line: 1,
489 column: 11
490 }
491 ]
492 },
493
494 // never-objectsInObjects
495 {
496 code: "var obj = {'foo': {'bar': 1, 'baz': 2}};",
497 output: "var obj = {'foo': {'bar': 1, 'baz': 2} };",
498 options: ["never", {"objectsInObjects": true}],
499 errors: [
500 {
501 message: "A space is required before '}'.",
502 type: "ObjectExpression",
503 line: 1,
504 column: 39
505 }
506 ]
507 },
508 {
509 code: "var obj = {'foo': [1, 2] , 'bar': {'baz': 1, 'qux': 2}};",
510 output: "var obj = {'foo': [1, 2] , 'bar': {'baz': 1, 'qux': 2} };",
511 options: ["never", {"objectsInObjects": true}],
512 errors: [
513 {
514 message: "A space is required before '}'.",
515 type: "ObjectExpression",
516 line: 1,
517 column: 55
518 }
519 ]
520 },
521
522 // always & never
523 {
524 code: "var obj = {foo: bar, baz: qux};",
525 output: "var obj = { foo: bar, baz: qux };",
526 options: ["always"],
527 errors: [
528 {
529 message: "A space is required after '{'.",
530 type: "ObjectExpression",
531 line: 1,
532 column: 11
533 },
534 {
535 message: "A space is required before '}'.",
536 type: "ObjectExpression",
537 line: 1,
538 column: 30
539 }
540 ]
541 },
542 {
543 code: "var obj = {foo: bar, baz: qux };",
544 output: "var obj = { foo: bar, baz: qux };",
545 options: ["always"],
546 errors: [
547 {
548 message: "A space is required after '{'.",
549 type: "ObjectExpression",
550 line: 1,
551 column: 11
552 }
553 ]
554 },
555 {
556 code: "var obj = { foo: bar, baz: qux};",
557 output: "var obj = { foo: bar, baz: qux };",
558 options: ["always"],
559 errors: [
560 {
561 message: "A space is required before '}'.",
562 type: "ObjectExpression",
563 line: 1,
564 column: 31
565 }
566 ]
567 },
568 {
569 code: "var obj = { foo: bar, baz: qux };",
570 output: "var obj = {foo: bar, baz: qux};",
571 options: ["never"],
572 errors: [
573 {
574 message: "There should be no space after '{'.",
575 type: "ObjectExpression",
576 line: 1,
577 column: 11
578 },
579 {
580 message: "There should be no space before '}'.",
581 type: "ObjectExpression",
582 line: 1,
583 column: 32
584 }
585 ]
586 },
587 {
588 code: "var obj = {foo: bar, baz: qux };",
589 output: "var obj = {foo: bar, baz: qux};",
590 options: ["never"],
591 errors: [
592 {
593 message: "There should be no space before '}'.",
594 type: "ObjectExpression",
595 line: 1,
596 column: 31
597 }
598 ]
599 },
600 {
601 code: "var obj = { foo: bar, baz: qux};",
602 output: "var obj = {foo: bar, baz: qux};",
603 options: ["never"],
604 errors: [
605 {
606 message: "There should be no space after '{'.",
607 type: "ObjectExpression",
608 line: 1,
609 column: 11
610 }
611 ]
612 },
613 {
614 code: "var obj = { foo: { bar: quxx}, baz: qux};",
615 output: "var obj = {foo: {bar: quxx}, baz: qux};",
616 options: ["never"],
617 errors: [
618 {
619 message: "There should be no space after '{'.",
620 type: "ObjectExpression",
621 line: 1,
622 column: 11
623 },
624 {
625 message: "There should be no space after '{'.",
626 type: "ObjectExpression",
627 line: 1,
628 column: 18
629 }
630 ]
631 },
632 {
633 code: "var obj = {foo: {bar: quxx }, baz: qux };",
634 output: "var obj = {foo: {bar: quxx}, baz: qux};",
635 options: ["never"],
636 errors: [
637 {
638 message: "There should be no space before '}'.",
639 type: "ObjectExpression",
640 line: 1,
641 column: 28
642 },
643 {
644 message: "There should be no space before '}'.",
645 type: "ObjectExpression",
646 line: 1,
647 column: 40
648 }
649 ]
650 },
651 {
652 code: "export const thing = {value: 1 };",
653 output: "export const thing = { value: 1 };",
654 ecmaFeatures: {
655 modules: true,
656 blockBindings: true
657 },
658 options: ["always"],
659 errors: [
660 {
661 message: "A space is required after '{'.",
662 type: "ObjectExpression",
663 line: 1,
664 column: 22
665 }
666 ]
667 },
668
669 // destructuring
670 {
671 code: "var {x, y} = y",
672 output: "var { x, y } = y",
673 ecmaFeatures: {destructuring: true},
674 options: ["always"],
675 errors: [
676 {
677 message: "A space is required after '{'.",
678 type: "ObjectPattern",
679 line: 1,
680 column: 5
681 },
682 {
683 message: "A space is required before '}'.",
684 type: "ObjectPattern",
685 line: 1,
686 column: 10
687 }
688 ]
689 },
690 {
691 code: "var { x, y} = y",
692 output: "var { x, y } = y",
693 ecmaFeatures: {destructuring: true},
694 options: ["always"],
695 errors: [
696 {
697 message: "A space is required before '}'.",
698 type: "ObjectPattern",
699 line: 1,
700 column: 11
701 }
702 ]
703 },
704 {
705 code: "var { x, y } = y",
706 output: "var {x, y} = y",
707 ecmaFeatures: {destructuring: true},
708 options: ["never"],
709 errors: [
710 {
711 message: "There should be no space after '{'.",
712 type: "ObjectPattern",
713 line: 1,
714 column: 5
715 },
716 {
717 message: "There should be no space before '}'.",
718 type: "ObjectPattern",
719 line: 1,
720 column: 12
721 }
722 ]
723 },
724 {
725 code: "var {x, y } = y",
726 output: "var {x, y} = y",
727 ecmaFeatures: {destructuring: true},
728 options: ["never"],
729 errors: [
730 {
731 message: "There should be no space before '}'.",
732 type: "ObjectPattern",
733 line: 1,
734 column: 11
735 }
736 ]
737 },
738 {
739 code: "var { x=10} = y",
740 output: "var { x=10 } = y",
741 ecmaFeatures: {destructuring: true},
742 options: ["always"],
743 errors: [
744 {
745 message: "A space is required before '}'.",
746 type: "ObjectPattern",
747 line: 1,
748 column: 11
749 }
750 ]
751 },
752 {
753 code: "var {x=10 } = y",
754 output: "var { x=10 } = y",
755 ecmaFeatures: {destructuring: true},
756 options: ["always"],
757 errors: [
758 {
759 message: "A space is required after '{'.",
760 type: "ObjectPattern",
761 line: 1,
762 column: 5
763 }
764 ]
765 },
766
767 // never - arraysInObjects
768 {
769 code: "var obj = {'foo': [1, 2]};",
770 output: "var obj = {'foo': [1, 2] };",
771 options: ["never", {"arraysInObjects": true}],
772 errors: [
773 {
774 message: "A space is required before '}'.",
775 type: "ObjectExpression"
776 }
777 ]
778 },
779 {
780 code: "var obj = {'foo': [1, 2] , 'bar': ['baz', 'qux']};",
781 output: "var obj = {'foo': [1, 2] , 'bar': ['baz', 'qux'] };",
782 options: ["never", {"arraysInObjects": true}],
783 errors: [
784 {
785 message: "A space is required before '}'.",
786 type: "ObjectExpression"
787 }
788 ]
789 },
790
791 // Babel test cases.
792
793 // always - destructuring typed object param
794 {
795 code: "function fn({a,b}: Object){}",
796 output: "function fn({ a,b }: Object){}",
797 options: ["always"],
798 parser: "babel-eslint",
799 ecmaFeatures: {
800 destructuring: true
801 },
802 errors: [
803 {
804 message: "A space is required after '{'.",
805 type: "ObjectPattern",
806 line: 1,
807 column: 13
808 },
809 {
810 message: "A space is required before '}'.",
811 type: "ObjectPattern",
812 line: 1,
813 column: 17
814 }
815 ]
816 },
817
818 // never - destructuring typed object param
819 {
820 code: "function fn({ a,b }: Object){}",
821 output: "function fn({a,b}: Object){}",
822 options: ["never"],
823 parser: "babel-eslint",
824 ecmaFeatures: {
825 destructuring: true
826 },
827 errors: [
828 {
829 message: "There should be no space after '{'.",
830 type: "ObjectPattern",
831 line: 1,
832 column: 13
833 },
834 {
835 message: "There should be no space before '}'.",
836 type: "ObjectPattern",
837 line: 1,
838 column: 19
839 }
840 ]
841 }
842 ]
843});