]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/rest-spread-spacing.js
2 * @fileoverview Enforce spacing between rest and spread operators and their expressions.
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const rule
= require("../../../lib/rules/rest-spread-spacing"),
13 { RuleTester
} = require("../../../lib/rule-tester");
16 //------------------------------------------------------------------------------
18 //------------------------------------------------------------------------------
20 const ruleTester
= new RuleTester({ parserOptions
: { ecmaVersion
: 6 } });
22 ruleTester
.run("rest-spread-spacing", rule
, {
27 { code
: "fn(...args)", options
: ["never"] },
28 { code
: "fn(... args)", options
: ["always"] },
29 { code
: "fn(...\targs)", options
: ["always"] },
30 { code
: "fn(...\nargs)", options
: ["always"] },
32 "[...(arr), 4, 5, 6]",
33 "[...( arr ), 4, 5, 6]",
34 { code
: "[...arr, 4, 5, 6]", options
: ["never"] },
35 { code
: "[... arr, 4, 5, 6]", options
: ["always"] },
36 { code
: "[...\tarr, 4, 5, 6]", options
: ["always"] },
37 { code
: "[...\narr, 4, 5, 6]", options
: ["always"] },
38 "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
39 { code
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];", options
: ["never"] },
40 { code
: "let [a, b, ... arr] = [1, 2, 3, 4, 5];", options
: ["always"] },
41 { code
: "let [a, b, ...\tarr] = [1, 2, 3, 4, 5];", options
: ["always"] },
42 { code
: "let [a, b, ...\narr] = [1, 2, 3, 4, 5];", options
: ["always"] },
43 { code
: "let n = { x, y, ...z };", parserOptions
: { ecmaVersion
: 2018 } },
44 { code
: "let n = { x, y, ...(z) };", parserOptions
: { ecmaVersion
: 2018 } },
45 { code
: "let n = { x, y, ...( z ) };", parserOptions
: { ecmaVersion
: 2018 } },
46 { code
: "let n = { x, y, ...z };", options
: ["never"], parserOptions
: { ecmaVersion
: 2018 } },
47 { code
: "let n = { x, y, ... z };", options
: ["always"], parserOptions
: { ecmaVersion
: 2018 } },
48 { code
: "let n = { x, y, ...\tz };", options
: ["always"], parserOptions
: { ecmaVersion
: 2018 } },
49 { code
: "let n = { x, y, ...\nz };", options
: ["always"], parserOptions
: { ecmaVersion
: 2018 } },
50 { code
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", parserOptions
: { ecmaVersion
: 2018 } },
51 { code
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", options
: ["never"], parserOptions
: { ecmaVersion
: 2018 } },
52 { code
: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };", options
: ["always"], parserOptions
: { ecmaVersion
: 2018 } },
53 { code
: "let { x, y, ...\tz } = { x: 1, y: 2, a: 3, b: 4 };", options
: ["always"], parserOptions
: { ecmaVersion
: 2018 } },
54 { code
: "let { x, y, ...\nz } = { x: 1, y: 2, a: 3, b: 4 };", options
: ["always"], parserOptions
: { ecmaVersion
: 2018 } }
60 output
: "fn(...args)",
66 messageId
: "unexpectedWhitespace",
67 data
: { type
: "spread" },
73 output
: "fn(...args)",
79 messageId
: "unexpectedWhitespace",
80 data
: { type
: "spread" },
85 code
: "fn(...\targs)",
86 output
: "fn(...args)",
92 messageId
: "unexpectedWhitespace",
93 data
: { type
: "spread" },
98 code
: "fn(... \t args)",
99 output
: "fn(...args)",
105 messageId
: "unexpectedWhitespace",
106 data
: { type
: "spread" },
107 type
: "SpreadElement"
111 code
: "fn(...\nargs)",
112 output
: "fn(...args)",
118 messageId
: "unexpectedWhitespace",
119 data
: { type
: "spread" },
120 type
: "SpreadElement"
124 code
: "fn(...\n args)",
125 output
: "fn(...args)",
131 messageId
: "unexpectedWhitespace",
132 data
: { type
: "spread" },
133 type
: "SpreadElement"
137 code
: "fn(...\n\targs)",
138 output
: "fn(...args)",
144 messageId
: "unexpectedWhitespace",
145 data
: { type
: "spread" },
146 type
: "SpreadElement"
150 code
: "fn(... args)",
151 output
: "fn(...args)",
158 messageId
: "unexpectedWhitespace",
159 data
: { type
: "spread" },
160 type
: "SpreadElement"
164 code
: "fn(...\targs)",
165 output
: "fn(...args)",
172 messageId
: "unexpectedWhitespace",
173 data
: { type
: "spread" },
174 type
: "SpreadElement"
178 code
: "fn(...\nargs)",
179 output
: "fn(...args)",
186 messageId
: "unexpectedWhitespace",
187 data
: { type
: "spread" },
188 type
: "SpreadElement"
193 output
: "fn(... args)",
200 messageId
: "expectedWhitespace",
201 data
: { type
: "spread" },
202 type
: "SpreadElement"
206 code
: "fn(... (args))",
207 output
: "fn(...(args))",
213 messageId
: "unexpectedWhitespace",
214 data
: { type
: "spread" },
215 type
: "SpreadElement"
219 code
: "fn(... ( args ))",
220 output
: "fn(...( args ))",
226 messageId
: "unexpectedWhitespace",
227 data
: { type
: "spread" },
228 type
: "SpreadElement"
232 code
: "fn(...(args))",
233 output
: "fn(... (args))",
240 messageId
: "expectedWhitespace",
241 data
: { type
: "spread" },
242 type
: "SpreadElement"
246 code
: "fn(...( args ))",
247 output
: "fn(... ( args ))",
254 messageId
: "expectedWhitespace",
255 data
: { type
: "spread" },
256 type
: "SpreadElement"
260 code
: "[... arr, 4, 5, 6]",
261 output
: "[...arr, 4, 5, 6]",
267 messageId
: "unexpectedWhitespace",
268 data
: { type
: "spread" },
269 type
: "SpreadElement"
273 code
: "[...\tarr, 4, 5, 6]",
274 output
: "[...arr, 4, 5, 6]",
280 messageId
: "unexpectedWhitespace",
281 data
: { type
: "spread" },
282 type
: "SpreadElement"
286 code
: "[...\narr, 4, 5, 6]",
287 output
: "[...arr, 4, 5, 6]",
293 messageId
: "unexpectedWhitespace",
294 data
: { type
: "spread" },
295 type
: "SpreadElement"
299 code
: "[... arr, 4, 5, 6]",
300 output
: "[...arr, 4, 5, 6]",
307 messageId
: "unexpectedWhitespace",
308 data
: { type
: "spread" },
309 type
: "SpreadElement"
313 code
: "[...\tarr, 4, 5, 6]",
314 output
: "[...arr, 4, 5, 6]",
321 messageId
: "unexpectedWhitespace",
322 data
: { type
: "spread" },
323 type
: "SpreadElement"
327 code
: "[...\narr, 4, 5, 6]",
328 output
: "[...arr, 4, 5, 6]",
335 messageId
: "unexpectedWhitespace",
336 data
: { type
: "spread" },
337 type
: "SpreadElement"
341 code
: "[...arr, 4, 5, 6]",
342 output
: "[... arr, 4, 5, 6]",
349 messageId
: "expectedWhitespace",
350 data
: { type
: "spread" },
351 type
: "SpreadElement"
355 code
: "[... (arr), 4, 5, 6]",
356 output
: "[...(arr), 4, 5, 6]",
362 messageId
: "unexpectedWhitespace",
363 data
: { type
: "spread" },
364 type
: "SpreadElement"
368 code
: "[... ( arr ), 4, 5, 6]",
369 output
: "[...( arr ), 4, 5, 6]",
375 messageId
: "unexpectedWhitespace",
376 data
: { type
: "spread" },
377 type
: "SpreadElement"
381 code
: "[...(arr), 4, 5, 6]",
382 output
: "[... (arr), 4, 5, 6]",
389 messageId
: "expectedWhitespace",
390 data
: { type
: "spread" },
391 type
: "SpreadElement"
395 code
: "[...( arr ), 4, 5, 6]",
396 output
: "[... ( arr ), 4, 5, 6]",
403 messageId
: "expectedWhitespace",
404 data
: { type
: "spread" },
405 type
: "SpreadElement"
409 code
: "let [a, b, ... arr] = [1, 2, 3, 4, 5];",
410 output
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
416 messageId
: "unexpectedWhitespace",
417 data
: { type
: "rest" },
422 code
: "let [a, b, ...\tarr] = [1, 2, 3, 4, 5];",
423 output
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
429 messageId
: "unexpectedWhitespace",
430 data
: { type
: "rest" },
435 code
: "let [a, b, ...\narr] = [1, 2, 3, 4, 5];",
436 output
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
442 messageId
: "unexpectedWhitespace",
443 data
: { type
: "rest" },
448 code
: "let [a, b, ... arr] = [1, 2, 3, 4, 5];",
449 output
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
456 messageId
: "unexpectedWhitespace",
457 data
: { type
: "rest" },
462 code
: "let [a, b, ...\tarr] = [1, 2, 3, 4, 5];",
463 output
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
470 messageId
: "unexpectedWhitespace",
471 data
: { type
: "rest" },
476 code
: "let [a, b, ...\narr] = [1, 2, 3, 4, 5];",
477 output
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
484 messageId
: "unexpectedWhitespace",
485 data
: { type
: "rest" },
490 code
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
491 output
: "let [a, b, ... arr] = [1, 2, 3, 4, 5];",
498 messageId
: "expectedWhitespace",
499 data
: { type
: "rest" },
504 code
: "let n = { x, y, ... z };",
505 output
: "let n = { x, y, ...z };",
506 parserOptions
: { ecmaVersion
: 2018 },
512 messageId
: "unexpectedWhitespace",
513 data
: { type
: "spread property" },
514 type
: "SpreadElement"
518 code
: "let n = { x, y, ...\tz };",
519 output
: "let n = { x, y, ...z };",
520 parserOptions
: { ecmaVersion
: 2018 },
526 messageId
: "unexpectedWhitespace",
527 data
: { type
: "spread property" },
528 type
: "SpreadElement"
532 code
: "let n = { x, y, ...\nz };",
533 output
: "let n = { x, y, ...z };",
534 parserOptions
: { ecmaVersion
: 2018 },
540 messageId
: "unexpectedWhitespace",
541 data
: { type
: "spread property" },
542 type
: "SpreadElement"
546 code
: "let n = { x, y, ... z };",
547 output
: "let n = { x, y, ...z };",
549 parserOptions
: { ecmaVersion
: 2018 },
555 messageId
: "unexpectedWhitespace",
556 data
: { type
: "spread property" },
557 type
: "SpreadElement"
561 code
: "let n = { x, y, ...\tz };",
562 output
: "let n = { x, y, ...z };",
564 parserOptions
: { ecmaVersion
: 2018 },
570 messageId
: "unexpectedWhitespace",
571 data
: { type
: "spread property" },
572 type
: "SpreadElement"
576 code
: "let n = { x, y, ...\nz };",
577 output
: "let n = { x, y, ...z };",
579 parserOptions
: { ecmaVersion
: 2018 },
585 messageId
: "unexpectedWhitespace",
586 data
: { type
: "spread property" },
587 type
: "SpreadElement"
591 code
: "let n = { x, y, ...z };",
592 output
: "let n = { x, y, ... z };",
594 parserOptions
: { ecmaVersion
: 2018 },
600 messageId
: "expectedWhitespace",
601 data
: { type
: "spread property" },
602 type
: "SpreadElement"
606 code
: "let n = { x, y, ... (z) };",
607 output
: "let n = { x, y, ...(z) };",
609 parserOptions
: { ecmaVersion
: 2018 },
615 messageId
: "unexpectedWhitespace",
616 data
: { type
: "spread property" },
617 type
: "SpreadElement"
621 code
: "let n = { x, y, ... ( z ) };",
622 output
: "let n = { x, y, ...( z ) };",
624 parserOptions
: { ecmaVersion
: 2018 },
630 messageId
: "unexpectedWhitespace",
631 data
: { type
: "spread property" },
632 type
: "SpreadElement"
636 code
: "let n = { x, y, ...(z) };",
637 output
: "let n = { x, y, ... (z) };",
639 parserOptions
: { ecmaVersion
: 2018 },
645 messageId
: "expectedWhitespace",
646 data
: { type
: "spread property" },
647 type
: "SpreadElement"
651 code
: "let n = { x, y, ...( z ) };",
652 output
: "let n = { x, y, ... ( z ) };",
654 parserOptions
: { ecmaVersion
: 2018 },
660 messageId
: "expectedWhitespace",
661 data
: { type
: "spread property" },
662 type
: "SpreadElement"
666 code
: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };",
667 output
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };",
668 parserOptions
: { ecmaVersion
: 2018 },
674 messageId
: "unexpectedWhitespace",
675 data
: { type
: "rest property" },
680 code
: "let { x, y, ...\tz } = { x: 1, y: 2, a: 3, b: 4 };",
681 output
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };",
682 parserOptions
: { ecmaVersion
: 2018 },
688 messageId
: "unexpectedWhitespace",
689 data
: { type
: "rest property" },
694 code
: "let { x, y, ...\nz } = { x: 1, y: 2, a: 3, b: 4 };",
695 output
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };",
696 parserOptions
: { ecmaVersion
: 2018 },
702 messageId
: "unexpectedWhitespace",
703 data
: { type
: "rest property" },
708 code
: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };",
709 output
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };",
711 parserOptions
: { ecmaVersion
: 2018 },
717 messageId
: "unexpectedWhitespace",
718 data
: { type
: "rest property" },
723 code
: "let { x, y, ...\tz } = { x: 1, y: 2, a: 3, b: 4 };",
724 output
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };",
726 parserOptions
: { ecmaVersion
: 2018 },
732 messageId
: "unexpectedWhitespace",
733 data
: { type
: "rest property" },
738 code
: "let { x, y, ...\nz } = { x: 1, y: 2, a: 3, b: 4 };",
739 output
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };",
741 parserOptions
: { ecmaVersion
: 2018 },
747 messageId
: "unexpectedWhitespace",
748 data
: { type
: "rest property" },
753 code
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };",
754 output
: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };",
756 parserOptions
: { ecmaVersion
: 2018 },
762 messageId
: "expectedWhitespace",
763 data
: { type
: "rest property" },