]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/padding-line-between-statements.js
51ddf0eb3b50c0403b6526470189e454905a2d40
[pve-eslint.git] / eslint / tests / lib / rules / padding-line-between-statements.js
1 /**
2 * @fileoverview Tests for padding-line-between-statements rule.
3 * @author Toru Nagashima
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/padding-line-between-statements");
13 const { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2017 } });
20
21 ruleTester.run("padding-line-between-statements", rule, {
22 valid: [
23
24 // do nothing if no options.
25 "'use strict'; foo(); if (a) { bar(); }",
26
27 // do nothing for single statement.
28 {
29 code: "foo()",
30 options: [
31 { blankLine: "never", prev: "*", next: "*" }
32 ]
33 },
34 {
35 code: "foo()",
36 options: [
37 { blankLine: "always", prev: "*", next: "*" }
38 ]
39 },
40
41 //----------------------------------------------------------------------
42 // wildcard
43 //----------------------------------------------------------------------
44
45 {
46 code: "foo();bar();",
47 options: [
48 { blankLine: "never", prev: "*", next: "*" }
49 ]
50 },
51 {
52 code: "foo();\nbar();",
53 options: [
54 { blankLine: "never", prev: "*", next: "*" }
55 ]
56 },
57 {
58 code: "foo();\n//comment\nbar();",
59 options: [
60 { blankLine: "never", prev: "*", next: "*" }
61 ]
62 },
63 {
64 code: "foo();\n/*comment*/\nbar();",
65 options: [
66 { blankLine: "never", prev: "*", next: "*" }
67 ]
68 },
69 {
70 code: "foo();\n\nbar();",
71 options: [
72 { blankLine: "always", prev: "*", next: "*" }
73 ]
74 },
75 {
76 code: "foo();\n\n//comment\nbar();",
77 options: [
78 { blankLine: "always", prev: "*", next: "*" }
79 ]
80 },
81 {
82 code: "foo();\n//comment\n\nbar();",
83 options: [
84 { blankLine: "always", prev: "*", next: "*" }
85 ]
86 },
87 {
88 code: "foo();\n//comment\n\n//comment\nbar();",
89 options: [
90 { blankLine: "always", prev: "*", next: "*" }
91 ]
92 },
93 {
94 code: "if(a){}\n\n;[].map(b)",
95 options: [
96 { blankLine: "always", prev: "if", next: "*" },
97 { blankLine: "never", prev: "empty", next: "*" }
98 ]
99 },
100
101
102 //----------------------------------------------------------------------
103 // block-like
104 //----------------------------------------------------------------------
105
106 {
107 code: "foo();\n\n{ foo() }\n\nfoo();",
108 options: [
109 { blankLine: "always", prev: "*", next: "*" },
110 { blankLine: "never", prev: "block-like", next: "block-like" }
111 ]
112 },
113 {
114 code: "{ foo() } { foo() }",
115 options: [
116 { blankLine: "always", prev: "*", next: "*" },
117 { blankLine: "never", prev: "block-like", next: "block-like" }
118 ]
119 },
120 {
121 code: "{ foo() }\n{ foo() }",
122 options: [
123 { blankLine: "always", prev: "*", next: "*" },
124 { blankLine: "never", prev: "block-like", next: "block-like" }
125 ]
126 },
127 {
128 code: "{ foo() }\n\n{ foo() }",
129 options: [
130 { blankLine: "never", prev: "*", next: "*" },
131 { blankLine: "always", prev: "block-like", next: "block-like" }
132 ]
133 },
134 {
135 code: "{ foo() }\n\n//comment\n{ foo() }",
136 options: [
137 { blankLine: "never", prev: "*", next: "*" },
138 { blankLine: "always", prev: "block-like", next: "block-like" }
139 ]
140 },
141 {
142 code: "if(a);\nfoo()",
143 options: [
144 { blankLine: "never", prev: "*", next: "*" },
145 { blankLine: "always", prev: "block-like", next: "*" }
146 ]
147 },
148 {
149 code: "do;while(a);\nfoo()",
150 options: [
151 { blankLine: "never", prev: "*", next: "*" },
152 { blankLine: "always", prev: "block-like", next: "*" }
153 ]
154 },
155 {
156 code: "do{}while(a);\n\nfoo()",
157 options: [
158 { blankLine: "never", prev: "*", next: "*" },
159 { blankLine: "always", prev: "block-like", next: "*" }
160 ]
161 },
162 {
163 code: "a={}\nfoo()",
164 options: [
165 { blankLine: "never", prev: "*", next: "*" },
166 { blankLine: "always", prev: "block-like", next: "*" }
167 ]
168 },
169 {
170 code: "let a={}\nfoo()",
171 options: [
172 { blankLine: "never", prev: "*", next: "*" },
173 { blankLine: "always", prev: "block-like", next: "*" }
174 ]
175 },
176 {
177 code: "foo(function(){})\nfoo()",
178 options: [
179 { blankLine: "never", prev: "*", next: "*" },
180 { blankLine: "always", prev: "block-like", next: "*" }
181 ]
182 },
183 {
184 code: "(function(){})()\n\nfoo()",
185 options: [
186 { blankLine: "never", prev: "*", next: "*" },
187 { blankLine: "always", prev: "block-like", next: "*" }
188 ]
189 },
190 {
191 code: "!function(){}()\n\nfoo()",
192 options: [
193 { blankLine: "never", prev: "*", next: "*" },
194 { blankLine: "always", prev: "block-like", next: "*" }
195 ]
196 },
197
198 //----------------------------------------------------------------------
199 // cjs-export
200 //----------------------------------------------------------------------
201
202 {
203 code: "module.exports=1",
204 options: [
205 { blankLine: "never", prev: "*", next: "*" },
206 { blankLine: "always", prev: "cjs-export", next: "*" }
207 ]
208 },
209 {
210 code: "module.exports=1\n\nfoo()",
211 options: [
212 { blankLine: "never", prev: "*", next: "*" },
213 { blankLine: "always", prev: "cjs-export", next: "*" }
214 ]
215 },
216 {
217 code: "module.exports.foo=1\n\nfoo()",
218 options: [
219 { blankLine: "never", prev: "*", next: "*" },
220 { blankLine: "always", prev: "cjs-export", next: "*" }
221 ]
222 },
223 {
224 code: "exports.foo=1\n\nfoo()",
225 options: [
226 { blankLine: "never", prev: "*", next: "*" },
227 { blankLine: "always", prev: "cjs-export", next: "*" }
228 ]
229 },
230 {
231 code: "m.exports=1\nfoo()",
232 options: [
233 { blankLine: "never", prev: "*", next: "*" },
234 { blankLine: "always", prev: "cjs-export", next: "*" }
235 ]
236 },
237 {
238 code: "module.foo=1\nfoo()",
239 options: [
240 { blankLine: "never", prev: "*", next: "*" },
241 { blankLine: "always", prev: "cjs-export", next: "*" }
242 ]
243 },
244
245 //----------------------------------------------------------------------
246 // cjs-import
247 //----------------------------------------------------------------------
248
249 {
250 code: "foo=require(\"foo\")\nfoo()",
251 options: [
252 { blankLine: "never", prev: "*", next: "*" },
253 { blankLine: "always", prev: "cjs-import", next: "*" }
254 ]
255 },
256 {
257 code: "const foo=a.require(\"foo\")\nfoo()",
258 options: [
259 { blankLine: "never", prev: "*", next: "*" },
260 { blankLine: "always", prev: "cjs-import", next: "*" }
261 ]
262 },
263
264 //----------------------------------------------------------------------
265 // directive
266 //----------------------------------------------------------------------
267
268 {
269 code: "\"use strict\"\n\nfoo()",
270 options: [
271 { blankLine: "never", prev: "*", next: "*" },
272 { blankLine: "always", prev: "directive", next: "*" }
273 ]
274 },
275 {
276 code: "function foo(){\"use strict\"\n\nfoo()}",
277 options: [
278 { blankLine: "never", prev: "*", next: "*" },
279 { blankLine: "always", prev: "directive", next: "*" }
280 ]
281 },
282 {
283 code: "(function foo(){\"use strict\"\n\nfoo()})",
284 options: [
285 { blankLine: "never", prev: "*", next: "*" },
286 { blankLine: "always", prev: "directive", next: "*" }
287 ]
288 },
289 {
290 code: "(()=>{\"use strict\"\n\nfoo()})",
291 options: [
292 { blankLine: "never", prev: "*", next: "*" },
293 { blankLine: "always", prev: "directive", next: "*" }
294 ]
295 },
296 {
297 code: "'use strict'\n\nfoo()",
298 options: [
299 { blankLine: "never", prev: "*", next: "*" },
300 { blankLine: "always", prev: "directive", next: "*" }
301 ]
302 },
303 {
304 code: "foo(\"use strict\")\nfoo()",
305 options: [
306 { blankLine: "never", prev: "*", next: "*" },
307 { blankLine: "always", prev: "directive", next: "*" }
308 ]
309 },
310 {
311 code: "`use strict`\nfoo()",
312 options: [
313 { blankLine: "never", prev: "*", next: "*" },
314 { blankLine: "always", prev: "directive", next: "*" }
315 ]
316 },
317 {
318 code: "(\"use strict\")\nfoo()",
319 options: [
320 { blankLine: "never", prev: "*", next: "*" },
321 { blankLine: "always", prev: "directive", next: "*" }
322 ]
323 },
324 {
325 code: "'use '+'strict'\nfoo()",
326 options: [
327 { blankLine: "never", prev: "*", next: "*" },
328 { blankLine: "always", prev: "directive", next: "*" }
329 ]
330 },
331 {
332 code: "foo()\n\"use strict\"\nfoo()",
333 options: [
334 { blankLine: "never", prev: "*", next: "*" },
335 { blankLine: "always", prev: "directive", next: "*" }
336 ]
337 },
338 {
339 code: "{\"use strict\"\nfoo()}",
340 options: [
341 { blankLine: "never", prev: "*", next: "*" },
342 { blankLine: "always", prev: "directive", next: "*" }
343 ]
344 },
345
346 //----------------------------------------------------------------------
347 // multiline-block-like
348 //----------------------------------------------------------------------
349
350 {
351 code: "{}\nfoo()",
352 options: [
353 { blankLine: "never", prev: "*", next: "*" },
354 { blankLine: "always", prev: "multiline-block-like", next: "*" }
355 ]
356 },
357 {
358 code: "if(a){}\nfoo()",
359 options: [
360 { blankLine: "never", prev: "*", next: "*" },
361 { blankLine: "always", prev: "multiline-block-like", next: "*" }
362 ]
363 },
364 {
365 code: "while(a){}\nfoo()",
366 options: [
367 { blankLine: "never", prev: "*", next: "*" },
368 { blankLine: "always", prev: "multiline-block-like", next: "*" }
369 ]
370 },
371 {
372 code: "{\n}\n\nfoo()",
373 options: [
374 { blankLine: "never", prev: "*", next: "*" },
375 { blankLine: "always", prev: "multiline-block-like", next: "*" }
376 ]
377 },
378 {
379 code: "if(a){\n}\n\nfoo()",
380 options: [
381 { blankLine: "never", prev: "*", next: "*" },
382 { blankLine: "always", prev: "multiline-block-like", next: "*" }
383 ]
384 },
385 {
386 code: "while(a){\n}\n\nfoo()",
387 options: [
388 { blankLine: "never", prev: "*", next: "*" },
389 { blankLine: "always", prev: "multiline-block-like", next: "*" }
390 ]
391 },
392 {
393 code: "do{\n}while(a)\n\nfoo()",
394 options: [
395 { blankLine: "never", prev: "*", next: "*" },
396 { blankLine: "always", prev: "multiline-block-like", next: "*" }
397 ]
398 },
399 {
400 code: "for(;;){\n}\n\nfoo()",
401 options: [
402 { blankLine: "never", prev: "*", next: "*" },
403 { blankLine: "always", prev: "multiline-block-like", next: "*" }
404 ]
405 },
406 {
407 code: "for(a in b){\n}\n\nfoo()",
408 options: [
409 { blankLine: "never", prev: "*", next: "*" },
410 { blankLine: "always", prev: "multiline-block-like", next: "*" }
411 ]
412 },
413 {
414 code: "for(a of b){\n}\n\nfoo()",
415 options: [
416 { blankLine: "never", prev: "*", next: "*" },
417 { blankLine: "always", prev: "multiline-block-like", next: "*" }
418 ]
419 },
420 {
421 code: "switch(a){\n}\n\nfoo()",
422 options: [
423 { blankLine: "never", prev: "*", next: "*" },
424 { blankLine: "always", prev: "multiline-block-like", next: "*" }
425 ]
426 },
427 {
428 code: "function foo(a){\n}\n\nfoo()",
429 options: [
430 { blankLine: "never", prev: "*", next: "*" },
431 { blankLine: "always", prev: "multiline-block-like", next: "*" }
432 ]
433 },
434 {
435 code: "var a=function foo(a){\n}\n\nfoo()",
436 options: [
437 { blankLine: "never", prev: "*", next: "*" },
438 { blankLine: "always", prev: "multiline-block-like", next: "*" }
439 ]
440 },
441
442 //----------------------------------------------------------------------
443 // block
444 //----------------------------------------------------------------------
445
446 {
447 code: "{}\n\nfoo()",
448 options: [
449 { blankLine: "never", prev: "*", next: "*" },
450 { blankLine: "always", prev: "block", next: "*" }
451 ]
452 },
453 {
454 code: "{\n}\n\nfoo()",
455 options: [
456 { blankLine: "never", prev: "*", next: "*" },
457 { blankLine: "always", prev: "block", next: "*" }
458 ]
459 },
460 {
461 code: "{\nfoo()\n}\n\nfoo()",
462 options: [
463 { blankLine: "never", prev: "*", next: "*" },
464 { blankLine: "always", prev: "block", next: "*" }
465 ]
466 },
467 {
468 code: "if(a){}\nfoo()",
469 options: [
470 { blankLine: "never", prev: "*", next: "*" },
471 { blankLine: "always", prev: "block", next: "*" }
472 ]
473 },
474 {
475 code: "a={}\nfoo()",
476 options: [
477 { blankLine: "never", prev: "*", next: "*" },
478 { blankLine: "always", prev: "block", next: "*" }
479 ]
480 },
481
482 //----------------------------------------------------------------------
483 // empty
484 //----------------------------------------------------------------------
485
486 {
487 code: ";\n\nfoo()",
488 options: [
489 { blankLine: "never", prev: "*", next: "*" },
490 { blankLine: "always", prev: "empty", next: "*" }
491 ]
492 },
493 {
494 code: "1;\nfoo()",
495 options: [
496 { blankLine: "never", prev: "*", next: "*" },
497 { blankLine: "always", prev: "empty", next: "*" }
498 ]
499 },
500
501 //----------------------------------------------------------------------
502 // expression
503 //----------------------------------------------------------------------
504
505 {
506 code: "foo()\n\nfoo()",
507 options: [
508 { blankLine: "never", prev: "*", next: "*" },
509 { blankLine: "always", prev: "expression", next: "*" }
510 ]
511 },
512 {
513 code: "a=b+c\n\nfoo()",
514 options: [
515 { blankLine: "never", prev: "*", next: "*" },
516 { blankLine: "always", prev: "expression", next: "*" }
517 ]
518 },
519 {
520 code: "var a=1\nfoo()",
521 options: [
522 { blankLine: "never", prev: "*", next: "*" },
523 { blankLine: "always", prev: "expression", next: "*" }
524 ]
525 },
526 {
527 code: "'use strict'\nfoo()",
528 options: [
529 { blankLine: "never", prev: "*", next: "*" },
530 { blankLine: "always", prev: "expression", next: "*" }
531 ]
532 },
533
534 //----------------------------------------------------------------------
535 // multiline-expression
536 //----------------------------------------------------------------------
537
538 {
539 code: "foo()\n\nfoo(\n\tx,\n\ty\n)",
540 options: [
541 { blankLine: "always", prev: "*", next: "multiline-expression" }
542 ]
543 },
544 {
545 code: "foo()\nfoo()",
546 options: [
547 { blankLine: "always", prev: "*", next: "multiline-expression" }
548 ]
549 },
550 {
551 code: "() => {\n\tsomeArray.forEach(x => doSomething(x));\n\treturn theThing;\n}",
552 options: [
553 { blankLine: "always", prev: "multiline-expression", next: "return" }
554 ]
555 },
556 {
557 code: "() => {\n\tsomeArray.forEach(\n\t\tx => doSomething(x)\n\t);\n\n\treturn theThing;\n}",
558 options: [
559 { blankLine: "always", prev: "multiline-expression", next: "return" }
560 ]
561 },
562
563 //----------------------------------------------------------------------
564 // break
565 //----------------------------------------------------------------------
566
567 {
568 code: "A:{break A\n\nfoo()}",
569 options: [
570 { blankLine: "never", prev: "*", next: "*" },
571 { blankLine: "always", prev: "break", next: "*" }
572 ]
573 },
574 {
575 code: "while(a){break\n\nfoo()}",
576 options: [
577 { blankLine: "never", prev: "*", next: "*" },
578 { blankLine: "always", prev: "break", next: "*" }
579 ]
580 },
581 {
582 code: "switch(a){case 0:break\n\nfoo()}",
583 options: [
584 { blankLine: "never", prev: "*", next: "*" },
585 { blankLine: "always", prev: "break", next: "*" }
586 ]
587 },
588 {
589 code: "switch(a){case 0:break\ncase 1:break}",
590 options: [
591 { blankLine: "never", prev: "*", next: "*" },
592 { blankLine: "always", prev: "break", next: "*" }
593 ]
594 },
595
596 //----------------------------------------------------------------------
597 // case
598 //----------------------------------------------------------------------
599
600 {
601 code: "switch(a){case 0:\nfoo()\n\ncase 1:\nfoo()}",
602 options: [
603 { blankLine: "never", prev: "*", next: "*" },
604 { blankLine: "always", prev: "case", next: "*" }
605 ]
606 },
607 {
608 code: "switch(a){case 0:\nfoo()\n\ndefault:\nfoo()}",
609 options: [
610 { blankLine: "never", prev: "*", next: "*" },
611 { blankLine: "always", prev: "case", next: "*" }
612 ]
613 },
614
615 //----------------------------------------------------------------------
616 // class
617 //----------------------------------------------------------------------
618
619 {
620 code: "class A{}\n\nfoo()",
621 options: [
622 { blankLine: "never", prev: "*", next: "*" },
623 { blankLine: "always", prev: "class", next: "*" }
624 ]
625 },
626 {
627 code: "var A = class{}\nfoo()",
628 options: [
629 { blankLine: "never", prev: "*", next: "*" },
630 { blankLine: "always", prev: "class", next: "*" }
631 ]
632 },
633
634 //----------------------------------------------------------------------
635 // const
636 //----------------------------------------------------------------------
637
638 {
639 code: "const a=1\n\nfoo()",
640 options: [
641 { blankLine: "never", prev: "*", next: "*" },
642 { blankLine: "always", prev: "const", next: "*" }
643 ]
644 },
645 {
646 code: "let a=1\nfoo()",
647 options: [
648 { blankLine: "never", prev: "*", next: "*" },
649 { blankLine: "always", prev: "const", next: "*" }
650 ]
651 },
652
653 //----------------------------------------------------------------------
654 // continue
655 //----------------------------------------------------------------------
656
657 {
658 code: "while(a){continue\n\nfoo()}",
659 options: [
660 { blankLine: "never", prev: "*", next: "*" },
661 { blankLine: "always", prev: "continue", next: "*" }
662 ]
663 },
664 {
665 code: "while(a){break\nfoo()}",
666 options: [
667 { blankLine: "never", prev: "*", next: "*" },
668 { blankLine: "always", prev: "continue", next: "*" }
669 ]
670 },
671
672 //----------------------------------------------------------------------
673 // debugger
674 //----------------------------------------------------------------------
675
676 {
677 code: "debugger\n\nfoo()",
678 options: [
679 { blankLine: "never", prev: "*", next: "*" },
680 { blankLine: "always", prev: "debugger", next: "*" }
681 ]
682 },
683
684 //----------------------------------------------------------------------
685 // default
686 //----------------------------------------------------------------------
687
688 {
689 code: "switch(a){default:\nfoo()\n\ncase 0:\nfoo()\ncase 1:}",
690 options: [
691 { blankLine: "never", prev: "*", next: "*" },
692 { blankLine: "always", prev: "default", next: "*" }
693 ]
694 },
695
696 //----------------------------------------------------------------------
697 // do
698 //----------------------------------------------------------------------
699
700 {
701 code: "do;while(a)\n\nfoo()",
702 options: [
703 { blankLine: "never", prev: "*", next: "*" },
704 { blankLine: "always", prev: "do", next: "*" }
705 ]
706 },
707 {
708 code: "while(a);\nfoo()",
709 options: [
710 { blankLine: "never", prev: "*", next: "*" },
711 { blankLine: "always", prev: "do", next: "*" }
712 ]
713 },
714
715 //----------------------------------------------------------------------
716 // export
717 //----------------------------------------------------------------------
718
719 {
720 code: "export default 1\n\nfoo()",
721 options: [
722 { blankLine: "never", prev: "*", next: "*" },
723 { blankLine: "always", prev: "export", next: "*" }
724 ],
725 parserOptions: { ecmaVersion: 6, sourceType: "module" }
726 },
727 {
728 code: "export let a=1\n\nfoo()",
729 options: [
730 { blankLine: "never", prev: "*", next: "*" },
731 { blankLine: "always", prev: "export", next: "*" }
732 ],
733 parserOptions: { ecmaVersion: 6, sourceType: "module" }
734 },
735 {
736 code: "var a = 0; export {a}\n\nfoo()",
737 options: [
738 { blankLine: "never", prev: "*", next: "*" },
739 { blankLine: "always", prev: "export", next: "*" }
740 ],
741 parserOptions: { ecmaVersion: 6, sourceType: "module" }
742 },
743 {
744 code: "exports.foo=1\nfoo()",
745 options: [
746 { blankLine: "never", prev: "*", next: "*" },
747 { blankLine: "always", prev: "export", next: "*" }
748 ],
749 parserOptions: { ecmaVersion: 6, sourceType: "module" }
750 },
751 {
752 code: "module.exports={}\nfoo()",
753 options: [
754 { blankLine: "never", prev: "*", next: "*" },
755 { blankLine: "always", prev: "export", next: "*" }
756 ],
757 parserOptions: { ecmaVersion: 6, sourceType: "module" }
758 },
759
760 //----------------------------------------------------------------------
761 // for
762 //----------------------------------------------------------------------
763
764 {
765 code: "for(;;);\n\nfoo()",
766 options: [
767 { blankLine: "never", prev: "*", next: "*" },
768 { blankLine: "always", prev: "for", next: "*" }
769 ]
770 },
771 {
772 code: "for(a in b);\n\nfoo()",
773 options: [
774 { blankLine: "never", prev: "*", next: "*" },
775 { blankLine: "always", prev: "for", next: "*" }
776 ]
777 },
778 {
779 code: "for(a of b);\n\nfoo()",
780 options: [
781 { blankLine: "never", prev: "*", next: "*" },
782 { blankLine: "always", prev: "for", next: "*" }
783 ]
784 },
785 {
786 code: "while(a);\nfoo()",
787 options: [
788 { blankLine: "never", prev: "*", next: "*" },
789 { blankLine: "always", prev: "for", next: "*" }
790 ]
791 },
792
793 //----------------------------------------------------------------------
794 // function
795 //----------------------------------------------------------------------
796
797 {
798 code: "function foo(){}\n\nfoo()",
799 options: [
800 { blankLine: "never", prev: "*", next: "*" },
801 { blankLine: "always", prev: "function", next: "*" }
802 ]
803 },
804 {
805 code: "var foo=function(){}\nfoo()",
806 options: [
807 { blankLine: "never", prev: "*", next: "*" },
808 { blankLine: "always", prev: "function", next: "*" }
809 ]
810 },
811 {
812 code: "async function foo(){}\n\nfoo()",
813 options: [
814 { blankLine: "never", prev: "*", next: "*" },
815 { blankLine: "always", prev: "function", next: "*" }
816 ]
817 },
818
819 //----------------------------------------------------------------------
820 // if
821 //----------------------------------------------------------------------
822
823 {
824 code: "if(a);\n\nfoo()",
825 options: [
826 { blankLine: "never", prev: "*", next: "*" },
827 { blankLine: "always", prev: "if", next: "*" }
828 ]
829 },
830 {
831 code: "if(a);else;\n\nfoo()",
832 options: [
833 { blankLine: "never", prev: "*", next: "*" },
834 { blankLine: "always", prev: "if", next: "*" }
835 ]
836 },
837 {
838 code: "if(a);else if(b);else;\n\nfoo()",
839 options: [
840 { blankLine: "never", prev: "*", next: "*" },
841 { blankLine: "always", prev: "if", next: "*" }
842 ]
843 },
844 {
845 code: "for(;;);\nfoo()",
846 options: [
847 { blankLine: "never", prev: "*", next: "*" },
848 { blankLine: "always", prev: "if", next: "*" }
849 ]
850 },
851
852 //----------------------------------------------------------------------
853 // iife
854 //----------------------------------------------------------------------
855
856 {
857 code: "(function(){\n})()\n\nvar a = 2;",
858 options: [
859 { blankLine: "always", prev: "iife", next: "*" }
860 ]
861 },
862 {
863 code: "+(function(){\n})()\n\nvar a = 2;",
864 options: [
865 { blankLine: "always", prev: "iife", next: "*" }
866 ]
867 },
868 {
869 code: "(function(){\n})()\nvar a = 2;",
870 options: [
871 { blankLine: "never", prev: "iife", next: "*" }
872 ]
873 },
874 {
875 code: "+(function(){\n})()\nvar a = 2;",
876 options: [
877 { blankLine: "never", prev: "iife", next: "*" }
878 ]
879 },
880
881 //----------------------------------------------------------------------
882 // import
883 //----------------------------------------------------------------------
884
885 {
886 code: "import 'a'\n\nfoo()",
887 options: [
888 { blankLine: "never", prev: "*", next: "*" },
889 { blankLine: "always", prev: "import", next: "*" }
890 ],
891 parserOptions: { ecmaVersion: 6, sourceType: "module" }
892 },
893 {
894 code: "import a from 'a'\n\nfoo()",
895 options: [
896 { blankLine: "never", prev: "*", next: "*" },
897 { blankLine: "always", prev: "import", next: "*" }
898 ],
899 parserOptions: { ecmaVersion: 6, sourceType: "module" }
900 },
901 {
902 code: "import * as a from 'a'\n\nfoo()",
903 options: [
904 { blankLine: "never", prev: "*", next: "*" },
905 { blankLine: "always", prev: "import", next: "*" }
906 ],
907 parserOptions: { ecmaVersion: 6, sourceType: "module" }
908 },
909 {
910 code: "import {a} from 'a'\n\nfoo()",
911 options: [
912 { blankLine: "never", prev: "*", next: "*" },
913 { blankLine: "always", prev: "import", next: "*" }
914 ],
915 parserOptions: { ecmaVersion: 6, sourceType: "module" }
916 },
917 {
918 code: "const a=require('a')\nfoo()",
919 options: [
920 { blankLine: "never", prev: "*", next: "*" },
921 { blankLine: "always", prev: "import", next: "*" }
922 ],
923 parserOptions: { ecmaVersion: 6, sourceType: "module" }
924 },
925
926 //----------------------------------------------------------------------
927 // let
928 //----------------------------------------------------------------------
929
930 {
931 code: "let a=1\n\nfoo()",
932 options: [
933 { blankLine: "never", prev: "*", next: "*" },
934 { blankLine: "always", prev: "let", next: "*" }
935 ]
936 },
937 {
938 code: "var a=1\nfoo()",
939 options: [
940 { blankLine: "never", prev: "*", next: "*" },
941 { blankLine: "always", prev: "let", next: "*" }
942 ]
943 },
944
945 //----------------------------------------------------------------------
946 // return
947 //----------------------------------------------------------------------
948
949 {
950 code: "function foo(){return\n\nfoo()}",
951 options: [
952 { blankLine: "never", prev: "*", next: "*" },
953 { blankLine: "always", prev: "return", next: "*" }
954 ]
955 },
956 {
957 code: "throw a\nfoo()",
958 options: [
959 { blankLine: "never", prev: "*", next: "*" },
960 { blankLine: "always", prev: "return", next: "*" }
961 ]
962 },
963
964 //----------------------------------------------------------------------
965 // switch
966 //----------------------------------------------------------------------
967
968 {
969 code: "switch(a){}\n\nfoo()",
970 options: [
971 { blankLine: "never", prev: "*", next: "*" },
972 { blankLine: "always", prev: "switch", next: "*" }
973 ]
974 },
975 {
976 code: "if(a){}\nfoo()",
977 options: [
978 { blankLine: "never", prev: "*", next: "*" },
979 { blankLine: "always", prev: "switch", next: "*" }
980 ]
981 },
982
983 //----------------------------------------------------------------------
984 // throw
985 //----------------------------------------------------------------------
986
987 {
988 code: "throw a\n\nfoo()",
989 options: [
990 { blankLine: "never", prev: "*", next: "*" },
991 { blankLine: "always", prev: "throw", next: "*" }
992 ]
993 },
994
995 //----------------------------------------------------------------------
996 // try
997 //----------------------------------------------------------------------
998
999 {
1000 code: "try{}catch(e){}\n\nfoo()",
1001 options: [
1002 { blankLine: "never", prev: "*", next: "*" },
1003 { blankLine: "always", prev: "try", next: "*" }
1004 ]
1005 },
1006 {
1007 code: "try{}finally{}\n\nfoo()",
1008 options: [
1009 { blankLine: "never", prev: "*", next: "*" },
1010 { blankLine: "always", prev: "try", next: "*" }
1011 ]
1012 },
1013 {
1014 code: "try{}catch(e){}finally{}\n\nfoo()",
1015 options: [
1016 { blankLine: "never", prev: "*", next: "*" },
1017 { blankLine: "always", prev: "try", next: "*" }
1018 ]
1019 },
1020
1021 //----------------------------------------------------------------------
1022 // var
1023 //----------------------------------------------------------------------
1024
1025 {
1026 code: "var a=1\n\nfoo()",
1027 options: [
1028 { blankLine: "never", prev: "*", next: "*" },
1029 { blankLine: "always", prev: "var", next: "*" }
1030 ]
1031 },
1032 {
1033 code: "const a=1\nfoo()",
1034 options: [
1035 { blankLine: "never", prev: "*", next: "*" },
1036 { blankLine: "always", prev: "var", next: "*" }
1037 ]
1038 },
1039
1040 //----------------------------------------------------------------------
1041 // while
1042 //----------------------------------------------------------------------
1043
1044 {
1045 code: "while(a);\n\nfoo()",
1046 options: [
1047 { blankLine: "never", prev: "*", next: "*" },
1048 { blankLine: "always", prev: "while", next: "*" }
1049 ]
1050 },
1051 {
1052 code: "do;while(a)\nfoo()",
1053 options: [
1054 { blankLine: "never", prev: "*", next: "*" },
1055 { blankLine: "always", prev: "while", next: "*" }
1056 ]
1057 },
1058
1059 //----------------------------------------------------------------------
1060 // with
1061 //----------------------------------------------------------------------
1062
1063 {
1064 code: "with(a);\n\nfoo()",
1065 options: [
1066 { blankLine: "never", prev: "*", next: "*" },
1067 { blankLine: "always", prev: "with", next: "*" }
1068 ]
1069 },
1070
1071 //----------------------------------------------------------------------
1072 // multiline-const
1073 //----------------------------------------------------------------------
1074
1075 {
1076 code: "const a={\nb:1,\nc:2\n}\n\nconst d=3",
1077 options: [
1078 { blankLine: "never", prev: "*", next: "*" },
1079 { blankLine: "always", prev: "multiline-const", next: "*" }
1080 ]
1081 },
1082 {
1083 code: "const a=1\n\nconst b={\nc:2,\nd:3\n}",
1084 options: [
1085 { blankLine: "never", prev: "*", next: "*" },
1086 { blankLine: "always", prev: "*", next: "multiline-const" }
1087 ]
1088 },
1089 {
1090 code: "const a=1\nconst b=2",
1091 options: [
1092 { blankLine: "never", prev: "*", next: "*" },
1093 { blankLine: "always", prev: "multiline-const", next: "*" }
1094 ]
1095 },
1096 {
1097 code: "const a=1\nconst b=2",
1098 options: [
1099 { blankLine: "never", prev: "*", next: "*" },
1100 { blankLine: "always", prev: "*", next: "multiline-const" }
1101 ]
1102 },
1103
1104 //----------------------------------------------------------------------
1105 // multiline-let
1106 //----------------------------------------------------------------------
1107
1108 {
1109 code: "let a={\nb:1,\nc:2\n}\n\nlet d=3",
1110 options: [
1111 { blankLine: "never", prev: "*", next: "*" },
1112 { blankLine: "always", prev: "multiline-let", next: "*" }
1113 ]
1114 },
1115 {
1116 code: "let a=1\n\nlet b={\nc:2,\nd:3\n}",
1117 options: [
1118 { blankLine: "never", prev: "*", next: "*" },
1119 { blankLine: "always", prev: "*", next: "multiline-let" }
1120 ]
1121 },
1122 {
1123 code: "let a=1\nlet b=2",
1124 options: [
1125 { blankLine: "never", prev: "*", next: "*" },
1126 { blankLine: "always", prev: "multiline-let", next: "*" }
1127 ]
1128 },
1129 {
1130 code: "let a=1\nlet b=2",
1131 options: [
1132 { blankLine: "never", prev: "*", next: "*" },
1133 { blankLine: "always", prev: "*", next: "multiline-let" }
1134 ]
1135 },
1136
1137 //----------------------------------------------------------------------
1138 // multiline-var
1139 //----------------------------------------------------------------------
1140
1141 {
1142 code: "var a={\nb:1,\nc:2\n}\n\nvar d=3",
1143 options: [
1144 { blankLine: "never", prev: "*", next: "*" },
1145 { blankLine: "always", prev: "multiline-var", next: "*" }
1146 ]
1147 },
1148 {
1149 code: "var a=1\n\nvar b={\nc:2,\nd:3\n}",
1150 options: [
1151 { blankLine: "never", prev: "*", next: "*" },
1152 { blankLine: "always", prev: "*", next: "multiline-var" }
1153 ]
1154 },
1155 {
1156 code: "var a=1\nvar b=2",
1157 options: [
1158 { blankLine: "never", prev: "*", next: "*" },
1159 { blankLine: "always", prev: "multiline-var", next: "*" }
1160 ]
1161 },
1162 {
1163 code: "var a=1\nvar b=2",
1164 options: [
1165 { blankLine: "never", prev: "*", next: "*" },
1166 { blankLine: "always", prev: "*", next: "multiline-var" }
1167 ]
1168 },
1169
1170 //----------------------------------------------------------------------
1171 // singleline-const
1172 //----------------------------------------------------------------------
1173
1174 {
1175 code: "const a=1\n\nconst b=2",
1176 options: [
1177 { blankLine: "never", prev: "*", next: "*" },
1178 { blankLine: "always", prev: "singleline-const", next: "*" }
1179 ]
1180 },
1181 {
1182 code: "const a=1\n\nconst b=2",
1183 options: [
1184 { blankLine: "never", prev: "*", next: "*" },
1185 { blankLine: "always", prev: "*", next: "singleline-const" }
1186 ]
1187 },
1188 {
1189 code: "const a={\nb:1,\nc:2\n}\nconst d={\ne:3,\nf:4\n}",
1190 options: [
1191 { blankLine: "never", prev: "*", next: "*" },
1192 { blankLine: "always", prev: "singleline-const", next: "*" }
1193 ]
1194 },
1195 {
1196 code: "const a={\nb:1,\nc:2\n}\nconst d={\ne:3,\nf:4\n}",
1197 options: [
1198 { blankLine: "never", prev: "*", next: "*" },
1199 { blankLine: "always", prev: "*", next: "singleline-const" }
1200 ]
1201 },
1202
1203 //----------------------------------------------------------------------
1204 // singleline-let
1205 //----------------------------------------------------------------------
1206
1207 {
1208 code: "let a=1\n\nlet b=2",
1209 options: [
1210 { blankLine: "never", prev: "*", next: "*" },
1211 { blankLine: "always", prev: "singleline-let", next: "*" }
1212 ]
1213 },
1214 {
1215 code: "let a=1\n\nlet b=2",
1216 options: [
1217 { blankLine: "never", prev: "*", next: "*" },
1218 { blankLine: "always", prev: "*", next: "singleline-let" }
1219 ]
1220 },
1221 {
1222 code: "let a={\nb:1,\nc:2\n}\nlet d={\ne:3,\nf:4\n}",
1223 options: [
1224 { blankLine: "never", prev: "*", next: "*" },
1225 { blankLine: "always", prev: "singleline-let", next: "*" }
1226 ]
1227 },
1228 {
1229 code: "let a={\nb:1,\nc:2\n}\nlet d={\ne:3,\nf:4\n}",
1230 options: [
1231 { blankLine: "never", prev: "*", next: "*" },
1232 { blankLine: "always", prev: "*", next: "singleline-let" }
1233 ]
1234 },
1235
1236 //----------------------------------------------------------------------
1237 // singleline-var
1238 //----------------------------------------------------------------------
1239
1240 {
1241 code: "var a=1\n\nvar b=2",
1242 options: [
1243 { blankLine: "never", prev: "*", next: "*" },
1244 { blankLine: "always", prev: "singleline-var", next: "*" }
1245 ]
1246 },
1247 {
1248 code: "var a=1\n\nvar b=2",
1249 options: [
1250 { blankLine: "never", prev: "*", next: "*" },
1251 { blankLine: "always", prev: "*", next: "singleline-var" }
1252 ]
1253 },
1254 {
1255 code: "var a={\nb:1,\nc:2\n}\nvar d={\ne:3,\nf:4\n}",
1256 options: [
1257 { blankLine: "never", prev: "*", next: "*" },
1258 { blankLine: "always", prev: "singleline-var", next: "*" }
1259 ]
1260 },
1261 {
1262 code: "var a={\nb:1,\nc:2\n}\nvar d={\ne:3,\nf:4\n}",
1263 options: [
1264 { blankLine: "never", prev: "*", next: "*" },
1265 { blankLine: "always", prev: "*", next: "singleline-var" }
1266 ]
1267 },
1268
1269 //----------------------------------------------------------------------
1270 // Tests from newline-after-var
1271 //----------------------------------------------------------------------
1272
1273 // should skip rule entirely
1274 {
1275 code: "console.log(greet);",
1276 options: [
1277 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1278 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1279 ]
1280 },
1281 {
1282 code: "console.log(greet);",
1283 options: [
1284 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1285 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1286 ]
1287 },
1288
1289 // should ignore a `var` with no following token
1290 {
1291 code: "var greet = 'hello';",
1292 options: [
1293 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1294 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1295 ]
1296 },
1297 {
1298 code: "var greet = 'hello';",
1299 options: [
1300 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1301 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1302 ]
1303 },
1304
1305 // should allow no line break in "never" mode
1306 {
1307 code: "var greet = 'hello';console.log(greet);",
1308 options: [
1309 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1310 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1311 ]
1312 },
1313
1314 // should allow no blank line in "never" mode
1315 {
1316 code: "var greet = 'hello';\nconsole.log(greet);",
1317 options: [
1318 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1319 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1320 ]
1321 },
1322
1323 // should allow one blank line in "always" mode
1324 {
1325 code: "var greet = 'hello';\n\nconsole.log(greet);",
1326 options: [
1327 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1328 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1329 ]
1330 },
1331
1332 // should allow two or more blank lines in "always" mode
1333 {
1334 code: "var greet = 'hello';\n\n\nconsole.log(greet);",
1335 options: [
1336 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1337 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1338 ]
1339 },
1340 {
1341 code: "var greet = 'hello';\n\n\n\nconsole.log(greet);",
1342 options: [
1343 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1344 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1345 ]
1346 },
1347
1348 // should allow trailing whitespace after the `var`
1349 {
1350 code: "var greet = 'hello'; \n\nconsole.log(greet);",
1351 options: [
1352 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1353 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1354 ]
1355 },
1356 {
1357 code: "var greet = 'hello'; \nconsole.log(greet);",
1358 options: [
1359 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1360 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1361 ]
1362 },
1363
1364 // should allow inline comments after the `var`
1365 {
1366 code: "var greet = 'hello'; // inline comment\n\nconsole.log(greet);",
1367 options: [
1368 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1369 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1370 ]
1371 },
1372 {
1373 code: "var greet = 'hello'; // inline comment\nconsole.log(greet);",
1374 options: [
1375 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1376 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1377 ]
1378 },
1379
1380 // should allow a comment on the next line in "never" mode
1381 {
1382 code: "var greet = 'hello';\n// next-line comment\nconsole.log(greet);",
1383 options: [
1384 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1385 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1386 ]
1387 },
1388 {
1389 code: "var greet = 'hello';\n/* block comment\nblock comment */\nconsole.log(greet);",
1390 options: [
1391 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1392 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1393 ]
1394 },
1395
1396 // should allow comments on the next line followed by a blank in "always" mode
1397 {
1398 code: "var greet = 'hello';\n// next-line comment\n\nconsole.log(greet);",
1399 options: [
1400 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1401 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1402 ]
1403 },
1404 {
1405 code: "var greet = 'hello';\n/* block comment\nblock comment */\n\nconsole.log(greet);",
1406 options: [
1407 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1408 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1409 ]
1410 },
1411 {
1412 code: "var greet = 'hello';\n// next-line comment\n// second-line comment\n\nconsole.log(greet);",
1413 options: [
1414 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1415 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1416 ]
1417 },
1418
1419 // should allow comments on the next line followed by no blank in "never" mode
1420 {
1421 code: "var greet = 'hello';\n// next-line comment\n// second-line comment\nconsole.log(greet);",
1422 options: [
1423 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1424 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1425 ]
1426 },
1427 {
1428 code: "var greet = 'hello';\n// next-line comment\n/* block comment\nblock comment */\nconsole.log(greet);",
1429 options: [
1430 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1431 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1432 ]
1433 },
1434
1435 // should allow another `var` statement to follow without blank line
1436 {
1437 code: "var greet = 'hello';var name = 'world';console.log(greet, name);",
1438 options: [
1439 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1440 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1441 ]
1442 },
1443 {
1444 code: "var greet = 'hello';\nvar name = 'world';\nconsole.log(greet, name);",
1445 options: [
1446 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1447 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1448 ]
1449 },
1450 {
1451 code: "var greet = 'hello';\nvar name = 'world';\n\nconsole.log(greet, name);",
1452 options: [
1453 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1454 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1455 ]
1456 },
1457
1458 // should allow a comment directly between `var` statements
1459 {
1460 code: "var greet = 'hello';\n// inline comment\nvar name = 'world';\n\nconsole.log(greet, name);",
1461 options: [
1462 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1463 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1464 ]
1465 },
1466 {
1467 code: "var greet = 'hello';\n/* block comment\nblock comment */\nvar name = 'world';\n\nconsole.log(greet, name);",
1468 options: [
1469 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1470 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1471 ]
1472 },
1473 {
1474 code: "var greet = 'hello';\n// inline comment\nvar name = 'world';\nconsole.log(greet, name);",
1475 options: [
1476 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1477 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1478 ]
1479 },
1480 {
1481 code: "var greet = 'hello';\n/* block comment\nblock comment */\nvar name = 'world';\nconsole.log(greet, name);",
1482 options: [
1483 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1484 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1485 ]
1486 },
1487
1488 // should handle single `var` statement with multiple declarations
1489 {
1490 code: "var greet = 'hello', name = 'world';console.log(greet, name);",
1491 options: [
1492 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1493 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1494 ]
1495 },
1496 {
1497 code: "var greet = 'hello', name = 'world';\nconsole.log(greet, name);",
1498 options: [
1499 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1500 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1501 ]
1502 },
1503 {
1504 code: "var greet = 'hello', name = 'world';\n\nconsole.log(greet, name);",
1505 options: [
1506 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1507 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1508 ]
1509 },
1510
1511 // should handle single `var` statement with multi-line declaration
1512 {
1513 code: "var greet = 'hello',\nname = 'world';\n\nconsole.log(greet, name);",
1514 options: [
1515 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1516 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1517 ]
1518 },
1519 {
1520 code: "var greet = 'hello',\nname = 'world';\nconsole.log(greet, name);",
1521 options: [
1522 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1523 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1524 ]
1525 },
1526 {
1527 code: "var greet = 'hello', // inline comment\nname = 'world'; // inline comment\n\nconsole.log(greet, name);",
1528 options: [
1529 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1530 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1531 ]
1532 },
1533 {
1534 code: "var greet = 'hello', // inline comment\nname = 'world'; // inline comment\nconsole.log(greet, name);",
1535 options: [
1536 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1537 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1538 ]
1539 },
1540 {
1541 code: "var greet = 'hello',\nname = 'world';\n// next-line comment\nconsole.log(greet);",
1542 options: [
1543 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1544 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1545 ]
1546 },
1547 {
1548 code: "var greet = 'hello',\nname = 'world';\n/* block comment\nblock comment */\nconsole.log(greet);",
1549 options: [
1550 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1551 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1552 ]
1553 },
1554
1555 // should handle ES6 `let` block binding
1556 {
1557 code: "let greet = 'hello';\n\nconsole.log(greet);",
1558 options: [
1559 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1560 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1561 ]
1562 },
1563 {
1564 code: "let greet = 'hello';\nconsole.log(greet);",
1565 options: [
1566 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1567 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1568 ]
1569 },
1570
1571 // should handle ES6 `const` block binding
1572 {
1573 code: "const greet = 'hello';\n\nconsole.log(greet);",
1574 options: [
1575 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1576 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1577 ]
1578 },
1579 {
1580 code: "const greet = 'hello';\nconsole.log(greet);",
1581 options: [
1582 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1583 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1584 ]
1585 },
1586
1587 // should handle a mix of `var`, `let`, or `const`
1588 {
1589 code: "let greet = 'hello';\nvar name = 'world';\n\nconsole.log(greet, name);",
1590 options: [
1591 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1592 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1593 ]
1594 },
1595 {
1596 code: "const greet = 'hello';\nvar name = 'world';\n\nconsole.log(greet, name);",
1597 options: [
1598 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1599 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1600 ]
1601 },
1602 {
1603 code: "let greet = 'hello';\nconst name = 'world';\n\nconsole.log(greet, name);",
1604 options: [
1605 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1606 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1607 ]
1608 },
1609
1610 // should handle a mix of `var` or `let` inside for variations
1611 {
1612 code: "for(let a = 1; a < 1; a++){\n break;\n}",
1613 options: [
1614 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1615 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1616 ]
1617 },
1618 {
1619 code: "for(var a = 1; a < 1; a++){\n break;\n}",
1620 options: [
1621 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1622 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1623 ]
1624 },
1625 {
1626 code: "for(let a = 1; a < 1; a++){\n break;\n}",
1627 options: [
1628 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1629 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1630 ]
1631 },
1632 {
1633 code: "for(var a = 1; a < 1; a++){\n break;\n}",
1634 options: [
1635 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1636 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1637 ]
1638 },
1639 {
1640 code: "for(let a in obj){\n break;\n}",
1641 options: [
1642 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1643 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1644 ]
1645 },
1646 {
1647 code: "for(var a in obj){\n break;\n}",
1648 options: [
1649 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1650 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1651 ]
1652 },
1653 {
1654 code: "for(let a in obj){\n break;\n}",
1655 options: [
1656 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1657 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1658 ]
1659 },
1660 {
1661 code: "for(var a in obj){\n break;\n}",
1662 options: [
1663 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1664 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1665 ]
1666 },
1667
1668 // should handle export specifiers
1669 {
1670 code: "export let a = 1;\nexport let b = 2;",
1671 options: [
1672 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1673 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1674 ],
1675 parserOptions: { ecmaVersion: 6, sourceType: "module" }
1676 },
1677 {
1678 code: "export let a = 1;\nexport let b = 2;",
1679 options: [
1680 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1681 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1682 ],
1683 parserOptions: { ecmaVersion: 6, sourceType: "module" }
1684 },
1685 {
1686 code: "export var a = 1;\nexport var b = 2;",
1687 options: [
1688 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1689 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1690 ],
1691 parserOptions: { ecmaVersion: 6, sourceType: "module" }
1692 },
1693 {
1694 code: "export var a = 1;\nexport var b = 2;",
1695 options: [
1696 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1697 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1698 ],
1699 parserOptions: { ecmaVersion: 6, sourceType: "module" }
1700 },
1701 {
1702 code: "export const a = 1;\nexport const b = 2;",
1703 options: [
1704 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1705 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1706 ],
1707 parserOptions: { ecmaVersion: 6, sourceType: "module" }
1708 },
1709 {
1710 code: "export const a = 1;\nexport const b = 2;",
1711 options: [
1712 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1713 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1714 ],
1715 parserOptions: { ecmaVersion: 6, sourceType: "module" }
1716 },
1717
1718 // should allow no blank line at end of block
1719 {
1720 code: "function example() {\nvar greet = 'hello'\n}",
1721 options: [
1722 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1723 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1724 ]
1725 },
1726 {
1727 code: "function example() {\nvar greet = 'hello'\n}",
1728 options: [
1729 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1730 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1731 ]
1732 },
1733 {
1734 code: "function example() {\nvar greet = 'hello';\nconsole.log(greet);\n}",
1735 options: [
1736 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1737 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1738 ]
1739 },
1740 {
1741 code: "var f = function() {\nvar greet = 'hello'\n};",
1742 options: [
1743 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1744 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1745 ]
1746 },
1747 {
1748 code: "var f = function() {\nvar greet = 'hello'\n};",
1749 options: [
1750 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1751 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1752 ]
1753 },
1754 {
1755 code: "var f = function() {\nvar greet = 'hello';\nconsole.log(greet);\n};",
1756 options: [
1757 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1758 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1759 ]
1760 },
1761 {
1762 code: "() => {\nvar greet = 'hello';\n}",
1763 options: [
1764 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1765 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1766 ]
1767 },
1768 {
1769 code: "() => {\nvar greet = 'hello';\n}",
1770 options: [
1771 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1772 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1773 ]
1774 },
1775 {
1776 code: "() => {\nvar greet = 'hello';\nconsole.log(greet);\n}",
1777 options: [
1778 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1779 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1780 ]
1781 },
1782 {
1783 code: "{\nvar foo;\n}",
1784 options: [
1785 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1786 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1787 ]
1788 },
1789 {
1790 code: "{\nvar foo;\n}",
1791 options: [
1792 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1793 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1794 ]
1795 },
1796 {
1797 code: "if(true) {\nvar foo;\n}",
1798 options: [
1799 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1800 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1801 ]
1802 },
1803 {
1804 code: "if(true) {\nvar foo;\n}",
1805 options: [
1806 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1807 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1808 ]
1809 },
1810 {
1811 code: "switch(a) {\ncase 0:\nvar foo;\n}",
1812 options: [
1813 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1814 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1815 ]
1816 },
1817 {
1818 code: "switch(a) {\ncase 0:\nvar foo;\n}",
1819 options: [
1820 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1821 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1822 ]
1823 },
1824
1825 // should handle one/no blank before case.
1826 {
1827 code: "switch(a) {\ncase 0:\nvar foo;\n\ncase 1:}",
1828 options: [
1829 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1830 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1831 ]
1832 },
1833 {
1834 code: "switch(a) {\ncase 0:\nvar foo;\ncase 1:}",
1835 options: [
1836 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1837 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1838 ]
1839 },
1840
1841 // https://github.com/eslint/eslint/issues/6834
1842 {
1843 code: `
1844 var a = 1
1845
1846 ;(b || c).doSomething()
1847 `,
1848 options: [
1849 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1850 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1851 ]
1852 },
1853 {
1854 code: `
1855 var a = 1
1856 ;(b || c).doSomething()
1857 `,
1858 options: [
1859 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1860 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1861 ]
1862 },
1863 {
1864 code: `
1865 var a = 1
1866 ;
1867 (b || c).doSomething();
1868 `,
1869 options: [
1870 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1871 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1872 ]
1873 },
1874
1875 {
1876 code: "switch(a) {\ncase 0:\nvar foo;\n\ncase 1:}",
1877 options: [
1878 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1879 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1880 ]
1881 },
1882 {
1883 code: "switch(a) {\ncase 0:\nvar foo;\ncase 1:}",
1884 options: [
1885 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
1886 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1887 ]
1888 },
1889 {
1890 code: `
1891 var a = 1
1892
1893 ;
1894 (b || c).doSomething();
1895 `,
1896 options: [
1897 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
1898 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
1899 ]
1900 },
1901
1902 //----------------------------------------------------------------------
1903 // Tests from newline-before-return
1904 //----------------------------------------------------------------------
1905
1906 {
1907 code: "function a() {\nreturn;\n}",
1908 options: [
1909 { blankLine: "always", prev: "*", next: "return" }
1910 ]
1911 },
1912 {
1913 code: "function a() {\n\nreturn;\n}",
1914 options: [
1915 { blankLine: "always", prev: "*", next: "return" }
1916 ]
1917 },
1918 {
1919 code: "function a() {\nvar b;\n\nreturn;\n}",
1920 options: [
1921 { blankLine: "always", prev: "*", next: "return" }
1922 ]
1923 },
1924 {
1925 code: "function a() {\nif (b) return;\n}",
1926 options: [
1927 { blankLine: "always", prev: "*", next: "return" }
1928 ]
1929 },
1930 {
1931 code: "function a() {\nif (b) { return; }\n}",
1932 options: [
1933 { blankLine: "always", prev: "*", next: "return" }
1934 ]
1935 },
1936 {
1937 code: "function a() {\nif (b) {\nreturn;\n}\n}",
1938 options: [
1939 { blankLine: "always", prev: "*", next: "return" }
1940 ]
1941 },
1942 {
1943 code: "function a() {\nif (b) {\n\nreturn;\n}\n}",
1944 options: [
1945 { blankLine: "always", prev: "*", next: "return" }
1946 ]
1947 },
1948 {
1949 code: "function a() {\nif (b) {\nreturn;\n}\n\nreturn c;\n}",
1950 options: [
1951 { blankLine: "always", prev: "*", next: "return" }
1952 ]
1953 },
1954 {
1955 code: "function a() {\nif (b) {\n\nreturn;\n}\n\nreturn c;\n}",
1956 options: [
1957 { blankLine: "always", prev: "*", next: "return" }
1958 ]
1959 },
1960 {
1961 code: "function a() {\nif (!b) {\nreturn;\n} else {\nreturn b;\n}\n}",
1962 options: [
1963 { blankLine: "always", prev: "*", next: "return" }
1964 ]
1965 },
1966 {
1967 code: "function a() {\nif (!b) {\nreturn;\n} else {\n\nreturn b;\n}\n}",
1968 options: [
1969 { blankLine: "always", prev: "*", next: "return" }
1970 ]
1971 },
1972 {
1973 code: "function a() {\nif (b) {\nreturn b;\n} else if (c) {\nreturn c;\n}\n}",
1974 options: [
1975 { blankLine: "always", prev: "*", next: "return" }
1976 ]
1977 },
1978 {
1979 code: "function a() {\nif (b) {\nreturn b;\n} else if (c) {\nreturn c;\n} else {\nreturn d;\n}\n}",
1980 options: [
1981 { blankLine: "always", prev: "*", next: "return" }
1982 ]
1983 },
1984 {
1985 code: "function a() {\nif (b) {\nreturn b;\n} else if (c) {\nreturn c;\n} else {\nreturn d;\n}\n\nreturn a;\n}",
1986 options: [
1987 { blankLine: "always", prev: "*", next: "return" }
1988 ]
1989 },
1990 {
1991 code: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse return d;\n}",
1992 options: [
1993 { blankLine: "always", prev: "*", next: "return" }
1994 ]
1995 },
1996 {
1997 code: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\nreturn d;\n}\n}",
1998 options: [
1999 { blankLine: "always", prev: "*", next: "return" }
2000 ]
2001 },
2002 {
2003 code: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\ne();\n\nreturn d;\n}\n}",
2004 options: [
2005 { blankLine: "always", prev: "*", next: "return" }
2006 ]
2007 },
2008 {
2009 code: "function a() {\nwhile (b) return;\n}",
2010 options: [
2011 { blankLine: "always", prev: "*", next: "return" }
2012 ]
2013 },
2014 {
2015 code: "function a() {\n while (b) \nreturn;\n}",
2016 options: [
2017 { blankLine: "always", prev: "*", next: "return" }
2018 ]
2019 },
2020 {
2021 code: "function a() {\n while (b) { return; }\n}",
2022 options: [
2023 { blankLine: "always", prev: "*", next: "return" }
2024 ]
2025 },
2026 {
2027 code: "function a() {\n while (b) {\nreturn;\n}\n}",
2028 options: [
2029 { blankLine: "always", prev: "*", next: "return" }
2030 ]
2031 },
2032 {
2033 code: "function a() {\n while (b) {\nc();\n\nreturn;\n}\n}",
2034 options: [
2035 { blankLine: "always", prev: "*", next: "return" }
2036 ]
2037 },
2038 {
2039 code: "function a() {\nvar c;\nwhile (b) {\n c = d; //comment\n}\n\nreturn c;\n}",
2040 options: [
2041 { blankLine: "always", prev: "*", next: "return" }
2042 ]
2043 },
2044 {
2045 code: "function a() {\ndo return;\nwhile (b);\n}",
2046 options: [
2047 { blankLine: "always", prev: "*", next: "return" }
2048 ]
2049 },
2050 {
2051 code: "function a() {\ndo \nreturn;\nwhile (b);\n}",
2052 options: [
2053 { blankLine: "always", prev: "*", next: "return" }
2054 ]
2055 },
2056 {
2057 code: "function a() {\ndo { return; } while (b);\n}",
2058 options: [
2059 { blankLine: "always", prev: "*", next: "return" }
2060 ]
2061 },
2062 {
2063 code: "function a() {\ndo { return; }\nwhile (b);\n}",
2064 options: [
2065 { blankLine: "always", prev: "*", next: "return" }
2066 ]
2067 },
2068 {
2069 code: "function a() {\ndo {\nreturn;\n} while (b);\n}",
2070 options: [
2071 { blankLine: "always", prev: "*", next: "return" }
2072 ]
2073 },
2074 {
2075 code: "function a() {\ndo {\nc();\n\nreturn;\n} while (b);\n}",
2076 options: [
2077 { blankLine: "always", prev: "*", next: "return" }
2078 ]
2079 },
2080 {
2081 code: "function a() {\nfor (var b; b < c; b++) return;\n}",
2082 options: [
2083 { blankLine: "always", prev: "*", next: "return" }
2084 ]
2085 },
2086 {
2087 code: "function a() {\nfor (var b; b < c; b++)\nreturn;\n}",
2088 options: [
2089 { blankLine: "always", prev: "*", next: "return" }
2090 ]
2091 },
2092 {
2093 code: "function a() {\nfor (var b; b < c; b++) {\nreturn;\n}\n}",
2094 options: [
2095 { blankLine: "always", prev: "*", next: "return" }
2096 ]
2097 },
2098 {
2099 code: "function a() {\nfor (var b; b < c; b++) {\nc();\n\nreturn;\n}\n}",
2100 options: [
2101 { blankLine: "always", prev: "*", next: "return" }
2102 ]
2103 },
2104 {
2105 code: "function a() {\nfor (var b; b < c; b++) {\nif (d) {\nbreak; //comment\n}\n\nreturn;\n}\n}",
2106 options: [
2107 { blankLine: "always", prev: "*", next: "return" }
2108 ]
2109 },
2110 {
2111 code: "function a() {\nfor (b in c)\nreturn;\n}",
2112 options: [
2113 { blankLine: "always", prev: "*", next: "return" }
2114 ]
2115 },
2116 {
2117 code: "function a() {\nfor (b in c) { return; }\n}",
2118 options: [
2119 { blankLine: "always", prev: "*", next: "return" }
2120 ]
2121 },
2122 {
2123 code: "function a() {\nfor (b in c) {\nreturn;\n}\n}",
2124 options: [
2125 { blankLine: "always", prev: "*", next: "return" }
2126 ]
2127 },
2128 {
2129 code: "function a() {\nfor (b in c) {\nd();\n\nreturn;\n}\n}",
2130 options: [
2131 { blankLine: "always", prev: "*", next: "return" }
2132 ]
2133 },
2134 {
2135 code: "function a() {\nfor (b of c) return;\n}",
2136 options: [
2137 { blankLine: "always", prev: "*", next: "return" }
2138 ]
2139 },
2140 {
2141 code: "function a() {\nfor (b of c)\nreturn;\n}",
2142 options: [
2143 { blankLine: "always", prev: "*", next: "return" }
2144 ]
2145 },
2146 {
2147 code: "function a() {\nfor (b of c) {\nreturn;\n}\n}",
2148 options: [
2149 { blankLine: "always", prev: "*", next: "return" }
2150 ]
2151 },
2152 {
2153 code: "function a() {\nfor (b of c) {\nd();\n\nreturn;\n}\n}",
2154 options: [
2155 { blankLine: "always", prev: "*", next: "return" }
2156 ]
2157 },
2158 {
2159 code: "function a() {\nswitch (b) {\ncase 'b': return;\n}\n}",
2160 options: [
2161 { blankLine: "always", prev: "*", next: "return" }
2162 ]
2163 },
2164 {
2165 code: "function a() {\nswitch (b) {\ncase 'b':\nreturn;\n}\n}",
2166 options: [
2167 { blankLine: "always", prev: "*", next: "return" }
2168 ]
2169 },
2170 {
2171 code: "function a() {\nswitch (b) {\ncase 'b': {\nreturn;\n}\n}\n}",
2172 options: [
2173 { blankLine: "always", prev: "*", next: "return" }
2174 ]
2175 },
2176 {
2177 code: "function a() {\n//comment\nreturn b;\n}",
2178 options: [
2179 { blankLine: "always", prev: "*", next: "return" }
2180 ]
2181 },
2182 {
2183 code: "function a() {\n{\n//comment\n}\n\nreturn\n}",
2184 options: [
2185 { blankLine: "always", prev: "*", next: "return" }
2186 ]
2187 },
2188 {
2189 code: "function a() {\nvar b = {\n//comment\n};\n\nreturn;\n}",
2190 options: [
2191 { blankLine: "always", prev: "*", next: "return" }
2192 ]
2193 },
2194 {
2195 code: "function a() {/*multi-line\ncomment*/return b;\n}",
2196 options: [
2197 { blankLine: "always", prev: "*", next: "return" }
2198 ]
2199 },
2200 {
2201 code: "function a() {\n/*comment\ncomment*/\n//comment\nreturn b;\n}",
2202 options: [
2203 { blankLine: "always", prev: "*", next: "return" }
2204 ]
2205 },
2206 {
2207 code: "function a() {\n/*comment\ncomment*/\n//comment\nif (b) return;\n}",
2208 options: [
2209 { blankLine: "always", prev: "*", next: "return" }
2210 ]
2211 },
2212 {
2213 code: "function a() {\n/*comment\ncomment*/\n//comment\nif (b) {\nc();\n\nreturn b;\n} else {\n//comment\nreturn d;\n}\n\n/*multi-line\ncomment*/\nreturn e;\n}",
2214 options: [
2215 { blankLine: "always", prev: "*", next: "return" }
2216 ]
2217 },
2218 {
2219 code: "function a() {\nif (b) { //comment\nreturn;\n}\n\nreturn c;\n}",
2220 options: [
2221 { blankLine: "always", prev: "*", next: "return" }
2222 ]
2223 },
2224 {
2225 code: "function a() {\nif (b) { return; } //comment\n\nreturn c;\n}",
2226 options: [
2227 { blankLine: "always", prev: "*", next: "return" }
2228 ]
2229 },
2230 {
2231 code: "function a() {\nif (b) { return; } /*multi-line\ncomment*/\n\nreturn c;\n}",
2232 options: [
2233 { blankLine: "always", prev: "*", next: "return" }
2234 ]
2235 },
2236 {
2237 code: "function a() {\nif (b) { return; }\n\n/*multi-line\ncomment*/ return c;\n}",
2238 options: [
2239 { blankLine: "always", prev: "*", next: "return" }
2240 ]
2241 },
2242 {
2243 code: "return;",
2244 options: [
2245 { blankLine: "always", prev: "*", next: "return" }
2246 ],
2247 parserOptions: { ecmaFeatures: { globalReturn: true } }
2248 },
2249 {
2250 code: "var a;\n\nreturn;",
2251 options: [
2252 { blankLine: "always", prev: "*", next: "return" }
2253 ],
2254 parserOptions: { ecmaFeatures: { globalReturn: true } }
2255 },
2256 {
2257 code: "// comment\nreturn;",
2258 options: [
2259 { blankLine: "always", prev: "*", next: "return" }
2260 ],
2261 parserOptions: { ecmaFeatures: { globalReturn: true } }
2262 },
2263 {
2264 code: "/* comment */\nreturn;",
2265 options: [
2266 { blankLine: "always", prev: "*", next: "return" }
2267 ],
2268 parserOptions: { ecmaFeatures: { globalReturn: true } }
2269 },
2270 {
2271 code: "/* multi-line\ncomment */\nreturn;",
2272 options: [
2273 { blankLine: "always", prev: "*", next: "return" }
2274 ],
2275 parserOptions: { ecmaFeatures: { globalReturn: true } }
2276 },
2277
2278 //----------------------------------------------------------------------
2279 // From JSCS disallowPaddingNewLinesAfterBlocks
2280 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/disallow-padding-newlines-after-blocks.js
2281 //----------------------------------------------------------------------
2282
2283 {
2284 code: "if(true){}",
2285 options: [
2286 { blankLine: "never", prev: "block-like", next: "*" }
2287 ]
2288 },
2289 {
2290 code: "if(true){}\n",
2291 options: [
2292 { blankLine: "never", prev: "block-like", next: "*" }
2293 ]
2294 },
2295 {
2296 code: "if(true){}\nvar a = 2;",
2297 options: [
2298 { blankLine: "never", prev: "block-like", next: "*" }
2299 ]
2300 },
2301 {
2302 code: "if(true){\nif(true) {}\n}",
2303 options: [
2304 { blankLine: "never", prev: "block-like", next: "*" }
2305 ]
2306 },
2307 {
2308 code: "var a = {\nfoo: function() {\n},\nbar: function() {\n}}",
2309 options: [
2310 { blankLine: "never", prev: "block-like", next: "*" }
2311 ]
2312 },
2313 {
2314 code: "(function(){\n})()\nvar a = 2;",
2315 options: [
2316 { blankLine: "never", prev: "block-like", next: "*" }
2317 ]
2318 },
2319 {
2320 code: "if(true) {\n}\nelse\n{\n}",
2321 options: [
2322 { blankLine: "never", prev: "block-like", next: "*" }
2323 ]
2324 },
2325 {
2326 code: "if(true) {\n} else {\n var a = 2; }",
2327 options: [
2328 { blankLine: "never", prev: "block-like", next: "*" }
2329 ]
2330 },
2331 {
2332 code: "if(true) {\n}\nelse if(true)\n{\n}\nelse {\n}",
2333 options: [
2334 { blankLine: "never", prev: "block-like", next: "*" }
2335 ]
2336 },
2337 {
2338 code: "do{\n}\nwhile(true)",
2339 options: [
2340 { blankLine: "never", prev: "block-like", next: "*" }
2341 ]
2342 },
2343 {
2344 code: "try{\n}\ncatch(e) {}",
2345 options: [
2346 { blankLine: "never", prev: "block-like", next: "*" }
2347 ]
2348 },
2349 {
2350 code: "try{\n}\nfinally {}",
2351 options: [
2352 { blankLine: "never", prev: "block-like", next: "*" }
2353 ]
2354 },
2355 {
2356 code: "try{\n}\ncatch(e) {\n}\nfinally {\n}",
2357 options: [
2358 { blankLine: "never", prev: "block-like", next: "*" }
2359 ]
2360 },
2361 {
2362 code: "[].map(function() {})\n.filter(function(){})",
2363 options: [
2364 { blankLine: "never", prev: "block-like", next: "*" }
2365 ]
2366 },
2367
2368 //----------------------------------------------------------------------
2369 // From JSCS disallowPaddingNewLinesBeforeExport
2370 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/disallow-padding-newlines-before-export.js
2371 //----------------------------------------------------------------------
2372
2373 {
2374 code: "var a = 2;\nmodule.exports = a;",
2375 options: [
2376 { blankLine: "never", prev: "*", next: "cjs-export" }
2377 ]
2378 },
2379 {
2380 code: "module.exports = 2;",
2381 options: [
2382 { blankLine: "never", prev: "*", next: "cjs-export" }
2383 ]
2384 },
2385 {
2386 code: "var a = 2;\n// foo\nmodule.exports = a;",
2387 options: [
2388 { blankLine: "never", prev: "*", next: "cjs-export" }
2389 ]
2390 },
2391
2392 /*
2393 * TODO: May it need an option to ignore blank lines followed by comments?
2394 * {
2395 * code: "var a = 2;\n\n// foo\nmodule.exports = a;",
2396 * options: [
2397 * { blankLine: "never", prev: "*", next: "cjs-export" }
2398 * ]
2399 * },
2400 */
2401 {
2402 code: "var a = 2;\n\nfoo.exports = a;",
2403 options: [
2404 { blankLine: "never", prev: "*", next: "cjs-export" }
2405 ]
2406 },
2407 {
2408 code: "var a = 2;\n\nmodule.foo = a;",
2409 options: [
2410 { blankLine: "never", prev: "*", next: "cjs-export" }
2411 ]
2412 },
2413 {
2414 code: "var a = 2;\n\nfoo = a;",
2415 options: [
2416 { blankLine: "never", prev: "*", next: "cjs-export" }
2417 ]
2418 },
2419
2420 //----------------------------------------------------------------------
2421 // From JSCS requirePaddingNewLinesAfterBlocks
2422 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/require-padding-newlines-after-blocks.js
2423 //----------------------------------------------------------------------
2424
2425 {
2426 code: "{}",
2427 options: [
2428 { blankLine: "always", prev: "block-like", next: "*" }
2429 ]
2430 },
2431 {
2432 code: "if(true){}",
2433 options: [
2434 { blankLine: "always", prev: "block-like", next: "*" }
2435 ]
2436 },
2437 {
2438 code: "if(true){}\n",
2439 options: [
2440 { blankLine: "always", prev: "block-like", next: "*" }
2441 ]
2442 },
2443 {
2444 code: "if(true){}\n\nvar a = 2;",
2445 options: [
2446 { blankLine: "always", prev: "block-like", next: "*" }
2447 ]
2448 },
2449 {
2450 code: "if(true){}\n\n\nvar a = 2;",
2451 options: [
2452 { blankLine: "always", prev: "block-like", next: "*" }
2453 ]
2454 },
2455 {
2456 code: "if(true){\nif(true) {}\n}",
2457 options: [
2458 { blankLine: "always", prev: "block-like", next: "*" }
2459 ]
2460 },
2461 {
2462 code: "var a = {\nfoo: function() {\n},\n\nbar: function() {\n}}",
2463 options: [
2464 { blankLine: "always", prev: "block-like", next: "*" }
2465 ]
2466 },
2467 {
2468 code: "(function(){\n})()\n\nvar a = 2;",
2469 options: [
2470 { blankLine: "always", prev: "block-like", next: "*" }
2471 ]
2472 },
2473 {
2474 code: "if(true) {\n}\nelse\n{\n}",
2475 options: [
2476 { blankLine: "always", prev: "block-like", next: "*" }
2477 ]
2478 },
2479 {
2480 code: "if(true) {\n} else {\n var a = 2; }",
2481 options: [
2482 { blankLine: "always", prev: "block-like", next: "*" }
2483 ]
2484 },
2485 {
2486 code: "if(true) {\n}\nelse if(true)\n{\n}\nelse {\n}",
2487 options: [
2488 { blankLine: "always", prev: "block-like", next: "*" }
2489 ]
2490 },
2491 {
2492 code: "do{\n}\nwhile(true)",
2493 options: [
2494 { blankLine: "always", prev: "block-like", next: "*" }
2495 ]
2496 },
2497 {
2498 code: "try{\n}\ncatch(e) {}",
2499 options: [
2500 { blankLine: "always", prev: "block-like", next: "*" }
2501 ]
2502 },
2503 {
2504 code: "try{\n}\nfinally {}",
2505 options: [
2506 { blankLine: "always", prev: "block-like", next: "*" }
2507 ]
2508 },
2509 {
2510 code: "try{\n}\ncatch(e) {\n}\nfinally {\n}",
2511 options: [
2512 { blankLine: "always", prev: "block-like", next: "*" }
2513 ]
2514 },
2515 {
2516 code: "[].map(function() {})\n.filter(function(){})",
2517 options: [
2518 { blankLine: "always", prev: "block-like", next: "*" }
2519 ]
2520 },
2521 {
2522 code: "func(\n2,\n3,\nfunction() {\n}\n)",
2523 options: [
2524 { blankLine: "always", prev: "block-like", next: "*" }
2525 ]
2526 },
2527 {
2528 code: "[\n2,\n3,\nfunction() {\n}\n]",
2529 options: [
2530 { blankLine: "always", prev: "block-like", next: "*" }
2531 ]
2532 },
2533 {
2534 code: "a(res => {\n})\n.b();",
2535 options: [
2536 { blankLine: "always", prev: "block-like", next: "*" }
2537 ]
2538 },
2539 {
2540 code: "var foo = (\n<div\nref={function() {\n}}\n>\nfoo\n</div>\n);",
2541 options: [
2542 { blankLine: "always", prev: "block-like", next: "*" }
2543 ],
2544 parserOptions: { ecmaFeatures: { jsx: true } }
2545 },
2546 {
2547 code: "var i = 0;\nwhile (i < 100) {\nif(i % 2 === 0) {continue;}\n++i;\n}",
2548 options: [
2549 { blankLine: "always", prev: "multiline-block-like", next: "*" }
2550 ]
2551 },
2552 {
2553 code: "var i = 0;\nwhile (i < 100) {\nif(i % 2 === 0) {if(i === 4) {continue;}}\n++i;\n}",
2554 options: [
2555 { blankLine: "always", prev: "multiline-block-like", next: "*" }
2556 ]
2557 },
2558
2559 //----------------------------------------------------------------------
2560 // From JSCS requirePaddingNewLinesBeforeExport
2561 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/require-padding-newlines-before-export.js
2562 //----------------------------------------------------------------------
2563
2564 {
2565 code: "module.exports = 2;",
2566 options: [
2567 { blankLine: "always", prev: "*", next: "cjs-export" }
2568 ]
2569 },
2570 {
2571 code: "var a = 2;\n\nmodule.exports = a;",
2572 options: [
2573 { blankLine: "always", prev: "*", next: "cjs-export" }
2574 ]
2575 },
2576 {
2577 code: "var a = 2;\nfoo.exports = a;",
2578 options: [
2579 { blankLine: "always", prev: "*", next: "cjs-export" }
2580 ]
2581 },
2582 {
2583 code: "var a = 2;\nmodule.foo = a;",
2584 options: [
2585 { blankLine: "always", prev: "*", next: "cjs-export" }
2586 ]
2587 },
2588 {
2589 code: "if (true) {\nmodule.exports = a;\n}",
2590 options: [
2591 { blankLine: "always", prev: "*", next: "cjs-export" }
2592 ]
2593 },
2594
2595 //----------------------------------------------------------------------
2596 // From JSCS requirePaddingNewlinesBeforeKeywords
2597 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/require-padding-newlines-before-keywords.js
2598 //----------------------------------------------------------------------
2599
2600 {
2601 code: "function x() { return; }",
2602 options: [
2603 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
2604 ]
2605 },
2606 {
2607 code: "if (true) {} else if (false) {}",
2608 options: [
2609 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
2610 ]
2611 },
2612 {
2613 code: "function x() { var a = true; do { a = !a; } while (a); }",
2614 options: [
2615 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
2616 ]
2617 },
2618 {
2619 code: "function x() { if (true) return; }",
2620 options: [
2621 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
2622 ]
2623 },
2624 {
2625 code: "function test() {};",
2626 options: [
2627 { blankLine: "always", prev: "block-like", next: "block-like" }
2628 ]
2629 },
2630
2631 // class static blocks
2632 {
2633 code: "class C {\n static {\n let x;\n\n foo();\n }\n }",
2634 options: [
2635 { blankLine: "always", prev: "let", next: "expression" }
2636 ],
2637 parserOptions: { ecmaVersion: 2022 }
2638 },
2639 {
2640 code: "class C {\n static {\n let x;\n foo();\n }\n }",
2641 options: [
2642 { blankLine: "never", prev: "let", next: "expression" }
2643 ],
2644 parserOptions: { ecmaVersion: 2022 }
2645 },
2646 {
2647 code: "class C {\n static {\n let x;\n foo();\n\n const y = 1;\n }\n }",
2648 options: [
2649 { blankLine: "always", prev: "expression", next: "const" }
2650 ],
2651 parserOptions: { ecmaVersion: 2022 }
2652 },
2653 {
2654 code: "class C {\n static {\n let x;\n foo();\n const y = 1;\n }\n }",
2655 options: [
2656 { blankLine: "never", prev: "expression", next: "const" }
2657 ],
2658 parserOptions: { ecmaVersion: 2022 }
2659 },
2660 {
2661 code: "class C {\n static {\n let x;\n foo();\n\n const y = 1;\n const z = 1;\n }\n }",
2662 options: [
2663 { blankLine: "always", prev: "expression", next: "const" }
2664 ],
2665 parserOptions: { ecmaVersion: 2022 }
2666 },
2667 {
2668 code: "class C {\n static {\n let x;\n foo();\n const y = 1;\n const z = 1;\n }\n }",
2669 options: [
2670 { blankLine: "never", prev: "expression", next: "const" }
2671 ],
2672 parserOptions: { ecmaVersion: 2022 }
2673 },
2674 {
2675 code: "class C {\n static {\n let a = 0;\n let b =0;\n\n bar();\n }\n }",
2676 options: [
2677 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
2678 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
2679 ],
2680 parserOptions: { ecmaVersion: 2022 }
2681 },
2682 {
2683 code: "class C { static { let x; { let y; } let z; } }",
2684 options: [
2685 { blankLine: "always", prev: "let", next: "let" }
2686 ],
2687 parserOptions: { ecmaVersion: 2022 }
2688 },
2689 {
2690 code: "class C { method() { let x; } static { let y; } }",
2691 options: [
2692 { blankLine: "always", prev: "let", next: "let" }
2693 ],
2694 parserOptions: { ecmaVersion: 2022 }
2695 },
2696 {
2697 code: "class C { static { let y; } method() { let x; } }",
2698 options: [
2699 { blankLine: "always", prev: "let", next: "let" }
2700 ],
2701 parserOptions: { ecmaVersion: 2022 }
2702 },
2703 {
2704 code: "class C { static { let x; } static { let y; } }",
2705 options: [
2706 { blankLine: "always", prev: "let", next: "let" }
2707 ],
2708 parserOptions: { ecmaVersion: 2022 }
2709 },
2710 {
2711 code: "let x; class C { static { let y; } }",
2712 options: [
2713 { blankLine: "always", prev: "let", next: "let" }
2714 ],
2715 parserOptions: { ecmaVersion: 2022 }
2716 },
2717 {
2718 code: "class C { static { let x; } } let y;",
2719 options: [
2720 { blankLine: "always", prev: "let", next: "let" }
2721 ],
2722 parserOptions: { ecmaVersion: 2022 }
2723 },
2724 {
2725 code: "class C { static { let x; } }",
2726 options: [
2727 { blankLine: "always", prev: "class", next: "let" }
2728 ],
2729 parserOptions: { ecmaVersion: 2022 }
2730 },
2731 {
2732 code: "class C { static { 'use strict'; let x; } }", // 'use strict'; is "espression", because class static blocks don't have directives
2733 options: [
2734 { blankLine: "always", prev: "directive", next: "let" }
2735 ],
2736 parserOptions: { ecmaVersion: 2022 }
2737 }
2738 ],
2739 invalid: [
2740
2741 //----------------------------------------------------------------------
2742 // wildcard
2743 //----------------------------------------------------------------------
2744
2745 {
2746 code: "foo();\n\nfoo();",
2747 output: "foo();\nfoo();",
2748 options: [
2749 { blankLine: "never", prev: "*", next: "*" }
2750 ],
2751 errors: [{ messageId: "unexpectedBlankLine" }]
2752 },
2753 {
2754 code: "foo();\n\n//comment\nfoo();",
2755 output: "foo();\n//comment\nfoo();",
2756 options: [
2757 { blankLine: "never", prev: "*", next: "*" }
2758 ],
2759 errors: [{ messageId: "unexpectedBlankLine" }]
2760 },
2761 {
2762 code: " foo();\n \n //comment\n foo();",
2763 output: " foo();\n //comment\n foo();",
2764 options: [
2765 { blankLine: "never", prev: "*", next: "*" }
2766 ],
2767 errors: [{ messageId: "unexpectedBlankLine" }]
2768 },
2769 {
2770 code: "if (a) {}\n\nfor (;;) {}",
2771 output: "if (a) {}\nfor (;;) {}",
2772 options: [
2773 { blankLine: "never", prev: "*", next: "*" }
2774 ],
2775 errors: [{ messageId: "unexpectedBlankLine" }]
2776 },
2777 {
2778 code: "foo();\nfoo();",
2779 output: "foo();\n\nfoo();",
2780 options: [
2781 { blankLine: "always", prev: "*", next: "*" }
2782 ],
2783 errors: [{ messageId: "expectedBlankLine" }]
2784 },
2785 {
2786 code: " function a() {}\n do {} while (a)",
2787 output: " function a() {}\n\n do {} while (a)",
2788 options: [
2789 { blankLine: "always", prev: "*", next: "*" }
2790 ],
2791 errors: [{ messageId: "expectedBlankLine" }]
2792 },
2793 {
2794 code: "foo();//trailing-comment\n//comment\n//comment\nfoo();",
2795 output: "foo();//trailing-comment\n\n//comment\n//comment\nfoo();",
2796 options: [
2797 { blankLine: "always", prev: "*", next: "*" }
2798 ],
2799 errors: [{ messageId: "expectedBlankLine" }]
2800 },
2801
2802 //----------------------------------------------------------------------
2803 // block-like
2804 //----------------------------------------------------------------------
2805
2806 {
2807 code: "{}\n\nfoo()",
2808 output: "{}\nfoo()",
2809 options: [
2810 { blankLine: "never", prev: "block-like", next: "*" }
2811 ],
2812 errors: [{ messageId: "unexpectedBlankLine" }]
2813 },
2814 {
2815 code: "{}\nfoo()",
2816 output: "{}\n\nfoo()",
2817 options: [
2818 { blankLine: "always", prev: "block-like", next: "*" }
2819 ],
2820 errors: [{ messageId: "expectedBlankLine" }]
2821 },
2822 {
2823 code: "if(a){}\nfoo()",
2824 output: "if(a){}\n\nfoo()",
2825 options: [
2826 { blankLine: "always", prev: "block-like", next: "*" }
2827 ],
2828 errors: [{ messageId: "expectedBlankLine" }]
2829 },
2830 {
2831 code: "if(a){}else{}\nfoo()",
2832 output: "if(a){}else{}\n\nfoo()",
2833 options: [
2834 { blankLine: "always", prev: "block-like", next: "*" }
2835 ],
2836 errors: [{ messageId: "expectedBlankLine" }]
2837 },
2838 {
2839 code: "if(a){}else if(b){}\nfoo()",
2840 output: "if(a){}else if(b){}\n\nfoo()",
2841 options: [
2842 { blankLine: "always", prev: "block-like", next: "*" }
2843 ],
2844 errors: [{ messageId: "expectedBlankLine" }]
2845 },
2846 {
2847 code: "if(a){}else if(b){}else{}\nfoo()",
2848 output: "if(a){}else if(b){}else{}\n\nfoo()",
2849 options: [
2850 { blankLine: "always", prev: "block-like", next: "*" }
2851 ],
2852 errors: [{ messageId: "expectedBlankLine" }]
2853 },
2854 {
2855 code: "switch(a){}\nfoo()",
2856 output: "switch(a){}\n\nfoo()",
2857 options: [
2858 { blankLine: "always", prev: "block-like", next: "*" }
2859 ],
2860 errors: [{ messageId: "expectedBlankLine" }]
2861 },
2862 {
2863 code: "switch(a){case 0:}\nfoo()",
2864 output: "switch(a){case 0:}\n\nfoo()",
2865 options: [
2866 { blankLine: "always", prev: "block-like", next: "*" }
2867 ],
2868 errors: [{ messageId: "expectedBlankLine" }]
2869 },
2870 {
2871 code: "try{}catch(e){}\nfoo()",
2872 output: "try{}catch(e){}\n\nfoo()",
2873 options: [
2874 { blankLine: "always", prev: "block-like", next: "*" }
2875 ],
2876 errors: [{ messageId: "expectedBlankLine" }]
2877 },
2878 {
2879 code: "try{}finally{}\nfoo()",
2880 output: "try{}finally{}\n\nfoo()",
2881 options: [
2882 { blankLine: "always", prev: "block-like", next: "*" }
2883 ],
2884 errors: [{ messageId: "expectedBlankLine" }]
2885 },
2886 {
2887 code: "try{}catch(e){}finally{}\nfoo()",
2888 output: "try{}catch(e){}finally{}\n\nfoo()",
2889 options: [
2890 { blankLine: "always", prev: "block-like", next: "*" }
2891 ],
2892 errors: [{ messageId: "expectedBlankLine" }]
2893 },
2894 {
2895 code: "while(a){}\nfoo()",
2896 output: "while(a){}\n\nfoo()",
2897 options: [
2898 { blankLine: "always", prev: "block-like", next: "*" }
2899 ],
2900 errors: [{ messageId: "expectedBlankLine" }]
2901 },
2902 {
2903 code: "do{}while(a)\nfoo()",
2904 output: "do{}while(a)\n\nfoo()",
2905 options: [
2906 { blankLine: "always", prev: "block-like", next: "*" }
2907 ],
2908 errors: [{ messageId: "expectedBlankLine" }]
2909 },
2910 {
2911 code: "for(;;){}\nfoo()",
2912 output: "for(;;){}\n\nfoo()",
2913 options: [
2914 { blankLine: "always", prev: "block-like", next: "*" }
2915 ],
2916 errors: [{ messageId: "expectedBlankLine" }]
2917 },
2918 {
2919 code: "for(a in b){}\nfoo()",
2920 output: "for(a in b){}\n\nfoo()",
2921 options: [
2922 { blankLine: "always", prev: "block-like", next: "*" }
2923 ],
2924 errors: [{ messageId: "expectedBlankLine" }]
2925 },
2926 {
2927 code: "for(a of b){}\nfoo()",
2928 output: "for(a of b){}\n\nfoo()",
2929 options: [
2930 { blankLine: "always", prev: "block-like", next: "*" }
2931 ],
2932 errors: [{ messageId: "expectedBlankLine" }]
2933 },
2934 {
2935 code: "a=function(){}\nfoo()",
2936 output: "a=function(){}\n\nfoo()",
2937 options: [
2938 { blankLine: "always", prev: "block-like", next: "*" }
2939 ],
2940 errors: [{ messageId: "expectedBlankLine" }]
2941 },
2942 {
2943 code: "a=()=>{}\nfoo()",
2944 output: "a=()=>{}\n\nfoo()",
2945 options: [
2946 { blankLine: "always", prev: "block-like", next: "*" }
2947 ],
2948 errors: [{ messageId: "expectedBlankLine" }]
2949 },
2950 {
2951 code: "function a(){}\nfoo()",
2952 output: "function a(){}\n\nfoo()",
2953 options: [
2954 { blankLine: "always", prev: "block-like", next: "*" }
2955 ],
2956 errors: [{ messageId: "expectedBlankLine" }]
2957 },
2958 {
2959 code: "let a=function(){}\nfoo()",
2960 output: "let a=function(){}\n\nfoo()",
2961 options: [
2962 { blankLine: "always", prev: "block-like", next: "*" }
2963 ],
2964 errors: [{ messageId: "expectedBlankLine" }]
2965 },
2966
2967 //----------------------------------------------------------------------
2968 // cjs-export
2969 //----------------------------------------------------------------------
2970
2971 {
2972 code: "module.exports=1\n\nfoo()",
2973 output: "module.exports=1\nfoo()",
2974 options: [
2975 { blankLine: "never", prev: "cjs-export", next: "*" }
2976 ],
2977 errors: [{ messageId: "unexpectedBlankLine" }]
2978 },
2979 {
2980 code: "module.exports=1\nfoo()",
2981 output: "module.exports=1\n\nfoo()",
2982 options: [
2983 { blankLine: "always", prev: "cjs-export", next: "*" }
2984 ],
2985 errors: [{ messageId: "expectedBlankLine" }]
2986 },
2987 {
2988 code: "module.exports.foo=1\nfoo()",
2989 output: "module.exports.foo=1\n\nfoo()",
2990 options: [
2991 { blankLine: "always", prev: "cjs-export", next: "*" }
2992 ],
2993 errors: [{ messageId: "expectedBlankLine" }]
2994 },
2995 {
2996 code: "module.exports[foo]=1\nfoo()",
2997 output: "module.exports[foo]=1\n\nfoo()",
2998 options: [
2999 { blankLine: "always", prev: "cjs-export", next: "*" }
3000 ],
3001 errors: [{ messageId: "expectedBlankLine" }]
3002 },
3003 {
3004 code: "exports.foo=1\nfoo()",
3005 output: "exports.foo=1\n\nfoo()",
3006 options: [
3007 { blankLine: "always", prev: "cjs-export", next: "*" }
3008 ],
3009 errors: [{ messageId: "expectedBlankLine" }]
3010 },
3011 {
3012 code: "exports[foo]=1\nfoo()",
3013 output: "exports[foo]=1\n\nfoo()",
3014 options: [
3015 { blankLine: "always", prev: "cjs-export", next: "*" }
3016 ],
3017 errors: [{ messageId: "expectedBlankLine" }]
3018 },
3019
3020 //----------------------------------------------------------------------
3021 // cjs-import
3022 //----------------------------------------------------------------------
3023
3024 {
3025 code: "const foo=require(\"foo\")\n\nfoo()",
3026 output: "const foo=require(\"foo\")\nfoo()",
3027 options: [
3028 { blankLine: "never", prev: "cjs-import", next: "*" }
3029 ],
3030 errors: [{ messageId: "unexpectedBlankLine" }]
3031 },
3032 {
3033 code: "const foo=require(\"foo\")\nfoo()",
3034 output: "const foo=require(\"foo\")\n\nfoo()",
3035 options: [
3036 { blankLine: "always", prev: "cjs-import", next: "*" }
3037 ],
3038 errors: [{ messageId: "expectedBlankLine" }]
3039 },
3040 {
3041 code: "const foo=require(\"foo\").Foo\nfoo()",
3042 output: "const foo=require(\"foo\").Foo\n\nfoo()",
3043 options: [
3044 { blankLine: "always", prev: "cjs-import", next: "*" }
3045 ],
3046 errors: [{ messageId: "expectedBlankLine" }]
3047 },
3048 {
3049 code: "const foo=require(\"foo\")[a]\nfoo()",
3050 output: "const foo=require(\"foo\")[a]\n\nfoo()",
3051 options: [
3052 { blankLine: "always", prev: "cjs-import", next: "*" }
3053 ],
3054 errors: [{ messageId: "expectedBlankLine" }]
3055 },
3056
3057 //----------------------------------------------------------------------
3058 // directive
3059 //----------------------------------------------------------------------
3060
3061 {
3062 code: "\"use strict\"\n\nfoo()",
3063 output: "\"use strict\"\nfoo()",
3064 options: [
3065 { blankLine: "never", prev: "directive", next: "*" }
3066 ],
3067 errors: [{ messageId: "unexpectedBlankLine" }]
3068 },
3069 {
3070 code: "\"use strict\"\nfoo()",
3071 output: "\"use strict\"\n\nfoo()",
3072 options: [
3073 { blankLine: "always", prev: "directive", next: "*" }
3074 ],
3075 errors: [{ messageId: "expectedBlankLine" }]
3076 },
3077 {
3078 code: "'use strict'\nfoo()",
3079 output: "'use strict'\n\nfoo()",
3080 options: [
3081 { blankLine: "always", prev: "directive", next: "*" }
3082 ],
3083 errors: [{ messageId: "expectedBlankLine" }]
3084 },
3085 {
3086 code: "'use asm'\nfoo()",
3087 output: "'use asm'\n\nfoo()",
3088 options: [
3089 { blankLine: "always", prev: "directive", next: "*" }
3090 ],
3091 errors: [{ messageId: "expectedBlankLine" }]
3092 },
3093
3094 //----------------------------------------------------------------------
3095 // multiline-block-like
3096 //----------------------------------------------------------------------
3097
3098 {
3099 code: "{\n}\n\nfoo()",
3100 output: "{\n}\nfoo()",
3101 options: [
3102 { blankLine: "never", prev: "block-like", next: "*" }
3103 ],
3104 errors: [{ messageId: "unexpectedBlankLine" }]
3105 },
3106 {
3107 code: "{\n}\nfoo()",
3108 output: "{\n}\n\nfoo()",
3109 options: [
3110 { blankLine: "always", prev: "block-like", next: "*" }
3111 ],
3112 errors: [{ messageId: "expectedBlankLine" }]
3113 },
3114 {
3115 code: "if(a){\n}\nfoo()",
3116 output: "if(a){\n}\n\nfoo()",
3117 options: [
3118 { blankLine: "always", prev: "block-like", next: "*" }
3119 ],
3120 errors: [{ messageId: "expectedBlankLine" }]
3121 },
3122 {
3123 code: "if(a){\n}else{\n}\nfoo()",
3124 output: "if(a){\n}else{\n}\n\nfoo()",
3125 options: [
3126 { blankLine: "always", prev: "block-like", next: "*" }
3127 ],
3128 errors: [{ messageId: "expectedBlankLine" }]
3129 },
3130 {
3131 code: "if(a){\n}else if(b){\n}\nfoo()",
3132 output: "if(a){\n}else if(b){\n}\n\nfoo()",
3133 options: [
3134 { blankLine: "always", prev: "block-like", next: "*" }
3135 ],
3136 errors: [{ messageId: "expectedBlankLine" }]
3137 },
3138 {
3139 code: "if(a){\n}else if(b){\n}else{\n}\nfoo()",
3140 output: "if(a){\n}else if(b){\n}else{\n}\n\nfoo()",
3141 options: [
3142 { blankLine: "always", prev: "block-like", next: "*" }
3143 ],
3144 errors: [{ messageId: "expectedBlankLine" }]
3145 },
3146 {
3147 code: "switch(a){\n}\nfoo()",
3148 output: "switch(a){\n}\n\nfoo()",
3149 options: [
3150 { blankLine: "always", prev: "block-like", next: "*" }
3151 ],
3152 errors: [{ messageId: "expectedBlankLine" }]
3153 },
3154 {
3155 code: "try{\n}catch(e){\n}\nfoo()",
3156 output: "try{\n}catch(e){\n}\n\nfoo()",
3157 options: [
3158 { blankLine: "always", prev: "block-like", next: "*" }
3159 ],
3160 errors: [{ messageId: "expectedBlankLine" }]
3161 },
3162 {
3163 code: "try{\n}finally{\n}\nfoo()",
3164 output: "try{\n}finally{\n}\n\nfoo()",
3165 options: [
3166 { blankLine: "always", prev: "block-like", next: "*" }
3167 ],
3168 errors: [{ messageId: "expectedBlankLine" }]
3169 },
3170 {
3171 code: "try{\n}catch(e){\n}finally{\n}\nfoo()",
3172 output: "try{\n}catch(e){\n}finally{\n}\n\nfoo()",
3173 options: [
3174 { blankLine: "always", prev: "block-like", next: "*" }
3175 ],
3176 errors: [{ messageId: "expectedBlankLine" }]
3177 },
3178 {
3179 code: "while(a){\n}\nfoo()",
3180 output: "while(a){\n}\n\nfoo()",
3181 options: [
3182 { blankLine: "always", prev: "block-like", next: "*" }
3183 ],
3184 errors: [{ messageId: "expectedBlankLine" }]
3185 },
3186 {
3187 code: "do{\n}while(a)\nfoo()",
3188 output: "do{\n}while(a)\n\nfoo()",
3189 options: [
3190 { blankLine: "always", prev: "block-like", next: "*" }
3191 ],
3192 errors: [{ messageId: "expectedBlankLine" }]
3193 },
3194 {
3195 code: "for(;;){\n}\nfoo()",
3196 output: "for(;;){\n}\n\nfoo()",
3197 options: [
3198 { blankLine: "always", prev: "block-like", next: "*" }
3199 ],
3200 errors: [{ messageId: "expectedBlankLine" }]
3201 },
3202 {
3203 code: "for(a in b){\n}\nfoo()",
3204 output: "for(a in b){\n}\n\nfoo()",
3205 options: [
3206 { blankLine: "always", prev: "block-like", next: "*" }
3207 ],
3208 errors: [{ messageId: "expectedBlankLine" }]
3209 },
3210 {
3211 code: "for(a of b){\n}\nfoo()",
3212 output: "for(a of b){\n}\n\nfoo()",
3213 options: [
3214 { blankLine: "always", prev: "block-like", next: "*" }
3215 ],
3216 errors: [{ messageId: "expectedBlankLine" }]
3217 },
3218 {
3219 code: "a=function(){\n}\nfoo()",
3220 output: "a=function(){\n}\n\nfoo()",
3221 options: [
3222 { blankLine: "always", prev: "block-like", next: "*" }
3223 ],
3224 errors: [{ messageId: "expectedBlankLine" }]
3225 },
3226 {
3227 code: "a=()=>{\n}\nfoo()",
3228 output: "a=()=>{\n}\n\nfoo()",
3229 options: [
3230 { blankLine: "always", prev: "block-like", next: "*" }
3231 ],
3232 errors: [{ messageId: "expectedBlankLine" }]
3233 },
3234 {
3235 code: "function a(){\n}\nfoo()",
3236 output: "function a(){\n}\n\nfoo()",
3237 options: [
3238 { blankLine: "always", prev: "block-like", next: "*" }
3239 ],
3240 errors: [{ messageId: "expectedBlankLine" }]
3241 },
3242 {
3243 code: "let a=function(){\n}\nfoo()",
3244 output: "let a=function(){\n}\n\nfoo()",
3245 options: [
3246 { blankLine: "always", prev: "block-like", next: "*" }
3247 ],
3248 errors: [{ messageId: "expectedBlankLine" }]
3249 },
3250
3251 //----------------------------------------------------------------------
3252 // block
3253 //----------------------------------------------------------------------
3254
3255 {
3256 code: "{}\n\nfoo()",
3257 output: "{}\nfoo()",
3258 options: [
3259 { blankLine: "never", prev: "block", next: "*" }
3260 ],
3261 errors: [{ messageId: "unexpectedBlankLine" }]
3262 },
3263 {
3264 code: "{}\nfoo()",
3265 output: "{}\n\nfoo()",
3266 options: [
3267 { blankLine: "always", prev: "block", next: "*" }
3268 ],
3269 errors: [{ messageId: "expectedBlankLine" }]
3270 },
3271
3272 //----------------------------------------------------------------------
3273 // empty
3274 //----------------------------------------------------------------------
3275
3276 {
3277 code: ";\n\nfoo()",
3278 output: ";\nfoo()",
3279 options: [
3280 { blankLine: "never", prev: "empty", next: "*" }
3281 ],
3282 errors: [{ messageId: "unexpectedBlankLine" }]
3283 },
3284 {
3285 code: ";\nfoo()",
3286 output: ";\n\nfoo()",
3287 options: [
3288 { blankLine: "always", prev: "empty", next: "*" }
3289 ],
3290 errors: [{ messageId: "expectedBlankLine" }]
3291 },
3292
3293 //----------------------------------------------------------------------
3294 // expression
3295 //----------------------------------------------------------------------
3296
3297 {
3298 code: "foo()\n\nfoo()",
3299 output: "foo()\nfoo()",
3300 options: [
3301 { blankLine: "never", prev: "expression", next: "*" }
3302 ],
3303 errors: [{ messageId: "unexpectedBlankLine" }]
3304 },
3305 {
3306 code: "foo()\nfoo()",
3307 output: "foo()\n\nfoo()",
3308 options: [
3309 { blankLine: "always", prev: "expression", next: "*" }
3310 ],
3311 errors: [{ messageId: "expectedBlankLine" }]
3312 },
3313
3314 //----------------------------------------------------------------------
3315 // multiline-expression
3316 //----------------------------------------------------------------------
3317
3318 {
3319 code: "foo()\n\nfoo(\n\tx,\n\ty\n)",
3320 output: "foo()\nfoo(\n\tx,\n\ty\n)",
3321 options: [
3322 { blankLine: "never", prev: "*", next: "multiline-expression" }
3323 ],
3324 errors: [{ messageId: "unexpectedBlankLine" }]
3325 },
3326 {
3327 code: "foo()\nfoo(\n\tx,\n\ty\n)",
3328 output: "foo()\n\nfoo(\n\tx,\n\ty\n)",
3329 options: [
3330 { blankLine: "always", prev: "*", next: "multiline-expression" }
3331 ],
3332 errors: [{ messageId: "expectedBlankLine" }]
3333 },
3334 {
3335 code: "() => {\n\tsomeArray.forEach(\n\t\tx => doSomething(x)\n\t);\n\treturn theThing;\n}",
3336 output: "() => {\n\tsomeArray.forEach(\n\t\tx => doSomething(x)\n\t);\n\n\treturn theThing;\n}",
3337 options: [
3338 { blankLine: "always", prev: "multiline-expression", next: "return" }
3339 ],
3340 errors: [{ messageId: "expectedBlankLine" }]
3341 },
3342
3343 //----------------------------------------------------------------------
3344 // break
3345 //----------------------------------------------------------------------
3346
3347 {
3348 code: "while(a){break\n\nfoo()}",
3349 output: "while(a){break\nfoo()}",
3350 options: [
3351 { blankLine: "never", prev: "break", next: "*" }
3352 ],
3353 errors: [{ messageId: "unexpectedBlankLine" }]
3354 },
3355 {
3356 code: "switch(a){case 0:break\n\nfoo()}",
3357 output: "switch(a){case 0:break\nfoo()}",
3358 options: [
3359 { blankLine: "never", prev: "break", next: "*" }
3360 ],
3361 errors: [{ messageId: "unexpectedBlankLine" }]
3362 },
3363 {
3364 code: "while(a){break\nfoo()}",
3365 output: "while(a){break\n\nfoo()}",
3366 options: [
3367 { blankLine: "always", prev: "break", next: "*" }
3368 ],
3369 errors: [{ messageId: "expectedBlankLine" }]
3370 },
3371 {
3372 code: "switch(a){case 0:break\nfoo()}",
3373 output: "switch(a){case 0:break\n\nfoo()}",
3374 options: [
3375 { blankLine: "always", prev: "break", next: "*" }
3376 ],
3377 errors: [{ messageId: "expectedBlankLine" }]
3378 },
3379
3380 //----------------------------------------------------------------------
3381 // case
3382 //----------------------------------------------------------------------
3383
3384 {
3385 code: "switch(a){case 0:\nfoo()\n\ndefault:}",
3386 output: "switch(a){case 0:\nfoo()\ndefault:}",
3387 options: [
3388 { blankLine: "never", prev: "case", next: "*" }
3389 ],
3390 errors: [{ messageId: "unexpectedBlankLine" }]
3391 },
3392 {
3393 code: "switch(a){case 0:\nfoo()\ndefault:}",
3394 output: "switch(a){case 0:\nfoo()\n\ndefault:}",
3395 options: [
3396 { blankLine: "always", prev: "case", next: "*" }
3397 ],
3398 errors: [{ messageId: "expectedBlankLine" }]
3399 },
3400
3401 //----------------------------------------------------------------------
3402 // class
3403 //----------------------------------------------------------------------
3404
3405 {
3406 code: "class A{}\n\nfoo()",
3407 output: "class A{}\nfoo()",
3408 options: [
3409 { blankLine: "never", prev: "class", next: "*" }
3410 ],
3411 errors: [{ messageId: "unexpectedBlankLine" }]
3412 },
3413 {
3414 code: "class A{}\nfoo()",
3415 output: "class A{}\n\nfoo()",
3416 options: [
3417 { blankLine: "always", prev: "class", next: "*" }
3418 ],
3419 errors: [{ messageId: "expectedBlankLine" }]
3420 },
3421
3422 //----------------------------------------------------------------------
3423 // const
3424 //----------------------------------------------------------------------
3425
3426 {
3427 code: "const a=1\n\nfoo()",
3428 output: "const a=1\nfoo()",
3429 options: [
3430 { blankLine: "never", prev: "const", next: "*" }
3431 ],
3432 errors: [{ messageId: "unexpectedBlankLine" }]
3433 },
3434 {
3435 code: "const a=1\nfoo()",
3436 output: "const a=1\n\nfoo()",
3437 options: [
3438 { blankLine: "always", prev: "const", next: "*" }
3439 ],
3440 errors: [{ messageId: "expectedBlankLine" }]
3441 },
3442
3443 //----------------------------------------------------------------------
3444 // continue
3445 //----------------------------------------------------------------------
3446
3447 {
3448 code: "while(a){continue\n\nfoo()}",
3449 output: "while(a){continue\nfoo()}",
3450 options: [
3451 { blankLine: "never", prev: "continue", next: "*" }
3452 ],
3453 errors: [{ messageId: "unexpectedBlankLine" }]
3454 },
3455 {
3456 code: "while(a){continue\nfoo()}",
3457 output: "while(a){continue\n\nfoo()}",
3458 options: [
3459 { blankLine: "always", prev: "continue", next: "*" }
3460 ],
3461 errors: [{ messageId: "expectedBlankLine" }]
3462 },
3463
3464 //----------------------------------------------------------------------
3465 // debugger
3466 //----------------------------------------------------------------------
3467
3468 {
3469 code: "debugger\n\nfoo()",
3470 output: "debugger\nfoo()",
3471 options: [
3472 { blankLine: "never", prev: "debugger", next: "*" }
3473 ],
3474 errors: [{ messageId: "unexpectedBlankLine" }]
3475 },
3476 {
3477 code: "debugger\nfoo()",
3478 output: "debugger\n\nfoo()",
3479 options: [
3480 { blankLine: "always", prev: "debugger", next: "*" }
3481 ],
3482 errors: [{ messageId: "expectedBlankLine" }]
3483 },
3484
3485 //----------------------------------------------------------------------
3486 // default
3487 //----------------------------------------------------------------------
3488
3489 {
3490 code: "switch(a){default:\nfoo()\n\ncase 0:}",
3491 output: "switch(a){default:\nfoo()\ncase 0:}",
3492 options: [
3493 { blankLine: "never", prev: "default", next: "*" }
3494 ],
3495 errors: [{ messageId: "unexpectedBlankLine" }]
3496 },
3497 {
3498 code: "switch(a){default:\nfoo()\ncase 0:}",
3499 output: "switch(a){default:\nfoo()\n\ncase 0:}",
3500 options: [
3501 { blankLine: "always", prev: "default", next: "*" }
3502 ],
3503 errors: [{ messageId: "expectedBlankLine" }]
3504 },
3505
3506 //----------------------------------------------------------------------
3507 // do
3508 //----------------------------------------------------------------------
3509
3510 {
3511 code: "do;while(a)\n\nfoo()",
3512 output: "do;while(a)\nfoo()",
3513 options: [
3514 { blankLine: "never", prev: "do", next: "*" }
3515 ],
3516 errors: [{ messageId: "unexpectedBlankLine" }]
3517 },
3518 {
3519 code: "do;while(a)\nfoo()",
3520 output: "do;while(a)\n\nfoo()",
3521 options: [
3522 { blankLine: "always", prev: "do", next: "*" }
3523 ],
3524 errors: [{ messageId: "expectedBlankLine" }]
3525 },
3526
3527 //----------------------------------------------------------------------
3528 // export
3529 //----------------------------------------------------------------------
3530
3531 {
3532 code: "export default 1\n\nfoo()",
3533 output: "export default 1\nfoo()",
3534 options: [
3535 { blankLine: "never", prev: "export", next: "*" }
3536 ],
3537 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3538 errors: [{ messageId: "unexpectedBlankLine" }]
3539 },
3540 {
3541 code: "export let a=1\n\nfoo()",
3542 output: "export let a=1\nfoo()",
3543 options: [
3544 { blankLine: "never", prev: "export", next: "*" }
3545 ],
3546 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3547 errors: [{ messageId: "unexpectedBlankLine" }]
3548 },
3549 {
3550 code: "var a = 0;export {a}\n\nfoo()",
3551 output: "var a = 0;export {a}\nfoo()",
3552 options: [
3553 { blankLine: "never", prev: "export", next: "*" }
3554 ],
3555 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3556 errors: [{ messageId: "unexpectedBlankLine" }]
3557 },
3558 {
3559 code: "export default 1\nfoo()",
3560 output: "export default 1\n\nfoo()",
3561 options: [
3562 { blankLine: "always", prev: "export", next: "*" }
3563 ],
3564 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3565 errors: [{ messageId: "expectedBlankLine" }]
3566 },
3567 {
3568 code: "export let a=1\nfoo()",
3569 output: "export let a=1\n\nfoo()",
3570 options: [
3571 { blankLine: "always", prev: "export", next: "*" }
3572 ],
3573 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3574 errors: [{ messageId: "expectedBlankLine" }]
3575 },
3576 {
3577 code: "var a = 0;export {a}\nfoo()",
3578 output: "var a = 0;export {a}\n\nfoo()",
3579 options: [
3580 { blankLine: "always", prev: "export", next: "*" }
3581 ],
3582 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3583 errors: [{ messageId: "expectedBlankLine" }]
3584 },
3585
3586 //----------------------------------------------------------------------
3587 // for
3588 //----------------------------------------------------------------------
3589
3590 {
3591 code: "for(;;);\n\nfoo()",
3592 output: "for(;;);\nfoo()",
3593 options: [
3594 { blankLine: "never", prev: "for", next: "*" }
3595 ],
3596 errors: [{ messageId: "unexpectedBlankLine" }]
3597 },
3598 {
3599 code: "for(a in b);\n\nfoo()",
3600 output: "for(a in b);\nfoo()",
3601 options: [
3602 { blankLine: "never", prev: "for", next: "*" }
3603 ],
3604 errors: [{ messageId: "unexpectedBlankLine" }]
3605 },
3606 {
3607 code: "for(a of b);\n\nfoo()",
3608 output: "for(a of b);\nfoo()",
3609 options: [
3610 { blankLine: "never", prev: "for", next: "*" }
3611 ],
3612 errors: [{ messageId: "unexpectedBlankLine" }]
3613 },
3614 {
3615 code: "for(;;);\nfoo()",
3616 output: "for(;;);\n\nfoo()",
3617 options: [
3618 { blankLine: "always", prev: "for", next: "*" }
3619 ],
3620 errors: [{ messageId: "expectedBlankLine" }]
3621 },
3622 {
3623 code: "for(a in b);\nfoo()",
3624 output: "for(a in b);\n\nfoo()",
3625 options: [
3626 { blankLine: "always", prev: "for", next: "*" }
3627 ],
3628 errors: [{ messageId: "expectedBlankLine" }]
3629 },
3630 {
3631 code: "for(a of b);\nfoo()",
3632 output: "for(a of b);\n\nfoo()",
3633 options: [
3634 { blankLine: "always", prev: "for", next: "*" }
3635 ],
3636 errors: [{ messageId: "expectedBlankLine" }]
3637 },
3638
3639 //----------------------------------------------------------------------
3640 // function
3641 //----------------------------------------------------------------------
3642
3643 {
3644 code: "function foo(){}\n\nfoo()",
3645 output: "function foo(){}\nfoo()",
3646 options: [
3647 { blankLine: "never", prev: "function", next: "*" }
3648 ],
3649 errors: [{ messageId: "unexpectedBlankLine" }]
3650 },
3651 {
3652 code: "function foo(){}\nfoo()",
3653 output: "function foo(){}\n\nfoo()",
3654 options: [
3655 { blankLine: "always", prev: "function", next: "*" }
3656 ],
3657 errors: [{ messageId: "expectedBlankLine" }]
3658 },
3659 {
3660 code: "async function foo(){}\nfoo()",
3661 output: "async function foo(){}\n\nfoo()",
3662 options: [
3663 { blankLine: "never", prev: "*", next: "*" },
3664 { blankLine: "always", prev: "function", next: "*" }
3665 ],
3666 errors: [{ messageId: "expectedBlankLine" }]
3667 },
3668
3669 //----------------------------------------------------------------------
3670 // if
3671 //----------------------------------------------------------------------
3672
3673 {
3674 code: "if(a);\n\nfoo()",
3675 output: "if(a);\nfoo()",
3676 options: [
3677 { blankLine: "never", prev: "if", next: "*" }
3678 ],
3679 errors: [{ messageId: "unexpectedBlankLine" }]
3680 },
3681 {
3682 code: "if(a);else;\n\nfoo()",
3683 output: "if(a);else;\nfoo()",
3684 options: [
3685 { blankLine: "never", prev: "if", next: "*" }
3686 ],
3687 errors: [{ messageId: "unexpectedBlankLine" }]
3688 },
3689 {
3690 code: "if(a);\nfoo()",
3691 output: "if(a);\n\nfoo()",
3692 options: [
3693 { blankLine: "always", prev: "if", next: "*" }
3694 ],
3695 errors: [{ messageId: "expectedBlankLine" }]
3696 },
3697 {
3698 code: "if(a);else;\nfoo()",
3699 output: "if(a);else;\n\nfoo()",
3700 options: [
3701 { blankLine: "always", prev: "if", next: "*" }
3702 ],
3703 errors: [{ messageId: "expectedBlankLine" }]
3704 },
3705
3706 //----------------------------------------------------------------------
3707 // iife
3708 //----------------------------------------------------------------------
3709
3710 {
3711 code: "(function(){\n})()\n\nvar a = 2;",
3712 output: "(function(){\n})()\nvar a = 2;",
3713 options: [
3714 { blankLine: "never", prev: "iife", next: "*" }
3715 ],
3716 errors: [{ messageId: "unexpectedBlankLine" }]
3717 },
3718 {
3719 code: "+(function(){\n})()\n\nvar a = 2;",
3720 output: "+(function(){\n})()\nvar a = 2;",
3721 options: [
3722 { blankLine: "never", prev: "iife", next: "*" }
3723 ],
3724 errors: [{ messageId: "unexpectedBlankLine" }]
3725 },
3726 {
3727 code: "(function(){\n})()\nvar a = 2;",
3728 output: "(function(){\n})()\n\nvar a = 2;",
3729 options: [
3730 { blankLine: "always", prev: "iife", next: "*" }
3731 ],
3732 errors: [{ messageId: "expectedBlankLine" }]
3733 },
3734 {
3735 code: "+(function(){\n})()\nvar a = 2;",
3736 output: "+(function(){\n})()\n\nvar a = 2;",
3737 options: [
3738 { blankLine: "always", prev: "iife", next: "*" }
3739 ],
3740 errors: [{ messageId: "expectedBlankLine" }]
3741 },
3742
3743 // Optional chaining
3744 {
3745 code: "(function(){\n})?.()\nvar a = 2;",
3746 output: "(function(){\n})?.()\n\nvar a = 2;",
3747 options: [{ blankLine: "always", prev: "iife", next: "*" }],
3748 parserOptions: { ecmaVersion: 2020 },
3749 errors: [{ messageId: "expectedBlankLine" }]
3750 },
3751 {
3752 code: "void (function(){\n})?.()\nvar a = 2;",
3753 output: "void (function(){\n})?.()\n\nvar a = 2;",
3754 options: [{ blankLine: "always", prev: "iife", next: "*" }],
3755 parserOptions: { ecmaVersion: 2020 },
3756 errors: [{ messageId: "expectedBlankLine" }]
3757 },
3758
3759 //----------------------------------------------------------------------
3760 // import
3761 //----------------------------------------------------------------------
3762
3763 {
3764 code: "import a from 'a'\n\nfoo()",
3765 output: "import a from 'a'\nfoo()",
3766 options: [
3767 { blankLine: "never", prev: "import", next: "*" }
3768 ],
3769 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3770 errors: [{ messageId: "unexpectedBlankLine" }]
3771 },
3772 {
3773 code: "import * as a from 'a'\n\nfoo()",
3774 output: "import * as a from 'a'\nfoo()",
3775 options: [
3776 { blankLine: "never", prev: "import", next: "*" }
3777 ],
3778 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3779 errors: [{ messageId: "unexpectedBlankLine" }]
3780 },
3781 {
3782 code: "import {a} from 'a'\n\nfoo()",
3783 output: "import {a} from 'a'\nfoo()",
3784 options: [
3785 { blankLine: "never", prev: "import", next: "*" }
3786 ],
3787 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3788 errors: [{ messageId: "unexpectedBlankLine" }]
3789 },
3790 {
3791 code: "import a from 'a'\nfoo()",
3792 output: "import a from 'a'\n\nfoo()",
3793 options: [
3794 { blankLine: "always", prev: "import", next: "*" }
3795 ],
3796 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3797 errors: [{ messageId: "expectedBlankLine" }]
3798 },
3799 {
3800 code: "import * as a from 'a'\nfoo()",
3801 output: "import * as a from 'a'\n\nfoo()",
3802 options: [
3803 { blankLine: "always", prev: "import", next: "*" }
3804 ],
3805 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3806 errors: [{ messageId: "expectedBlankLine" }]
3807 },
3808 {
3809 code: "import {a} from 'a'\nfoo()",
3810 output: "import {a} from 'a'\n\nfoo()",
3811 options: [
3812 { blankLine: "always", prev: "import", next: "*" }
3813 ],
3814 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3815 errors: [{ messageId: "expectedBlankLine" }]
3816 },
3817
3818 //----------------------------------------------------------------------
3819 // let
3820 //----------------------------------------------------------------------
3821
3822 {
3823 code: "let a\n\nfoo()",
3824 output: "let a\nfoo()",
3825 options: [
3826 { blankLine: "never", prev: "let", next: "*" }
3827 ],
3828 errors: [{ messageId: "unexpectedBlankLine" }]
3829 },
3830 {
3831 code: "let a\nfoo()",
3832 output: "let a\n\nfoo()",
3833 options: [
3834 { blankLine: "always", prev: "let", next: "*" }
3835 ],
3836 errors: [{ messageId: "expectedBlankLine" }]
3837 },
3838
3839 //----------------------------------------------------------------------
3840 // return
3841 //----------------------------------------------------------------------
3842
3843 {
3844 code: "function foo(){return\n\nfoo()}",
3845 output: "function foo(){return\nfoo()}",
3846 options: [
3847 { blankLine: "never", prev: "return", next: "*" }
3848 ],
3849 errors: [{ messageId: "unexpectedBlankLine" }]
3850 },
3851 {
3852 code: "function foo(){return\nfoo()}",
3853 output: "function foo(){return\n\nfoo()}",
3854 options: [
3855 { blankLine: "always", prev: "return", next: "*" }
3856 ],
3857 errors: [{ messageId: "expectedBlankLine" }]
3858 },
3859
3860 //----------------------------------------------------------------------
3861 // switch
3862 //----------------------------------------------------------------------
3863
3864 {
3865 code: "switch(a){}\n\nfoo()",
3866 output: "switch(a){}\nfoo()",
3867 options: [
3868 { blankLine: "never", prev: "switch", next: "*" }
3869 ],
3870 errors: [{ messageId: "unexpectedBlankLine" }]
3871 },
3872 {
3873 code: "switch(a){}\nfoo()",
3874 output: "switch(a){}\n\nfoo()",
3875 options: [
3876 { blankLine: "always", prev: "switch", next: "*" }
3877 ],
3878 errors: [{ messageId: "expectedBlankLine" }]
3879 },
3880
3881 //----------------------------------------------------------------------
3882 // throw
3883 //----------------------------------------------------------------------
3884
3885 {
3886 code: "throw a\n\nfoo()",
3887 output: "throw a\nfoo()",
3888 options: [
3889 { blankLine: "never", prev: "throw", next: "*" }
3890 ],
3891 errors: [{ messageId: "unexpectedBlankLine" }]
3892 },
3893 {
3894 code: "throw a\nfoo()",
3895 output: "throw a\n\nfoo()",
3896 options: [
3897 { blankLine: "always", prev: "throw", next: "*" }
3898 ],
3899 errors: [{ messageId: "expectedBlankLine" }]
3900 },
3901
3902 //----------------------------------------------------------------------
3903 // try
3904 //----------------------------------------------------------------------
3905
3906 {
3907 code: "try{}catch(e){}\n\nfoo()",
3908 output: "try{}catch(e){}\nfoo()",
3909 options: [
3910 { blankLine: "never", prev: "try", next: "*" }
3911 ],
3912 errors: [{ messageId: "unexpectedBlankLine" }]
3913 },
3914 {
3915 code: "try{}finally{}\n\nfoo()",
3916 output: "try{}finally{}\nfoo()",
3917 options: [
3918 { blankLine: "never", prev: "try", next: "*" }
3919 ],
3920 errors: [{ messageId: "unexpectedBlankLine" }]
3921 },
3922 {
3923 code: "try{}catch(e){}finally{}\n\nfoo()",
3924 output: "try{}catch(e){}finally{}\nfoo()",
3925 options: [
3926 { blankLine: "never", prev: "try", next: "*" }
3927 ],
3928 errors: [{ messageId: "unexpectedBlankLine" }]
3929 },
3930 {
3931 code: "try{}catch(e){}\nfoo()",
3932 output: "try{}catch(e){}\n\nfoo()",
3933 options: [
3934 { blankLine: "always", prev: "try", next: "*" }
3935 ],
3936 errors: [{ messageId: "expectedBlankLine" }]
3937 },
3938 {
3939 code: "try{}finally{}\nfoo()",
3940 output: "try{}finally{}\n\nfoo()",
3941 options: [
3942 { blankLine: "always", prev: "try", next: "*" }
3943 ],
3944 errors: [{ messageId: "expectedBlankLine" }]
3945 },
3946 {
3947 code: "try{}catch(e){}finally{}\nfoo()",
3948 output: "try{}catch(e){}finally{}\n\nfoo()",
3949 options: [
3950 { blankLine: "always", prev: "try", next: "*" }
3951 ],
3952 errors: [{ messageId: "expectedBlankLine" }]
3953 },
3954
3955 //----------------------------------------------------------------------
3956 // var
3957 //----------------------------------------------------------------------
3958
3959 {
3960 code: "var a\n\nfoo()",
3961 output: "var a\nfoo()",
3962 options: [
3963 { blankLine: "never", prev: "var", next: "*" }
3964 ],
3965 errors: [{ messageId: "unexpectedBlankLine" }]
3966 },
3967 {
3968 code: "var a\nfoo()",
3969 output: "var a\n\nfoo()",
3970 options: [
3971 { blankLine: "always", prev: "var", next: "*" }
3972 ],
3973 errors: [{ messageId: "expectedBlankLine" }]
3974 },
3975
3976 //----------------------------------------------------------------------
3977 // while
3978 //----------------------------------------------------------------------
3979
3980 {
3981 code: "while(a);\n\nfoo()",
3982 output: "while(a);\nfoo()",
3983 options: [
3984 { blankLine: "never", prev: "while", next: "*" }
3985 ],
3986 errors: [{ messageId: "unexpectedBlankLine" }]
3987 },
3988 {
3989 code: "while(a);\nfoo()",
3990 output: "while(a);\n\nfoo()",
3991 options: [
3992 { blankLine: "always", prev: "while", next: "*" }
3993 ],
3994 errors: [{ messageId: "expectedBlankLine" }]
3995 },
3996
3997 //----------------------------------------------------------------------
3998 // with
3999 //----------------------------------------------------------------------
4000
4001 {
4002 code: "with(a);\n\nfoo()",
4003 output: "with(a);\nfoo()",
4004 options: [
4005 { blankLine: "never", prev: "with", next: "*" }
4006 ],
4007 errors: [{ messageId: "unexpectedBlankLine" }]
4008 },
4009 {
4010 code: "with(a);\nfoo()",
4011 output: "with(a);\n\nfoo()",
4012 options: [
4013 { blankLine: "always", prev: "with", next: "*" }
4014 ],
4015 errors: [{ messageId: "expectedBlankLine" }]
4016 },
4017
4018 //----------------------------------------------------------------------
4019 // multiline-const
4020 //----------------------------------------------------------------------
4021
4022 {
4023 code: "const a={\nb:1,\nc:2\n}\n\nconst d=3",
4024 output: "const a={\nb:1,\nc:2\n}\nconst d=3",
4025 options: [
4026 { blankLine: "never", prev: "multiline-const", next: "*" }
4027 ],
4028 errors: [{ messageId: "unexpectedBlankLine" }]
4029 },
4030 {
4031 code: "const a={\nb:1,\nc:2\n}\nconst d=3",
4032 output: "const a={\nb:1,\nc:2\n}\n\nconst d=3",
4033 options: [
4034 { blankLine: "always", prev: "multiline-const", next: "*" }
4035 ],
4036 errors: [{ messageId: "expectedBlankLine" }]
4037 },
4038 {
4039 code: "const a=1\n\nconst b={\nc:2,\nd:3\n}",
4040 output: "const a=1\nconst b={\nc:2,\nd:3\n}",
4041 options: [
4042 { blankLine: "never", prev: "*", next: "multiline-const" }
4043 ],
4044 errors: [{ messageId: "unexpectedBlankLine" }]
4045 },
4046 {
4047 code: "const a=1\nconst b={\nc:2,\nd:3\n}",
4048 output: "const a=1\n\nconst b={\nc:2,\nd:3\n}",
4049 options: [
4050 { blankLine: "always", prev: "*", next: "multiline-const" }
4051 ],
4052 errors: [{ messageId: "expectedBlankLine" }]
4053 },
4054
4055 //----------------------------------------------------------------------
4056 // multiline-let
4057 //----------------------------------------------------------------------
4058
4059 {
4060 code: "let a={\nb:1,\nc:2\n}\n\nlet d=3",
4061 output: "let a={\nb:1,\nc:2\n}\nlet d=3",
4062 options: [
4063 { blankLine: "never", prev: "multiline-let", next: "*" }
4064 ],
4065 errors: [{ messageId: "unexpectedBlankLine" }]
4066 },
4067 {
4068 code: "let a={\nb:1,\nc:2\n}\nlet d=3",
4069 output: "let a={\nb:1,\nc:2\n}\n\nlet d=3",
4070 options: [
4071 { blankLine: "always", prev: "multiline-let", next: "*" }
4072 ],
4073 errors: [{ messageId: "expectedBlankLine" }]
4074 },
4075 {
4076 code: "let a=1\n\nlet b={\nc:2,\nd:3\n}",
4077 output: "let a=1\nlet b={\nc:2,\nd:3\n}",
4078 options: [
4079 { blankLine: "never", prev: "*", next: "multiline-let" }
4080 ],
4081 errors: [{ messageId: "unexpectedBlankLine" }]
4082 },
4083 {
4084 code: "let a=1\nlet b={\nc:2,\nd:3\n}",
4085 output: "let a=1\n\nlet b={\nc:2,\nd:3\n}",
4086 options: [
4087 { blankLine: "always", prev: "*", next: "multiline-let" }
4088 ],
4089 errors: [{ messageId: "expectedBlankLine" }]
4090 },
4091
4092 //----------------------------------------------------------------------
4093 // multiline-var
4094 //----------------------------------------------------------------------
4095
4096 {
4097 code: "var a={\nb:1,\nc:2\n}\n\nvar d=3",
4098 output: "var a={\nb:1,\nc:2\n}\nvar d=3",
4099 options: [
4100 { blankLine: "never", prev: "multiline-var", next: "*" }
4101 ],
4102 errors: [{ messageId: "unexpectedBlankLine" }]
4103 },
4104 {
4105 code: "var a={\nb:1,\nc:2\n}\nvar d=3",
4106 output: "var a={\nb:1,\nc:2\n}\n\nvar d=3",
4107 options: [
4108 { blankLine: "always", prev: "multiline-var", next: "*" }
4109 ],
4110 errors: [{ messageId: "expectedBlankLine" }]
4111 },
4112 {
4113 code: "var a=1\n\nvar b={\nc:2,\nd:3\n}",
4114 output: "var a=1\nvar b={\nc:2,\nd:3\n}",
4115 options: [
4116 { blankLine: "never", prev: "*", next: "multiline-var" }
4117 ],
4118 errors: [{ messageId: "unexpectedBlankLine" }]
4119 },
4120 {
4121 code: "var a=1\nvar b={\nc:2,\nd:3\n}",
4122 output: "var a=1\n\nvar b={\nc:2,\nd:3\n}",
4123 options: [
4124 { blankLine: "always", prev: "*", next: "multiline-var" }
4125 ],
4126 errors: [{ messageId: "expectedBlankLine" }]
4127 },
4128
4129 //----------------------------------------------------------------------
4130 // singleline-const
4131 //----------------------------------------------------------------------
4132
4133 {
4134 code: "const a=1\n\nconst b=2",
4135 output: "const a=1\nconst b=2",
4136 options: [
4137 { blankLine: "never", prev: "singleline-const", next: "*" }
4138 ],
4139 errors: [{ messageId: "unexpectedBlankLine" }]
4140 },
4141 {
4142 code: "const a=1\nconst b=2",
4143 output: "const a=1\n\nconst b=2",
4144 options: [
4145 { blankLine: "always", prev: "singleline-const", next: "*" }
4146 ],
4147 errors: [{ messageId: "expectedBlankLine" }]
4148 },
4149 {
4150 code: "const a=1\n\nconst b=2",
4151 output: "const a=1\nconst b=2",
4152 options: [
4153 { blankLine: "never", prev: "*", next: "singleline-const" }
4154 ],
4155 errors: [{ messageId: "unexpectedBlankLine" }]
4156 },
4157 {
4158 code: "const a=1\nconst b=2",
4159 output: "const a=1\n\nconst b=2",
4160 options: [
4161 { blankLine: "always", prev: "*", next: "singleline-const" }
4162 ],
4163 errors: [{ messageId: "expectedBlankLine" }]
4164 },
4165
4166 //----------------------------------------------------------------------
4167 // singleline-let
4168 //----------------------------------------------------------------------
4169
4170 {
4171 code: "let a=1\n\nlet b=2",
4172 output: "let a=1\nlet b=2",
4173 options: [
4174 { blankLine: "never", prev: "singleline-let", next: "*" }
4175 ],
4176 errors: [{ messageId: "unexpectedBlankLine" }]
4177 },
4178 {
4179 code: "let a=1\nlet b=2",
4180 output: "let a=1\n\nlet b=2",
4181 options: [
4182 { blankLine: "always", prev: "singleline-let", next: "*" }
4183 ],
4184 errors: [{ messageId: "expectedBlankLine" }]
4185 },
4186 {
4187 code: "let a=1\n\nlet b=2",
4188 output: "let a=1\nlet b=2",
4189 options: [
4190 { blankLine: "never", prev: "*", next: "singleline-let" }
4191 ],
4192 errors: [{ messageId: "unexpectedBlankLine" }]
4193 },
4194 {
4195 code: "let a=1\nlet b=2",
4196 output: "let a=1\n\nlet b=2",
4197 options: [
4198 { blankLine: "always", prev: "*", next: "singleline-let" }
4199 ],
4200 errors: [{ messageId: "expectedBlankLine" }]
4201 },
4202
4203 //----------------------------------------------------------------------
4204 // singleline-var
4205 //----------------------------------------------------------------------
4206
4207 {
4208 code: "var a=1\n\nvar b=2",
4209 output: "var a=1\nvar b=2",
4210 options: [
4211 { blankLine: "never", prev: "singleline-var", next: "*" }
4212 ],
4213 errors: [{ messageId: "unexpectedBlankLine" }]
4214 },
4215 {
4216 code: "var a=1\nvar b=2",
4217 output: "var a=1\n\nvar b=2",
4218 options: [
4219 { blankLine: "always", prev: "singleline-var", next: "*" }
4220 ],
4221 errors: [{ messageId: "expectedBlankLine" }]
4222 },
4223 {
4224 code: "var a=1\n\nvar b=2",
4225 output: "var a=1\nvar b=2",
4226 options: [
4227 { blankLine: "never", prev: "*", next: "singleline-var" }
4228 ],
4229 errors: [{ messageId: "unexpectedBlankLine" }]
4230 },
4231 {
4232 code: "var a=1\nvar b=2",
4233 output: "var a=1\n\nvar b=2",
4234 options: [
4235 { blankLine: "always", prev: "*", next: "singleline-var" }
4236 ],
4237 errors: [{ messageId: "expectedBlankLine" }]
4238 },
4239
4240 //----------------------------------------------------------------------
4241 // Tests from newline-after-var
4242 //----------------------------------------------------------------------
4243
4244 // should disallow no line break in "always" mode
4245 {
4246 code: "var greet = 'hello';console.log(greet);",
4247 output: "var greet = 'hello';\n\nconsole.log(greet);",
4248 options: [
4249 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4250 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4251 ],
4252 errors: [{ messageId: "expectedBlankLine" }]
4253 },
4254 {
4255 code: "var greet = 'hello';var name = 'world';console.log(greet, name);",
4256 output: "var greet = 'hello';var name = 'world';\n\nconsole.log(greet, name);",
4257 options: [
4258 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4259 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4260 ],
4261 errors: [{ messageId: "expectedBlankLine" }]
4262 },
4263 {
4264 code: "var greet = 'hello', name = 'world';console.log(greet, name);",
4265 output: "var greet = 'hello', name = 'world';\n\nconsole.log(greet, name);",
4266 options: [
4267 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4268 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4269 ],
4270 errors: [{ messageId: "expectedBlankLine" }]
4271 },
4272
4273 // should disallow no blank line in "always" mode
4274 {
4275 code: "var greet = 'hello';\nconsole.log(greet);",
4276 output: "var greet = 'hello';\n\nconsole.log(greet);",
4277 options: [
4278 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4279 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4280 ],
4281 errors: [{ messageId: "expectedBlankLine" }]
4282 },
4283 {
4284 code: "var greet = 'hello'; \nconsole.log(greet);",
4285 output: "var greet = 'hello';\n \nconsole.log(greet);",
4286 options: [
4287 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4288 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4289 ],
4290 errors: [{ messageId: "expectedBlankLine" }]
4291 },
4292 {
4293 code: "var greet = 'hello'; // inline comment\nconsole.log(greet);",
4294 output: "var greet = 'hello'; // inline comment\n\nconsole.log(greet);",
4295 options: [
4296 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4297 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4298 ],
4299 errors: [{ messageId: "expectedBlankLine" }]
4300 },
4301 {
4302 code: "var greet = 'hello';\nvar name = 'world';\nconsole.log(greet, name);",
4303 output: "var greet = 'hello';\nvar name = 'world';\n\nconsole.log(greet, name);",
4304 options: [
4305 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4306 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4307 ],
4308 errors: [{ messageId: "expectedBlankLine" }]
4309 },
4310 {
4311 code: "var greet = 'hello', name = 'world';\nconsole.log(greet, name);",
4312 output: "var greet = 'hello', name = 'world';\n\nconsole.log(greet, name);",
4313 options: [
4314 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4315 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4316 ],
4317 errors: [{ messageId: "expectedBlankLine" }]
4318 },
4319 {
4320 code: "var greet = 'hello',\nname = 'world';\nconsole.log(greet, name);",
4321 output: "var greet = 'hello',\nname = 'world';\n\nconsole.log(greet, name);",
4322 options: [
4323 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4324 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4325 ],
4326 errors: [{ messageId: "expectedBlankLine" }]
4327 },
4328 {
4329 code: "let greet = 'hello';\nconsole.log(greet);",
4330 output: "let greet = 'hello';\n\nconsole.log(greet);",
4331 options: [
4332 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4333 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4334 ],
4335 errors: [{ messageId: "expectedBlankLine" }]
4336 },
4337 {
4338 code: "const greet = 'hello';\nconsole.log(greet);",
4339 output: "const greet = 'hello';\n\nconsole.log(greet);",
4340 options: [
4341 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4342 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4343 ],
4344 errors: [{ messageId: "expectedBlankLine" }]
4345 },
4346 {
4347 code: "function example() {\nvar greet = 'hello';\nconsole.log(greet);\n}",
4348 output: "function example() {\nvar greet = 'hello';\n\nconsole.log(greet);\n}",
4349 options: [
4350 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4351 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4352 ],
4353 errors: [{ messageId: "expectedBlankLine" }]
4354 },
4355 {
4356 code: "var f = function() {\nvar greet = 'hello';\nconsole.log(greet);\n};",
4357 output: "var f = function() {\nvar greet = 'hello';\n\nconsole.log(greet);\n};",
4358 options: [
4359 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4360 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4361 ],
4362 errors: [{ messageId: "expectedBlankLine" }]
4363 },
4364 {
4365 code: "() => {\nvar greet = 'hello';\nconsole.log(greet);\n}",
4366 output: "() => {\nvar greet = 'hello';\n\nconsole.log(greet);\n}",
4367 options: [
4368 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4369 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4370 ],
4371 errors: [{ messageId: "expectedBlankLine" }]
4372 },
4373
4374 // should disallow blank lines in "never" mode
4375 {
4376 code: "var greet = 'hello';\n\nconsole.log(greet);",
4377 output: "var greet = 'hello';\nconsole.log(greet);",
4378 options: [
4379 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4380 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4381 ],
4382 errors: [{ messageId: "unexpectedBlankLine" }]
4383 },
4384 {
4385 code: "var greet = 'hello';\n\n\nconsole.log(greet);",
4386 output: "var greet = 'hello';\nconsole.log(greet);",
4387 options: [
4388 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4389 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4390 ],
4391 errors: [{ messageId: "unexpectedBlankLine" }]
4392 },
4393 {
4394 code: "var greet = 'hello';\n\n\n\nconsole.log(greet);",
4395 output: "var greet = 'hello';\nconsole.log(greet);",
4396 options: [
4397 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4398 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4399 ],
4400 errors: [{ messageId: "unexpectedBlankLine" }]
4401 },
4402 {
4403 code: "var greet = 'hello'; \n\nconsole.log(greet);",
4404 output: "var greet = 'hello'; \nconsole.log(greet);",
4405 options: [
4406 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4407 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4408 ],
4409 errors: [{ messageId: "unexpectedBlankLine" }]
4410 },
4411 {
4412 code: "var greet = 'hello'; // inline comment\n\nconsole.log(greet);",
4413 output: "var greet = 'hello'; // inline comment\nconsole.log(greet);",
4414 options: [
4415 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4416 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4417 ],
4418 errors: [{ messageId: "unexpectedBlankLine" }]
4419 },
4420 {
4421 code: "var greet = 'hello';\nvar name = 'world';\n\nconsole.log(greet, name);",
4422 output: "var greet = 'hello';\nvar name = 'world';\nconsole.log(greet, name);",
4423 options: [
4424 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4425 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4426 ],
4427 errors: [{ messageId: "unexpectedBlankLine" }]
4428 },
4429 {
4430 code: "var greet = 'hello', name = 'world';\n\nconsole.log(greet, name);",
4431 output: "var greet = 'hello', name = 'world';\nconsole.log(greet, name);",
4432 options: [
4433 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4434 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4435 ],
4436 errors: [{ messageId: "unexpectedBlankLine" }]
4437 },
4438 {
4439 code: "var greet = 'hello',\nname = 'world';\n\nconsole.log(greet, name);",
4440 output: "var greet = 'hello',\nname = 'world';\nconsole.log(greet, name);",
4441 options: [
4442 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4443 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4444 ],
4445 errors: [{ messageId: "unexpectedBlankLine" }]
4446 },
4447 {
4448 code: "var greet = 'hello', // inline comment\nname = 'world'; // inline comment\n\nconsole.log(greet, name);",
4449 output: "var greet = 'hello', // inline comment\nname = 'world'; // inline comment\nconsole.log(greet, name);",
4450 options: [
4451 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4452 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4453 ],
4454 errors: [{ messageId: "unexpectedBlankLine" }]
4455 },
4456 {
4457 code: "let greet = 'hello';\n\nconsole.log(greet);",
4458 output: "let greet = 'hello';\nconsole.log(greet);",
4459 options: [
4460 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4461 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4462 ],
4463 errors: [{ messageId: "unexpectedBlankLine" }]
4464 },
4465 {
4466 code: "const greet = 'hello';\n\nconsole.log(greet);",
4467 output: "const greet = 'hello';\nconsole.log(greet);",
4468 options: [
4469 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4470 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4471 ],
4472 errors: [{ messageId: "unexpectedBlankLine" }]
4473 },
4474
4475 // should disallow a comment on the next line that's not in turn followed by a blank in "always" mode
4476 {
4477 code: "var greet = 'hello';\n// next-line comment\nconsole.log(greet);",
4478 output: "var greet = 'hello';\n\n// next-line comment\nconsole.log(greet);",
4479 options: [
4480 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4481 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4482 ],
4483 errors: [{ messageId: "expectedBlankLine" }]
4484 },
4485 {
4486 code: "var greet = 'hello';\n/* block comment\nblock comment */\nconsole.log(greet);",
4487 output: "var greet = 'hello';\n\n/* block comment\nblock comment */\nconsole.log(greet);",
4488 options: [
4489 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4490 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4491 ],
4492 errors: [{ messageId: "expectedBlankLine" }]
4493 },
4494 {
4495 code: "var greet = 'hello',\nname = 'world';\n// next-line comment\nconsole.log(greet);",
4496 output: "var greet = 'hello',\nname = 'world';\n\n// next-line comment\nconsole.log(greet);",
4497 options: [
4498 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4499 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4500 ],
4501 errors: [{ messageId: "expectedBlankLine" }]
4502 },
4503 {
4504 code: "var greet = 'hello',\nname = 'world';\n/* block comment\nblock comment */\nconsole.log(greet);",
4505 output: "var greet = 'hello',\nname = 'world';\n\n/* block comment\nblock comment */\nconsole.log(greet);",
4506 options: [
4507 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4508 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4509 ],
4510 errors: [{ messageId: "expectedBlankLine" }]
4511 },
4512 {
4513 code: "var greet = 'hello';\n// next-line comment\n// second-line comment\nconsole.log(greet);",
4514 output: "var greet = 'hello';\n\n// next-line comment\n// second-line comment\nconsole.log(greet);",
4515 options: [
4516 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4517 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4518 ],
4519 errors: [{ messageId: "expectedBlankLine" }]
4520 },
4521 {
4522 code: "var greet = 'hello';\n// next-line comment\n/* block comment\nblock comment */\nconsole.log(greet);",
4523 output: "var greet = 'hello';\n\n// next-line comment\n/* block comment\nblock comment */\nconsole.log(greet);",
4524 options: [
4525 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4526 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4527 ],
4528 errors: [{ messageId: "expectedBlankLine" }]
4529 },
4530
4531 // https://github.com/eslint/eslint/issues/6834
4532 {
4533 code: `
4534 var a = 1
4535 ;(b || c).doSomething()
4536 `,
4537 output: `
4538 var a = 1
4539
4540 ;(b || c).doSomething()
4541 `,
4542 options: [
4543 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4544 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4545 ],
4546 errors: [{ messageId: "expectedBlankLine" }]
4547 },
4548 {
4549 code: `
4550 var a = 1
4551
4552 ;(b || c).doSomething()
4553 `,
4554 output: `
4555 var a = 1
4556 ;(b || c).doSomething()
4557 `,
4558 options: [
4559 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4560 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4561 ],
4562 errors: [{ messageId: "unexpectedBlankLine" }]
4563 },
4564
4565 //----------------------------------------------------------------------
4566 // Tests from newline-before-return
4567 //----------------------------------------------------------------------
4568
4569 {
4570 code: "function a() {\nvar b; return;\n}",
4571 output: "function a() {\nvar b;\n\n return;\n}",
4572 options: [
4573 { blankLine: "always", prev: "*", next: "return" }
4574 ],
4575 errors: [{ messageId: "expectedBlankLine" }]
4576 },
4577 {
4578 code: "function a() {\nvar b;\nreturn;\n}",
4579 output: "function a() {\nvar b;\n\nreturn;\n}",
4580 options: [
4581 { blankLine: "always", prev: "*", next: "return" }
4582 ],
4583 errors: [{ messageId: "expectedBlankLine" }]
4584 },
4585 {
4586 code: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\ne();\nreturn d;\n}\n}",
4587 output: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\ne();\n\nreturn d;\n}\n}",
4588 options: [
4589 { blankLine: "always", prev: "*", next: "return" }
4590 ],
4591 errors: [{ messageId: "expectedBlankLine" }]
4592 },
4593 {
4594 code: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\ne(); return d;\n}\n}",
4595 output: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\ne();\n\n return d;\n}\n}",
4596 options: [
4597 { blankLine: "always", prev: "*", next: "return" }
4598 ],
4599 errors: [{ messageId: "expectedBlankLine" }]
4600 },
4601 {
4602 code: "function a() {\n while (b) {\nc();\nreturn;\n}\n}",
4603 output: "function a() {\n while (b) {\nc();\n\nreturn;\n}\n}",
4604 options: [
4605 { blankLine: "always", prev: "*", next: "return" }
4606 ],
4607 errors: [{ messageId: "expectedBlankLine" }]
4608 },
4609 {
4610 code: "function a() {\ndo {\nc();\nreturn;\n} while (b);\n}",
4611 output: "function a() {\ndo {\nc();\n\nreturn;\n} while (b);\n}",
4612 options: [
4613 { blankLine: "always", prev: "*", next: "return" }
4614 ],
4615 errors: [{ messageId: "expectedBlankLine" }]
4616 },
4617 {
4618 code: "function a() {\nfor (var b; b < c; b++) {\nc();\nreturn;\n}\n}",
4619 output: "function a() {\nfor (var b; b < c; b++) {\nc();\n\nreturn;\n}\n}",
4620 options: [
4621 { blankLine: "always", prev: "*", next: "return" }
4622 ],
4623 errors: [{ messageId: "expectedBlankLine" }]
4624 },
4625 {
4626 code: "function a() {\nfor (b in c) {\nd();\nreturn;\n}\n}",
4627 output: "function a() {\nfor (b in c) {\nd();\n\nreturn;\n}\n}",
4628 options: [
4629 { blankLine: "always", prev: "*", next: "return" }
4630 ],
4631 errors: [{ messageId: "expectedBlankLine" }]
4632 },
4633 {
4634 code: "function a() {\nfor (b of c) {\nd();\nreturn;\n}\n}",
4635 output: "function a() {\nfor (b of c) {\nd();\n\nreturn;\n}\n}",
4636 options: [
4637 { blankLine: "always", prev: "*", next: "return" }
4638 ],
4639 errors: [{ messageId: "expectedBlankLine" }]
4640 },
4641 {
4642 code: "function a() {\nif (b) {\nc();\n}\n//comment\nreturn b;\n}",
4643 output: "function a() {\nif (b) {\nc();\n}\n\n//comment\nreturn b;\n}",
4644 options: [
4645 { blankLine: "always", prev: "*", next: "return" }
4646 ],
4647 errors: [{ messageId: "expectedBlankLine" }]
4648 },
4649 {
4650 code: "function a() {\n/*comment\ncomment*/\nif (b) {\nc();\nreturn b;\n} else {\n//comment\n\nreturn d;\n}\n/*multi-line\ncomment*/\nreturn e;\n}",
4651 output: "function a() {\n/*comment\ncomment*/\nif (b) {\nc();\n\nreturn b;\n} else {\n//comment\n\nreturn d;\n}\n\n/*multi-line\ncomment*/\nreturn e;\n}",
4652 options: [
4653 { blankLine: "always", prev: "*", next: "return" }
4654 ],
4655 errors: [{ messageId: "expectedBlankLine" }, { messageId: "expectedBlankLine" }]
4656 },
4657 {
4658 code: "function a() {\nif (b) { return; } //comment\nreturn c;\n}",
4659 output: "function a() {\nif (b) { return; } //comment\n\nreturn c;\n}",
4660 options: [
4661 { blankLine: "always", prev: "*", next: "return" }
4662 ],
4663 errors: [{ messageId: "expectedBlankLine" }]
4664 },
4665 {
4666 code: "function a() {\nif (b) { return; } /*multi-line\ncomment*/\nreturn c;\n}",
4667 output: "function a() {\nif (b) { return; } /*multi-line\ncomment*/\n\nreturn c;\n}",
4668 options: [
4669 { blankLine: "always", prev: "*", next: "return" }
4670 ],
4671 errors: [{ messageId: "expectedBlankLine" }]
4672 },
4673 {
4674 code: "function a() {\nif (b) { return; }\n/*multi-line\ncomment*/ return c;\n}",
4675 output: "function a() {\nif (b) { return; }\n\n/*multi-line\ncomment*/ return c;\n}",
4676 options: [
4677 { blankLine: "always", prev: "*", next: "return" }
4678 ],
4679 errors: [{ messageId: "expectedBlankLine" }]
4680 },
4681 {
4682 code: "function a() {\nif (b) { return; } /*multi-line\ncomment*/ return c;\n}",
4683 output: "function a() {\nif (b) { return; } /*multi-line\ncomment*/\n\n return c;\n}",
4684 options: [
4685 { blankLine: "always", prev: "*", next: "return" }
4686 ],
4687 errors: [{ messageId: "expectedBlankLine" }]
4688 },
4689 {
4690 code: "var a;\nreturn;",
4691 output: "var a;\n\nreturn;",
4692 options: [
4693 { blankLine: "always", prev: "*", next: "return" }
4694 ],
4695 parserOptions: { ecmaFeatures: { globalReturn: true } },
4696 errors: [{ messageId: "expectedBlankLine" }]
4697 },
4698 {
4699 code: "var a; return;",
4700 output: "var a;\n\n return;",
4701 options: [
4702 { blankLine: "always", prev: "*", next: "return" }
4703 ],
4704 parserOptions: { ecmaFeatures: { globalReturn: true } },
4705 errors: [{ messageId: "expectedBlankLine" }]
4706 },
4707 {
4708 code: "function a() {\n{\n//comment\n}\nreturn\n}",
4709 output: "function a() {\n{\n//comment\n}\n\nreturn\n}",
4710 options: [
4711 { blankLine: "always", prev: "*", next: "return" }
4712 ],
4713 errors: [{ messageId: "expectedBlankLine" }]
4714 },
4715 {
4716 code: "function a() {\n{\n//comment\n} return\n}",
4717 output: "function a() {\n{\n//comment\n}\n\n return\n}",
4718 options: [
4719 { blankLine: "always", prev: "*", next: "return" }
4720 ],
4721 errors: [{ messageId: "expectedBlankLine" }]
4722 },
4723 {
4724 code: "function a() {\nvar c;\nwhile (b) {\n c = d; //comment\n}\nreturn c;\n}",
4725 output: "function a() {\nvar c;\nwhile (b) {\n c = d; //comment\n}\n\nreturn c;\n}",
4726 options: [
4727 { blankLine: "always", prev: "*", next: "return" }
4728 ],
4729 errors: [{ messageId: "expectedBlankLine" }]
4730 },
4731 {
4732 code: "function a() {\nfor (var b; b < c; b++) {\nif (d) {\nbreak; //comment\n}\nreturn;\n}\n}",
4733 output: "function a() {\nfor (var b; b < c; b++) {\nif (d) {\nbreak; //comment\n}\n\nreturn;\n}\n}",
4734 options: [
4735 { blankLine: "always", prev: "*", next: "return" }
4736 ],
4737 errors: [{ messageId: "expectedBlankLine" }]
4738 },
4739 {
4740 code: "function a() {\nvar b; /*multi-line\ncomment*/\nreturn c;\n}",
4741 output: "function a() {\nvar b; /*multi-line\ncomment*/\n\nreturn c;\n}",
4742 options: [
4743 { blankLine: "always", prev: "*", next: "return" }
4744 ],
4745 errors: [{ messageId: "expectedBlankLine" }]
4746 },
4747 {
4748 code: "function a() {\nvar b;\n/*multi-line\ncomment*/ return c;\n}",
4749 output: "function a() {\nvar b;\n\n/*multi-line\ncomment*/ return c;\n}",
4750 options: [
4751 { blankLine: "always", prev: "*", next: "return" }
4752 ],
4753 errors: [{ messageId: "expectedBlankLine" }]
4754 },
4755 {
4756 code: "function a() {\nvar b; /*multi-line\ncomment*/ return c;\n}",
4757 output: "function a() {\nvar b; /*multi-line\ncomment*/\n\n return c;\n}",
4758 options: [
4759 { blankLine: "always", prev: "*", next: "return" }
4760 ],
4761 errors: [{ messageId: "expectedBlankLine" }]
4762 },
4763 {
4764 code: "function a() {\nvar b;\n//comment\nreturn;\n}",
4765 output: "function a() {\nvar b;\n\n//comment\nreturn;\n}",
4766 options: [
4767 { blankLine: "always", prev: "*", next: "return" }
4768 ],
4769 errors: [{ messageId: "expectedBlankLine" }]
4770 },
4771 {
4772 code: "function a() {\nvar b; //comment\nreturn;\n}",
4773 output: "function a() {\nvar b; //comment\n\nreturn;\n}",
4774 options: [
4775 { blankLine: "always", prev: "*", next: "return" }
4776 ],
4777 errors: [{ messageId: "expectedBlankLine" }]
4778 },
4779 {
4780 code: "function a() {\nvar b;\n/* comment */ return;\n}",
4781 output: "function a() {\nvar b;\n\n/* comment */ return;\n}",
4782 options: [
4783 { blankLine: "always", prev: "*", next: "return" }
4784 ],
4785 errors: [{ messageId: "expectedBlankLine" }]
4786 },
4787 {
4788 code: "function a() {\nvar b;\n//comment\n/* comment */ return;\n}",
4789 output: "function a() {\nvar b;\n\n//comment\n/* comment */ return;\n}",
4790 options: [
4791 { blankLine: "always", prev: "*", next: "return" }
4792 ],
4793 errors: [{ messageId: "expectedBlankLine" }]
4794 },
4795 {
4796 code: "function a() {\nvar b; /* comment */ return;\n}",
4797 output: "function a() {\nvar b; /* comment */\n\n return;\n}",
4798 options: [
4799 { blankLine: "always", prev: "*", next: "return" }
4800 ],
4801 errors: [{ messageId: "expectedBlankLine" }]
4802 },
4803 {
4804 code: "function a() {\nvar b; /* comment */\nreturn;\n}",
4805 output: "function a() {\nvar b; /* comment */\n\nreturn;\n}",
4806 options: [
4807 { blankLine: "always", prev: "*", next: "return" }
4808 ],
4809 errors: [{ messageId: "expectedBlankLine" }]
4810 },
4811 {
4812 code: "function a() {\nvar b;\nreturn; //comment\n}",
4813 output: "function a() {\nvar b;\n\nreturn; //comment\n}",
4814 options: [
4815 { blankLine: "always", prev: "*", next: "return" }
4816 ],
4817 errors: [{ messageId: "expectedBlankLine" }]
4818 },
4819 {
4820 code: "function a() {\nvar b; return; //comment\n}",
4821 output: "function a() {\nvar b;\n\n return; //comment\n}",
4822 options: [
4823 { blankLine: "always", prev: "*", next: "return" }
4824 ],
4825 errors: [{ messageId: "expectedBlankLine" }]
4826 },
4827
4828 //----------------------------------------------------------------------
4829 // From JSCS disallowPaddingNewLinesAfterBlocks
4830 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/disallow-padding-newlines-after-blocks.js
4831 //----------------------------------------------------------------------
4832
4833 {
4834 code: "if(true){}\n\nvar a = 2;",
4835 output: "if(true){}\nvar a = 2;",
4836 options: [
4837 { blankLine: "never", prev: "block-like", next: "*" }
4838 ],
4839 errors: [{ messageId: "unexpectedBlankLine" }]
4840 },
4841 {
4842 code: "if(true){\nif(true) {}\n\nvar a = 2;}",
4843 output: "if(true){\nif(true) {}\nvar a = 2;}",
4844 options: [
4845 { blankLine: "never", prev: "block-like", next: "*" }
4846 ],
4847 errors: [{ messageId: "unexpectedBlankLine" }]
4848 },
4849 {
4850 code: "(function(){\n})()\n\nvar a = 2;",
4851 output: "(function(){\n})()\nvar a = 2;",
4852 options: [
4853 { blankLine: "never", prev: "block-like", next: "*" }
4854 ],
4855 errors: [{ messageId: "unexpectedBlankLine" }]
4856 },
4857 {
4858 code: "+(function(){\n})()\n\nvar a = 2;",
4859 output: "+(function(){\n})()\nvar a = 2;",
4860 options: [
4861 { blankLine: "never", prev: "block-like", next: "*" }
4862 ],
4863 errors: [{ messageId: "unexpectedBlankLine" }]
4864 },
4865 {
4866 code: "var a = function() {};\n\nvar b = 2;",
4867 output: "var a = function() {};\nvar b = 2;",
4868 options: [
4869 { blankLine: "never", prev: "block-like", next: "*" }
4870 ],
4871 errors: [{ messageId: "unexpectedBlankLine" }]
4872 },
4873
4874 //----------------------------------------------------------------------
4875 // From JSCS disallowPaddingNewLinesBeforeExport
4876 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/disallow-padding-newlines-before-export.js
4877 //----------------------------------------------------------------------
4878
4879 {
4880 code: "var a = 2;\n\nmodule.exports = a;",
4881 output: "var a = 2;\nmodule.exports = a;",
4882 options: [
4883 { blankLine: "never", prev: "*", next: "cjs-export" }
4884 ],
4885 errors: [{ messageId: "unexpectedBlankLine" }]
4886 },
4887
4888 //----------------------------------------------------------------------
4889 // From JSCS disallowPaddingNewLinesBeforeExport
4890 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/disallow-padding-newlines-before-keywords.js
4891 //----------------------------------------------------------------------
4892
4893 {
4894 code: "function x() { var a;\n\nreturn; }",
4895 output: "function x() { var a;\nreturn; }",
4896 options: [
4897 { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] }
4898 ],
4899 errors: [{ messageId: "unexpectedBlankLine" }]
4900 },
4901 {
4902 code: "function x() { var a = true;\n\nif (a) { a = !a; }; }",
4903 output: "function x() { var a = true;\nif (a) { a = !a; }; }",
4904 options: [
4905 { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] }
4906 ],
4907 errors: [{ messageId: "unexpectedBlankLine" }]
4908 },
4909 {
4910 code: "function x() { var a = true;\n\nfor (var i = 0; i < 10; i++) { a = !a; }; }",
4911 output: "function x() { var a = true;\nfor (var i = 0; i < 10; i++) { a = !a; }; }",
4912 options: [
4913 { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] }
4914 ],
4915 errors: [{ messageId: "unexpectedBlankLine" }]
4916 },
4917 {
4918 code: "function x() { var y = true;\n\nswitch (\"Oranges\") { case \"Oranges\": y = !y;\n\nbreak;\n\ncase \"Apples\": y = !y;\n\nbreak; default: y = !y; } }",
4919 output: "function x() { var y = true;\nswitch (\"Oranges\") { case \"Oranges\": y = !y;\nbreak;\ncase \"Apples\": y = !y;\nbreak; default: y = !y; } }",
4920 options: [
4921 { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] }
4922 ],
4923 errors: [
4924 { messageId: "unexpectedBlankLine" },
4925 { messageId: "unexpectedBlankLine" },
4926 { messageId: "unexpectedBlankLine" },
4927 { messageId: "unexpectedBlankLine" }
4928 ]
4929 },
4930 {
4931 code: "function x() {try { var a;\n\nthrow 0; } catch (e) { var b = 0;\n\nthrow e; } }",
4932 output: "function x() {try { var a;\nthrow 0; } catch (e) { var b = 0;\nthrow e; } }",
4933 options: [
4934 { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] }
4935 ],
4936 errors: [
4937 { messageId: "unexpectedBlankLine" },
4938 { messageId: "unexpectedBlankLine" }
4939 ]
4940 },
4941 {
4942 code: "function x(a) { var b = 0;\n\nif (!a) { return false; };\n\nfor (var i = 0; i < b; i++) { if (!a[i]) return false; }\n\nreturn true; }",
4943 output: "function x(a) { var b = 0;\nif (!a) { return false; };\nfor (var i = 0; i < b; i++) { if (!a[i]) return false; }\nreturn true; }",
4944 options: [
4945 { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] }
4946 ],
4947 errors: [
4948 { messageId: "unexpectedBlankLine" },
4949 { messageId: "unexpectedBlankLine" },
4950 { messageId: "unexpectedBlankLine" }
4951 ]
4952 },
4953
4954 //----------------------------------------------------------------------
4955 // From JSCS requirePaddingNewLinesAfterBlocks
4956 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/require-padding-newlines-after-blocks.js
4957 //----------------------------------------------------------------------
4958
4959 {
4960 code: "if(true){}\nvar a = 2;",
4961 output: "if(true){}\n\nvar a = 2;",
4962 options: [
4963 { blankLine: "always", prev: "block-like", next: "*" }
4964 ],
4965 errors: [{ messageId: "expectedBlankLine" }]
4966 },
4967 {
4968 code: "var a = function() {\n};\nvar b = 2;",
4969 output: "var a = function() {\n};\n\nvar b = 2;",
4970 options: [
4971 { blankLine: "always", prev: "block-like", next: "*" }
4972 ],
4973 errors: [{ messageId: "expectedBlankLine" }]
4974 },
4975 {
4976 code: "if(true){\nif(true) {}\nvar a = 2;}",
4977 output: "if(true){\nif(true) {}\n\nvar a = 2;}",
4978 options: [
4979 { blankLine: "always", prev: "block-like", next: "*" }
4980 ],
4981 errors: [{ messageId: "expectedBlankLine" }]
4982 },
4983 {
4984 code: "(function(){\n})()\nvar a = 2;",
4985 output: "(function(){\n})()\n\nvar a = 2;",
4986 options: [
4987 { blankLine: "always", prev: "block-like", next: "*" }
4988 ],
4989 errors: [{ messageId: "expectedBlankLine" }]
4990 },
4991 {
4992 code: "var a = function() {\n};\nvar b = 2;",
4993 output: "var a = function() {\n};\n\nvar b = 2;",
4994 options: [
4995 { blankLine: "always", prev: "multiline-block-like", next: "*" }
4996 ],
4997 errors: [{ messageId: "expectedBlankLine" }]
4998 },
4999 {
5000 code: "(function(){\n})()\nvar a = 2;",
5001 output: "(function(){\n})()\n\nvar a = 2;",
5002 options: [
5003 { blankLine: "always", prev: "multiline-block-like", next: "*" }
5004 ],
5005 errors: [{ messageId: "expectedBlankLine" }]
5006 },
5007
5008 //----------------------------------------------------------------------
5009 // From JSCS requirePaddingNewLinesBeforeExport
5010 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/require-padding-newlines-before-export.js
5011 //----------------------------------------------------------------------
5012
5013 {
5014 code: "var a = 2;\nmodule.exports = a;",
5015 output: "var a = 2;\n\nmodule.exports = a;",
5016 options: [
5017 { blankLine: "always", prev: "*", next: "cjs-export" }
5018 ],
5019 errors: [{ messageId: "expectedBlankLine" }]
5020 },
5021
5022 //----------------------------------------------------------------------
5023 // From JSCS requirePaddingNewlinesBeforeKeywords
5024 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/require-padding-newlines-before-keywords.js
5025 //----------------------------------------------------------------------
5026
5027 {
5028 code: "function x() { var a; return; }",
5029 output: "function x() { var a;\n\n return; }",
5030 options: [
5031 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
5032 ],
5033 errors: [{ messageId: "expectedBlankLine" }]
5034 },
5035 {
5036 code: "function x() { var a = true; for (var i = 0; i < 10; i++) { a = !a; }; }",
5037 output: "function x() { var a = true;\n\n for (var i = 0; i < 10; i++) { a = !a; }; }",
5038 options: [
5039 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
5040 ],
5041 errors: [{ messageId: "expectedBlankLine" }]
5042 },
5043 {
5044 code: "function x() { var y = true; switch (\"Oranges\") { case \"Oranges\": y = !y; break; case \"Apples\": y = !y; break; default: y = !y; } }",
5045 output: "function x() { var y = true;\n\n switch (\"Oranges\") { case \"Oranges\": y = !y;\n\n break;\n\n case \"Apples\": y = !y;\n\n break;\n\n default: y = !y; } }",
5046 options: [
5047 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
5048 ],
5049 errors: [
5050 { messageId: "expectedBlankLine" },
5051 { messageId: "expectedBlankLine" },
5052 { messageId: "expectedBlankLine" },
5053 { messageId: "expectedBlankLine" },
5054 { messageId: "expectedBlankLine" }
5055 ]
5056 },
5057 {
5058 code: "function x() { var a = true; while (!a) { a = !a; }; }",
5059 output: "function x() { var a = true;\n\n while (!a) { a = !a; }; }",
5060 options: [
5061 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
5062 ],
5063 errors: [{ messageId: "expectedBlankLine" }]
5064 },
5065 {
5066 code: "function x() {try { var a; throw 0; } catch (e) { var b = 0; throw e; } }",
5067 output: "function x() {try { var a;\n\n throw 0; } catch (e) { var b = 0;\n\n throw e; } }",
5068 options: [
5069 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
5070 ],
5071 errors: [
5072 { messageId: "expectedBlankLine" },
5073 { messageId: "expectedBlankLine" }
5074 ]
5075 },
5076 {
5077 code: "function x(a) { var b = 0; if (!a) { return false; }; for (var i = 0; i < b; i++) { if (!a[i]) return false; } return true; }",
5078 output: "function x(a) { var b = 0;\n\n if (!a) { return false; };\n\n for (var i = 0; i < b; i++) { if (!a[i]) return false; }\n\n return true; }",
5079 options: [
5080 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
5081 ],
5082 errors: [
5083 { messageId: "expectedBlankLine" },
5084 { messageId: "expectedBlankLine" },
5085 { messageId: "expectedBlankLine" }
5086 ]
5087 },
5088
5089 // class static blocks
5090 {
5091 code: "class C {\n static {\n let x;\n foo();\n }\n }",
5092 output: "class C {\n static {\n let x;\n\n foo();\n }\n }",
5093 options: [
5094 { blankLine: "always", prev: "let", next: "expression" }
5095 ],
5096 parserOptions: { ecmaVersion: 2022 },
5097 errors: [{ messageId: "expectedBlankLine" }]
5098 },
5099 {
5100 code: "class C {\n static {\n let x;\n\n foo();\n }\n }",
5101 output: "class C {\n static {\n let x;\n foo();\n }\n }",
5102 options: [
5103 { blankLine: "never", prev: "let", next: "expression" }
5104 ],
5105 parserOptions: { ecmaVersion: 2022 },
5106 errors: [{ messageId: "unexpectedBlankLine" }]
5107 },
5108 {
5109 code: "class C {\n static {\n let x;\n foo();\n const y = 1;\n }\n }",
5110 output: "class C {\n static {\n let x;\n foo();\n\n const y = 1;\n }\n }",
5111 options: [
5112 { blankLine: "always", prev: "expression", next: "const" }
5113 ],
5114 parserOptions: { ecmaVersion: 2022 },
5115 errors: [{ messageId: "expectedBlankLine" }]
5116 },
5117 {
5118 code: "class C {\n static {\n let x;\n foo();\n\n const y = 1;\n }\n }",
5119 output: "class C {\n static {\n let x;\n foo();\n const y = 1;\n }\n }",
5120 options: [
5121 { blankLine: "never", prev: "expression", next: "const" }
5122 ],
5123 parserOptions: { ecmaVersion: 2022 },
5124 errors: [{ messageId: "unexpectedBlankLine" }]
5125 },
5126 {
5127 code: "class C {\n static {\n let x;\n foo();\n const y = 1;\n const z = 1;\n }\n }",
5128 output: "class C {\n static {\n let x;\n foo();\n\n const y = 1;\n const z = 1;\n }\n }",
5129 options: [
5130 { blankLine: "always", prev: "expression", next: "const" }
5131 ],
5132 parserOptions: { ecmaVersion: 2022 },
5133 errors: [{ messageId: "expectedBlankLine" }]
5134 },
5135 {
5136 code: "class C {\n static {\n let x;\n foo();\n\n const y = 1;\n const z = 1;\n }\n }",
5137 output: "class C {\n static {\n let x;\n foo();\n const y = 1;\n const z = 1;\n }\n }",
5138 options: [
5139 { blankLine: "never", prev: "expression", next: "const" }
5140 ],
5141 parserOptions: { ecmaVersion: 2022 },
5142 errors: [{ messageId: "unexpectedBlankLine" }]
5143 },
5144 {
5145 code: "class C {\n static {\n let a = 0;\n bar();\n }\n }",
5146 output: "class C {\n static {\n let a = 0;\n\n bar();\n }\n }",
5147 options: [
5148 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
5149 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
5150 ],
5151 parserOptions: { ecmaVersion: 2022 },
5152 errors: [{ messageId: "expectedBlankLine" }]
5153 },
5154 {
5155 code: "class C { static { let x; { let y; let z; } let q; } }",
5156 output: "class C { static { let x; { let y;\n\n let z; } let q; } }",
5157 options: [
5158 { blankLine: "always", prev: "let", next: "let" }
5159 ],
5160 parserOptions: { ecmaVersion: 2022 },
5161 errors: [{ messageId: "expectedBlankLine" }]
5162 },
5163 {
5164 code: "class C { static { { let x; } let y; let z; } }",
5165 output: "class C { static { { let x; } let y;\n\n let z; } }",
5166 options: [
5167 { blankLine: "always", prev: "let", next: "let" }
5168 ],
5169 parserOptions: { ecmaVersion: 2022 },
5170 errors: [{ messageId: "expectedBlankLine" }]
5171 },
5172 {
5173 code: "class C { static { foo(); if (bar) {} } }",
5174 output: "class C { static { foo();\n\n if (bar) {} } }",
5175 options: [
5176 { blankLine: "always", prev: "expression", next: "block-like" }
5177 ],
5178 parserOptions: { ecmaVersion: 2022 },
5179 errors: [{ messageId: "expectedBlankLine" }]
5180 },
5181 {
5182 code: "class C { static { let x; } } let y;",
5183 output: "class C { static { let x; } }\n\n let y;",
5184 options: [
5185 { blankLine: "always", prev: "class", next: "let" }
5186 ],
5187 parserOptions: { ecmaVersion: 2022 },
5188 errors: [{ messageId: "expectedBlankLine" }]
5189 },
5190 {
5191 code: "class C { static { 'use strict'; let x; } }", // 'use strict'; is "espression", because class static blocks don't have directives
5192 output: "class C { static { 'use strict';\n\n let x; } }",
5193 options: [
5194 { blankLine: "always", prev: "expression", next: "let" }
5195 ],
5196 parserOptions: { ecmaVersion: 2022 },
5197 errors: [{ messageId: "expectedBlankLine" }]
5198 }
5199 ]
5200 });