]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/rest-spread-spacing.js
first commit
[pve-eslint.git] / eslint / tests / lib / rules / rest-spread-spacing.js
1 /**
2 * @fileoverview Enforce spacing between rest and spread operators and their expressions.
3 * @author Kai Cataldo
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/rest-spread-spacing"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
16
17 ruleTester.run("rest-spread-spacing", rule, {
18 valid: [
19 "fn(...args)",
20 "fn(...(args))",
21 "fn(...( args ))",
22 { code: "fn(...args)", options: ["never"] },
23 { code: "fn(... args)", options: ["always"] },
24 { code: "fn(...\targs)", options: ["always"] },
25 { code: "fn(...\nargs)", options: ["always"] },
26 "[...arr, 4, 5, 6]",
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 } }
50 ],
51
52 invalid: [
53 {
54 code: "fn(... args)",
55 output: "fn(...args)",
56 errors: [{
57 line: 1,
58 column: 7,
59 messageId: "unexpectedWhitespace",
60 data: { type: "spread" },
61 type: "SpreadElement"
62 }]
63 },
64 {
65 code: "fn(...\targs)",
66 output: "fn(...args)",
67 errors: [{
68 line: 1,
69 column: 7,
70 messageId: "unexpectedWhitespace",
71 data: { type: "spread" },
72 type: "SpreadElement"
73 }]
74 },
75 {
76 code: "fn(...\nargs)",
77 output: "fn(...args)",
78 errors: [{
79 line: 1,
80 column: 7,
81 messageId: "unexpectedWhitespace",
82 data: { type: "spread" },
83 type: "SpreadElement"
84 }]
85 },
86 {
87 code: "fn(... args)",
88 output: "fn(...args)",
89 options: ["never"],
90 errors: [{
91 line: 1,
92 column: 7,
93 messageId: "unexpectedWhitespace",
94 data: { type: "spread" },
95 type: "SpreadElement"
96 }]
97 },
98 {
99 code: "fn(...\targs)",
100 output: "fn(...args)",
101 options: ["never"],
102 errors: [{
103 line: 1,
104 column: 7,
105 messageId: "unexpectedWhitespace",
106 data: { type: "spread" },
107 type: "SpreadElement"
108 }]
109 },
110 {
111 code: "fn(...\nargs)",
112 output: "fn(...args)",
113 options: ["never"],
114 errors: [{
115 line: 1,
116 column: 7,
117 messageId: "unexpectedWhitespace",
118 data: { type: "spread" },
119 type: "SpreadElement"
120 }]
121 },
122 {
123 code: "fn(...args)",
124 output: "fn(... args)",
125 options: ["always"],
126 errors: [{
127 line: 1,
128 column: 7,
129 messageId: "expectedWhitespace",
130 data: { type: "spread" },
131 type: "SpreadElement"
132 }]
133 },
134 {
135 code: "fn(... (args))",
136 output: "fn(...(args))",
137 errors: [{
138 line: 1,
139 column: 7,
140 messageId: "unexpectedWhitespace",
141 data: { type: "spread" },
142 type: "SpreadElement"
143 }]
144 },
145 {
146 code: "fn(... ( args ))",
147 output: "fn(...( args ))",
148 errors: [{
149 line: 1,
150 column: 7,
151 messageId: "unexpectedWhitespace",
152 data: { type: "spread" },
153 type: "SpreadElement"
154 }]
155 },
156 {
157 code: "fn(...(args))",
158 output: "fn(... (args))",
159 options: ["always"],
160 errors: [{
161 line: 1,
162 column: 7,
163 messageId: "expectedWhitespace",
164 data: { type: "spread" },
165 type: "SpreadElement"
166 }]
167 },
168 {
169 code: "fn(...( args ))",
170 output: "fn(... ( args ))",
171 options: ["always"],
172 errors: [{
173 line: 1,
174 column: 7,
175 messageId: "expectedWhitespace",
176 data: { type: "spread" },
177 type: "SpreadElement"
178 }]
179 },
180 {
181 code: "[... arr, 4, 5, 6]",
182 output: "[...arr, 4, 5, 6]",
183 errors: [{
184 line: 1,
185 column: 5,
186 messageId: "unexpectedWhitespace",
187 data: { type: "spread" },
188 type: "SpreadElement"
189 }]
190 },
191 {
192 code: "[...\tarr, 4, 5, 6]",
193 output: "[...arr, 4, 5, 6]",
194 errors: [{
195 line: 1,
196 column: 5,
197 messageId: "unexpectedWhitespace",
198 data: { type: "spread" },
199 type: "SpreadElement"
200 }]
201 },
202 {
203 code: "[...\narr, 4, 5, 6]",
204 output: "[...arr, 4, 5, 6]",
205 errors: [{
206 line: 1,
207 column: 5,
208 messageId: "unexpectedWhitespace",
209 data: { type: "spread" },
210 type: "SpreadElement"
211 }]
212 },
213 {
214 code: "[... arr, 4, 5, 6]",
215 output: "[...arr, 4, 5, 6]",
216 options: ["never"],
217 errors: [{
218 line: 1,
219 column: 5,
220 messageId: "unexpectedWhitespace",
221 data: { type: "spread" },
222 type: "SpreadElement"
223 }]
224 },
225 {
226 code: "[...\tarr, 4, 5, 6]",
227 output: "[...arr, 4, 5, 6]",
228 options: ["never"],
229 errors: [{
230 line: 1,
231 column: 5,
232 messageId: "unexpectedWhitespace",
233 data: { type: "spread" },
234 type: "SpreadElement"
235 }]
236 },
237 {
238 code: "[...\narr, 4, 5, 6]",
239 output: "[...arr, 4, 5, 6]",
240 options: ["never"],
241 errors: [{
242 line: 1,
243 column: 5,
244 messageId: "unexpectedWhitespace",
245 data: { type: "spread" },
246 type: "SpreadElement"
247 }]
248 },
249 {
250 code: "[...arr, 4, 5, 6]",
251 output: "[... arr, 4, 5, 6]",
252 options: ["always"],
253 errors: [{
254 line: 1,
255 column: 5,
256 messageId: "expectedWhitespace",
257 data: { type: "spread" },
258 type: "SpreadElement"
259 }]
260 },
261 {
262 code: "[... (arr), 4, 5, 6]",
263 output: "[...(arr), 4, 5, 6]",
264 errors: [{
265 line: 1,
266 column: 5,
267 messageId: "unexpectedWhitespace",
268 data: { type: "spread" },
269 type: "SpreadElement"
270 }]
271 },
272 {
273 code: "[... ( arr ), 4, 5, 6]",
274 output: "[...( arr ), 4, 5, 6]",
275 errors: [{
276 line: 1,
277 column: 5,
278 messageId: "unexpectedWhitespace",
279 data: { type: "spread" },
280 type: "SpreadElement"
281 }]
282 },
283 {
284 code: "[...(arr), 4, 5, 6]",
285 output: "[... (arr), 4, 5, 6]",
286 options: ["always"],
287 errors: [{
288 line: 1,
289 column: 5,
290 messageId: "expectedWhitespace",
291 data: { type: "spread" },
292 type: "SpreadElement"
293 }]
294 },
295 {
296 code: "[...( arr ), 4, 5, 6]",
297 output: "[... ( arr ), 4, 5, 6]",
298 options: ["always"],
299 errors: [{
300 line: 1,
301 column: 5,
302 messageId: "expectedWhitespace",
303 data: { type: "spread" },
304 type: "SpreadElement"
305 }]
306 },
307 {
308 code: "let [a, b, ... arr] = [1, 2, 3, 4, 5];",
309 output: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
310 errors: [{
311 line: 1,
312 column: 15,
313 messageId: "unexpectedWhitespace",
314 data: { type: "rest" },
315 type: "RestElement"
316 }]
317 },
318 {
319 code: "let [a, b, ...\tarr] = [1, 2, 3, 4, 5];",
320 output: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
321 errors: [{
322 line: 1,
323 column: 15,
324 messageId: "unexpectedWhitespace",
325 data: { type: "rest" },
326 type: "RestElement"
327 }]
328 },
329 {
330 code: "let [a, b, ...\narr] = [1, 2, 3, 4, 5];",
331 output: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
332 errors: [{
333 line: 1,
334 column: 15,
335 messageId: "unexpectedWhitespace",
336 data: { type: "rest" },
337 type: "RestElement"
338 }]
339 },
340 {
341 code: "let [a, b, ... arr] = [1, 2, 3, 4, 5];",
342 output: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
343 options: ["never"],
344 errors: [{
345 line: 1,
346 column: 15,
347 messageId: "unexpectedWhitespace",
348 data: { type: "rest" },
349 type: "RestElement"
350 }]
351 },
352 {
353 code: "let [a, b, ...\tarr] = [1, 2, 3, 4, 5];",
354 output: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
355 options: ["never"],
356 errors: [{
357 line: 1,
358 column: 15,
359 messageId: "unexpectedWhitespace",
360 data: { type: "rest" },
361 type: "RestElement"
362 }]
363 },
364 {
365 code: "let [a, b, ...\narr] = [1, 2, 3, 4, 5];",
366 output: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
367 options: ["never"],
368 errors: [{
369 line: 1,
370 column: 15,
371 messageId: "unexpectedWhitespace",
372 data: { type: "rest" },
373 type: "RestElement"
374 }]
375 },
376 {
377 code: "let [a, b, ...arr] = [1, 2, 3, 4, 5];",
378 output: "let [a, b, ... arr] = [1, 2, 3, 4, 5];",
379 options: ["always"],
380 errors: [{
381 line: 1,
382 column: 15,
383 messageId: "expectedWhitespace",
384 data: { type: "rest" },
385 type: "RestElement"
386 }]
387 },
388 {
389 code: "let n = { x, y, ... z };",
390 output: "let n = { x, y, ...z };",
391 parserOptions: { ecmaVersion: 2018 },
392 errors: [{
393 line: 1,
394 column: 20,
395 messageId: "unexpectedWhitespace",
396 data: { type: "spread property" },
397 type: "SpreadElement"
398 }]
399 },
400 {
401 code: "let n = { x, y, ...\tz };",
402 output: "let n = { x, y, ...z };",
403 parserOptions: { ecmaVersion: 2018 },
404 errors: [{
405 line: 1,
406 column: 20,
407 messageId: "unexpectedWhitespace",
408 data: { type: "spread property" },
409 type: "SpreadElement"
410 }]
411 },
412 {
413 code: "let n = { x, y, ...\nz };",
414 output: "let n = { x, y, ...z };",
415 parserOptions: { ecmaVersion: 2018 },
416 errors: [{
417 line: 1,
418 column: 20,
419 messageId: "unexpectedWhitespace",
420 data: { type: "spread property" },
421 type: "SpreadElement"
422 }]
423 },
424 {
425 code: "let n = { x, y, ... z };",
426 output: "let n = { x, y, ...z };",
427 options: ["never"],
428 parserOptions: { ecmaVersion: 2018 },
429 errors: [{
430 line: 1,
431 column: 20,
432 messageId: "unexpectedWhitespace",
433 data: { type: "spread property" },
434 type: "SpreadElement"
435 }]
436 },
437 {
438 code: "let n = { x, y, ...\tz };",
439 output: "let n = { x, y, ...z };",
440 options: ["never"],
441 parserOptions: { ecmaVersion: 2018 },
442 errors: [{
443 line: 1,
444 column: 20,
445 messageId: "unexpectedWhitespace",
446 data: { type: "spread property" },
447 type: "SpreadElement"
448 }]
449 },
450 {
451 code: "let n = { x, y, ...\nz };",
452 output: "let n = { x, y, ...z };",
453 options: ["never"],
454 parserOptions: { ecmaVersion: 2018 },
455 errors: [{
456 line: 1,
457 column: 20,
458 messageId: "unexpectedWhitespace",
459 data: { type: "spread property" },
460 type: "SpreadElement"
461 }]
462 },
463 {
464 code: "let n = { x, y, ...z };",
465 output: "let n = { x, y, ... z };",
466 options: ["always"],
467 parserOptions: { ecmaVersion: 2018 },
468 errors: [{
469 line: 1,
470 column: 20,
471 messageId: "expectedWhitespace",
472 data: { type: "spread property" },
473 type: "SpreadElement"
474 }]
475 },
476 {
477 code: "let n = { x, y, ... (z) };",
478 output: "let n = { x, y, ...(z) };",
479 options: ["never"],
480 parserOptions: { ecmaVersion: 2018 },
481 errors: [{
482 line: 1,
483 column: 20,
484 messageId: "unexpectedWhitespace",
485 data: { type: "spread property" },
486 type: "SpreadElement"
487 }]
488 },
489 {
490 code: "let n = { x, y, ... ( z ) };",
491 output: "let n = { x, y, ...( z ) };",
492 options: ["never"],
493 parserOptions: { ecmaVersion: 2018 },
494 errors: [{
495 line: 1,
496 column: 20,
497 messageId: "unexpectedWhitespace",
498 data: { type: "spread property" },
499 type: "SpreadElement"
500 }]
501 },
502 {
503 code: "let n = { x, y, ...(z) };",
504 output: "let n = { x, y, ... (z) };",
505 options: ["always"],
506 parserOptions: { ecmaVersion: 2018 },
507 errors: [{
508 line: 1,
509 column: 20,
510 messageId: "expectedWhitespace",
511 data: { type: "spread property" },
512 type: "SpreadElement"
513 }]
514 },
515 {
516 code: "let n = { x, y, ...( z ) };",
517 output: "let n = { x, y, ... ( z ) };",
518 options: ["always"],
519 parserOptions: { ecmaVersion: 2018 },
520 errors: [{
521 line: 1,
522 column: 20,
523 messageId: "expectedWhitespace",
524 data: { type: "spread property" },
525 type: "SpreadElement"
526 }]
527 },
528 {
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 },
532 errors: [{
533 line: 1,
534 column: 16,
535 messageId: "unexpectedWhitespace",
536 data: { type: "rest property" },
537 type: "RestElement"
538 }]
539 },
540 {
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 },
544 errors: [{
545 line: 1,
546 column: 16,
547 messageId: "unexpectedWhitespace",
548 data: { type: "rest property" },
549 type: "RestElement"
550 }]
551 },
552 {
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 },
556 errors: [{
557 line: 1,
558 column: 16,
559 messageId: "unexpectedWhitespace",
560 data: { type: "rest property" },
561 type: "RestElement"
562 }]
563 },
564 {
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 };",
567 options: ["never"],
568 parserOptions: { ecmaVersion: 2018 },
569 errors: [{
570 line: 1,
571 column: 16,
572 messageId: "unexpectedWhitespace",
573 data: { type: "rest property" },
574 type: "RestElement"
575 }]
576 },
577 {
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 };",
580 options: ["never"],
581 parserOptions: { ecmaVersion: 2018 },
582 errors: [{
583 line: 1,
584 column: 16,
585 messageId: "unexpectedWhitespace",
586 data: { type: "rest property" },
587 type: "RestElement"
588 }]
589 },
590 {
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 };",
593 options: ["never"],
594 parserOptions: { ecmaVersion: 2018 },
595 errors: [{
596 line: 1,
597 column: 16,
598 messageId: "unexpectedWhitespace",
599 data: { type: "rest property" },
600 type: "RestElement"
601 }]
602 },
603 {
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 };",
606 options: ["always"],
607 parserOptions: { ecmaVersion: 2018 },
608 errors: [{
609 line: 1,
610 column: 16,
611 messageId: "expectedWhitespace",
612 data: { type: "rest property" },
613 type: "RestElement"
614 }]
615 }
616 ]
617 });