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