]>
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");
15 const ruleTester
= new RuleTester({ parserOptions
: { ecmaVersion
: 6 } });
17 ruleTester
.run("rest-spread-spacing", rule
, {
22 { code
: "fn(...args)", options
: ["never"] },
23 { code
: "fn(... args)", options
: ["always"] },
24 { code
: "fn(...\targs)", options
: ["always"] },
25 { code
: "fn(...\nargs)", options
: ["always"] },
27 "[...(arr), 4, 5, 6]",
28 "[...( arr ), 4, 5, 6]",
29 { code
: "[...arr, 4, 5, 6]", options
: ["never"] },
30 { code
: "[... arr, 4, 5, 6]", options
: ["always"] },
31 { code
: "[...\tarr, 4, 5, 6]", options
: ["always"] },
32 { code
: "[...\narr, 4, 5, 6]", options
: ["always"] },
33 "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
34 { code
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];", options
: ["never"] },
35 { code
: "let [a, b, ... arr] = [1, 2, 3, 4, 5];", options
: ["always"] },
36 { code
: "let [a, b, ...\tarr] = [1, 2, 3, 4, 5];", options
: ["always"] },
37 { code
: "let [a, b, ...\narr] = [1, 2, 3, 4, 5];", options
: ["always"] },
38 { code
: "let n = { x, y, ...z };", parserOptions
: { ecmaVersion
: 2018 } },
39 { code
: "let n = { x, y, ...(z) };", parserOptions
: { ecmaVersion
: 2018 } },
40 { code
: "let n = { x, y, ...( z ) };", parserOptions
: { ecmaVersion
: 2018 } },
41 { code
: "let n = { x, y, ...z };", options
: ["never"], parserOptions
: { ecmaVersion
: 2018 } },
42 { code
: "let n = { x, y, ... z };", options
: ["always"], parserOptions
: { ecmaVersion
: 2018 } },
43 { code
: "let n = { x, y, ...\tz };", options
: ["always"], parserOptions
: { ecmaVersion
: 2018 } },
44 { code
: "let n = { x, y, ...\nz };", options
: ["always"], parserOptions
: { ecmaVersion
: 2018 } },
45 { code
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", parserOptions
: { ecmaVersion
: 2018 } },
46 { code
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", options
: ["never"], parserOptions
: { ecmaVersion
: 2018 } },
47 { code
: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };", options
: ["always"], parserOptions
: { ecmaVersion
: 2018 } },
48 { code
: "let { x, y, ...\tz } = { x: 1, y: 2, a: 3, b: 4 };", options
: ["always"], parserOptions
: { ecmaVersion
: 2018 } },
49 { code
: "let { x, y, ...\nz } = { x: 1, y: 2, a: 3, b: 4 };", options
: ["always"], parserOptions
: { ecmaVersion
: 2018 } }
55 output
: "fn(...args)",
59 messageId
: "unexpectedWhitespace",
60 data
: { type
: "spread" },
65 code
: "fn(...\targs)",
66 output
: "fn(...args)",
70 messageId
: "unexpectedWhitespace",
71 data
: { type
: "spread" },
76 code
: "fn(...\nargs)",
77 output
: "fn(...args)",
81 messageId
: "unexpectedWhitespace",
82 data
: { type
: "spread" },
88 output
: "fn(...args)",
93 messageId
: "unexpectedWhitespace",
94 data
: { type
: "spread" },
99 code
: "fn(...\targs)",
100 output
: "fn(...args)",
105 messageId
: "unexpectedWhitespace",
106 data
: { type
: "spread" },
107 type
: "SpreadElement"
111 code
: "fn(...\nargs)",
112 output
: "fn(...args)",
117 messageId
: "unexpectedWhitespace",
118 data
: { type
: "spread" },
119 type
: "SpreadElement"
124 output
: "fn(... args)",
129 messageId
: "expectedWhitespace",
130 data
: { type
: "spread" },
131 type
: "SpreadElement"
135 code
: "fn(... (args))",
136 output
: "fn(...(args))",
140 messageId
: "unexpectedWhitespace",
141 data
: { type
: "spread" },
142 type
: "SpreadElement"
146 code
: "fn(... ( args ))",
147 output
: "fn(...( args ))",
151 messageId
: "unexpectedWhitespace",
152 data
: { type
: "spread" },
153 type
: "SpreadElement"
157 code
: "fn(...(args))",
158 output
: "fn(... (args))",
163 messageId
: "expectedWhitespace",
164 data
: { type
: "spread" },
165 type
: "SpreadElement"
169 code
: "fn(...( args ))",
170 output
: "fn(... ( args ))",
175 messageId
: "expectedWhitespace",
176 data
: { type
: "spread" },
177 type
: "SpreadElement"
181 code
: "[... arr, 4, 5, 6]",
182 output
: "[...arr, 4, 5, 6]",
186 messageId
: "unexpectedWhitespace",
187 data
: { type
: "spread" },
188 type
: "SpreadElement"
192 code
: "[...\tarr, 4, 5, 6]",
193 output
: "[...arr, 4, 5, 6]",
197 messageId
: "unexpectedWhitespace",
198 data
: { type
: "spread" },
199 type
: "SpreadElement"
203 code
: "[...\narr, 4, 5, 6]",
204 output
: "[...arr, 4, 5, 6]",
208 messageId
: "unexpectedWhitespace",
209 data
: { type
: "spread" },
210 type
: "SpreadElement"
214 code
: "[... arr, 4, 5, 6]",
215 output
: "[...arr, 4, 5, 6]",
220 messageId
: "unexpectedWhitespace",
221 data
: { type
: "spread" },
222 type
: "SpreadElement"
226 code
: "[...\tarr, 4, 5, 6]",
227 output
: "[...arr, 4, 5, 6]",
232 messageId
: "unexpectedWhitespace",
233 data
: { type
: "spread" },
234 type
: "SpreadElement"
238 code
: "[...\narr, 4, 5, 6]",
239 output
: "[...arr, 4, 5, 6]",
244 messageId
: "unexpectedWhitespace",
245 data
: { type
: "spread" },
246 type
: "SpreadElement"
250 code
: "[...arr, 4, 5, 6]",
251 output
: "[... arr, 4, 5, 6]",
256 messageId
: "expectedWhitespace",
257 data
: { type
: "spread" },
258 type
: "SpreadElement"
262 code
: "[... (arr), 4, 5, 6]",
263 output
: "[...(arr), 4, 5, 6]",
267 messageId
: "unexpectedWhitespace",
268 data
: { type
: "spread" },
269 type
: "SpreadElement"
273 code
: "[... ( arr ), 4, 5, 6]",
274 output
: "[...( arr ), 4, 5, 6]",
278 messageId
: "unexpectedWhitespace",
279 data
: { type
: "spread" },
280 type
: "SpreadElement"
284 code
: "[...(arr), 4, 5, 6]",
285 output
: "[... (arr), 4, 5, 6]",
290 messageId
: "expectedWhitespace",
291 data
: { type
: "spread" },
292 type
: "SpreadElement"
296 code
: "[...( arr ), 4, 5, 6]",
297 output
: "[... ( arr ), 4, 5, 6]",
302 messageId
: "expectedWhitespace",
303 data
: { type
: "spread" },
304 type
: "SpreadElement"
308 code
: "let [a, b, ... arr] = [1, 2, 3, 4, 5];",
309 output
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
313 messageId
: "unexpectedWhitespace",
314 data
: { type
: "rest" },
319 code
: "let [a, b, ...\tarr] = [1, 2, 3, 4, 5];",
320 output
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
324 messageId
: "unexpectedWhitespace",
325 data
: { type
: "rest" },
330 code
: "let [a, b, ...\narr] = [1, 2, 3, 4, 5];",
331 output
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
335 messageId
: "unexpectedWhitespace",
336 data
: { type
: "rest" },
341 code
: "let [a, b, ... arr] = [1, 2, 3, 4, 5];",
342 output
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
347 messageId
: "unexpectedWhitespace",
348 data
: { type
: "rest" },
353 code
: "let [a, b, ...\tarr] = [1, 2, 3, 4, 5];",
354 output
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
359 messageId
: "unexpectedWhitespace",
360 data
: { type
: "rest" },
365 code
: "let [a, b, ...\narr] = [1, 2, 3, 4, 5];",
366 output
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
371 messageId
: "unexpectedWhitespace",
372 data
: { type
: "rest" },
377 code
: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
378 output
: "let [a, b, ... arr] = [1, 2, 3, 4, 5];",
383 messageId
: "expectedWhitespace",
384 data
: { type
: "rest" },
389 code
: "let n = { x, y, ... z };",
390 output
: "let n = { x, y, ...z };",
391 parserOptions
: { ecmaVersion
: 2018 },
395 messageId
: "unexpectedWhitespace",
396 data
: { type
: "spread property" },
397 type
: "SpreadElement"
401 code
: "let n = { x, y, ...\tz };",
402 output
: "let n = { x, y, ...z };",
403 parserOptions
: { ecmaVersion
: 2018 },
407 messageId
: "unexpectedWhitespace",
408 data
: { type
: "spread property" },
409 type
: "SpreadElement"
413 code
: "let n = { x, y, ...\nz };",
414 output
: "let n = { x, y, ...z };",
415 parserOptions
: { ecmaVersion
: 2018 },
419 messageId
: "unexpectedWhitespace",
420 data
: { type
: "spread property" },
421 type
: "SpreadElement"
425 code
: "let n = { x, y, ... z };",
426 output
: "let n = { x, y, ...z };",
428 parserOptions
: { ecmaVersion
: 2018 },
432 messageId
: "unexpectedWhitespace",
433 data
: { type
: "spread property" },
434 type
: "SpreadElement"
438 code
: "let n = { x, y, ...\tz };",
439 output
: "let n = { x, y, ...z };",
441 parserOptions
: { ecmaVersion
: 2018 },
445 messageId
: "unexpectedWhitespace",
446 data
: { type
: "spread property" },
447 type
: "SpreadElement"
451 code
: "let n = { x, y, ...\nz };",
452 output
: "let n = { x, y, ...z };",
454 parserOptions
: { ecmaVersion
: 2018 },
458 messageId
: "unexpectedWhitespace",
459 data
: { type
: "spread property" },
460 type
: "SpreadElement"
464 code
: "let n = { x, y, ...z };",
465 output
: "let n = { x, y, ... z };",
467 parserOptions
: { ecmaVersion
: 2018 },
471 messageId
: "expectedWhitespace",
472 data
: { type
: "spread property" },
473 type
: "SpreadElement"
477 code
: "let n = { x, y, ... (z) };",
478 output
: "let n = { x, y, ...(z) };",
480 parserOptions
: { ecmaVersion
: 2018 },
484 messageId
: "unexpectedWhitespace",
485 data
: { type
: "spread property" },
486 type
: "SpreadElement"
490 code
: "let n = { x, y, ... ( z ) };",
491 output
: "let n = { x, y, ...( z ) };",
493 parserOptions
: { ecmaVersion
: 2018 },
497 messageId
: "unexpectedWhitespace",
498 data
: { type
: "spread property" },
499 type
: "SpreadElement"
503 code
: "let n = { x, y, ...(z) };",
504 output
: "let n = { x, y, ... (z) };",
506 parserOptions
: { ecmaVersion
: 2018 },
510 messageId
: "expectedWhitespace",
511 data
: { type
: "spread property" },
512 type
: "SpreadElement"
516 code
: "let n = { x, y, ...( z ) };",
517 output
: "let n = { x, y, ... ( z ) };",
519 parserOptions
: { ecmaVersion
: 2018 },
523 messageId
: "expectedWhitespace",
524 data
: { type
: "spread property" },
525 type
: "SpreadElement"
529 code
: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };",
530 output
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };",
531 parserOptions
: { ecmaVersion
: 2018 },
535 messageId
: "unexpectedWhitespace",
536 data
: { type
: "rest property" },
541 code
: "let { x, y, ...\tz } = { x: 1, y: 2, a: 3, b: 4 };",
542 output
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };",
543 parserOptions
: { ecmaVersion
: 2018 },
547 messageId
: "unexpectedWhitespace",
548 data
: { type
: "rest property" },
553 code
: "let { x, y, ...\nz } = { x: 1, y: 2, a: 3, b: 4 };",
554 output
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };",
555 parserOptions
: { ecmaVersion
: 2018 },
559 messageId
: "unexpectedWhitespace",
560 data
: { type
: "rest property" },
565 code
: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };",
566 output
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };",
568 parserOptions
: { ecmaVersion
: 2018 },
572 messageId
: "unexpectedWhitespace",
573 data
: { type
: "rest property" },
578 code
: "let { x, y, ...\tz } = { x: 1, y: 2, a: 3, b: 4 };",
579 output
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };",
581 parserOptions
: { ecmaVersion
: 2018 },
585 messageId
: "unexpectedWhitespace",
586 data
: { type
: "rest property" },
591 code
: "let { x, y, ...\nz } = { x: 1, y: 2, a: 3, b: 4 };",
592 output
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };",
594 parserOptions
: { ecmaVersion
: 2018 },
598 messageId
: "unexpectedWhitespace",
599 data
: { type
: "rest property" },
604 code
: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };",
605 output
: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };",
607 parserOptions
: { ecmaVersion
: 2018 },
611 messageId
: "expectedWhitespace",
612 data
: { type
: "rest property" },