]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/padding-line-between-statements.js
import 7.12.1 upstream release
[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 invalid: [
2632
2633 //----------------------------------------------------------------------
2634 // wildcard
2635 //----------------------------------------------------------------------
2636
2637 {
2638 code: "foo();\n\nfoo();",
2639 output: "foo();\nfoo();",
2640 options: [
2641 { blankLine: "never", prev: "*", next: "*" }
2642 ],
2643 errors: [{ messageId: "unexpectedBlankLine" }]
2644 },
2645 {
2646 code: "foo();\n\n//comment\nfoo();",
2647 output: "foo();\n//comment\nfoo();",
2648 options: [
2649 { blankLine: "never", prev: "*", next: "*" }
2650 ],
2651 errors: [{ messageId: "unexpectedBlankLine" }]
2652 },
2653 {
2654 code: " foo();\n \n //comment\n foo();",
2655 output: " foo();\n //comment\n foo();",
2656 options: [
2657 { blankLine: "never", prev: "*", next: "*" }
2658 ],
2659 errors: [{ messageId: "unexpectedBlankLine" }]
2660 },
2661 {
2662 code: "if (a) {}\n\nfor (;;) {}",
2663 output: "if (a) {}\nfor (;;) {}",
2664 options: [
2665 { blankLine: "never", prev: "*", next: "*" }
2666 ],
2667 errors: [{ messageId: "unexpectedBlankLine" }]
2668 },
2669 {
2670 code: "foo();\nfoo();",
2671 output: "foo();\n\nfoo();",
2672 options: [
2673 { blankLine: "always", prev: "*", next: "*" }
2674 ],
2675 errors: [{ messageId: "expectedBlankLine" }]
2676 },
2677 {
2678 code: " function a() {}\n do {} while (a)",
2679 output: " function a() {}\n\n do {} while (a)",
2680 options: [
2681 { blankLine: "always", prev: "*", next: "*" }
2682 ],
2683 errors: [{ messageId: "expectedBlankLine" }]
2684 },
2685 {
2686 code: "foo();//trailing-comment\n//comment\n//comment\nfoo();",
2687 output: "foo();//trailing-comment\n\n//comment\n//comment\nfoo();",
2688 options: [
2689 { blankLine: "always", prev: "*", next: "*" }
2690 ],
2691 errors: [{ messageId: "expectedBlankLine" }]
2692 },
2693
2694 //----------------------------------------------------------------------
2695 // block-like
2696 //----------------------------------------------------------------------
2697
2698 {
2699 code: "{}\n\nfoo()",
2700 output: "{}\nfoo()",
2701 options: [
2702 { blankLine: "never", prev: "block-like", next: "*" }
2703 ],
2704 errors: [{ messageId: "unexpectedBlankLine" }]
2705 },
2706 {
2707 code: "{}\nfoo()",
2708 output: "{}\n\nfoo()",
2709 options: [
2710 { blankLine: "always", prev: "block-like", next: "*" }
2711 ],
2712 errors: [{ messageId: "expectedBlankLine" }]
2713 },
2714 {
2715 code: "if(a){}\nfoo()",
2716 output: "if(a){}\n\nfoo()",
2717 options: [
2718 { blankLine: "always", prev: "block-like", next: "*" }
2719 ],
2720 errors: [{ messageId: "expectedBlankLine" }]
2721 },
2722 {
2723 code: "if(a){}else{}\nfoo()",
2724 output: "if(a){}else{}\n\nfoo()",
2725 options: [
2726 { blankLine: "always", prev: "block-like", next: "*" }
2727 ],
2728 errors: [{ messageId: "expectedBlankLine" }]
2729 },
2730 {
2731 code: "if(a){}else if(b){}\nfoo()",
2732 output: "if(a){}else if(b){}\n\nfoo()",
2733 options: [
2734 { blankLine: "always", prev: "block-like", next: "*" }
2735 ],
2736 errors: [{ messageId: "expectedBlankLine" }]
2737 },
2738 {
2739 code: "if(a){}else if(b){}else{}\nfoo()",
2740 output: "if(a){}else if(b){}else{}\n\nfoo()",
2741 options: [
2742 { blankLine: "always", prev: "block-like", next: "*" }
2743 ],
2744 errors: [{ messageId: "expectedBlankLine" }]
2745 },
2746 {
2747 code: "switch(a){}\nfoo()",
2748 output: "switch(a){}\n\nfoo()",
2749 options: [
2750 { blankLine: "always", prev: "block-like", next: "*" }
2751 ],
2752 errors: [{ messageId: "expectedBlankLine" }]
2753 },
2754 {
2755 code: "switch(a){case 0:}\nfoo()",
2756 output: "switch(a){case 0:}\n\nfoo()",
2757 options: [
2758 { blankLine: "always", prev: "block-like", next: "*" }
2759 ],
2760 errors: [{ messageId: "expectedBlankLine" }]
2761 },
2762 {
2763 code: "try{}catch(e){}\nfoo()",
2764 output: "try{}catch(e){}\n\nfoo()",
2765 options: [
2766 { blankLine: "always", prev: "block-like", next: "*" }
2767 ],
2768 errors: [{ messageId: "expectedBlankLine" }]
2769 },
2770 {
2771 code: "try{}finally{}\nfoo()",
2772 output: "try{}finally{}\n\nfoo()",
2773 options: [
2774 { blankLine: "always", prev: "block-like", next: "*" }
2775 ],
2776 errors: [{ messageId: "expectedBlankLine" }]
2777 },
2778 {
2779 code: "try{}catch(e){}finally{}\nfoo()",
2780 output: "try{}catch(e){}finally{}\n\nfoo()",
2781 options: [
2782 { blankLine: "always", prev: "block-like", next: "*" }
2783 ],
2784 errors: [{ messageId: "expectedBlankLine" }]
2785 },
2786 {
2787 code: "while(a){}\nfoo()",
2788 output: "while(a){}\n\nfoo()",
2789 options: [
2790 { blankLine: "always", prev: "block-like", next: "*" }
2791 ],
2792 errors: [{ messageId: "expectedBlankLine" }]
2793 },
2794 {
2795 code: "do{}while(a)\nfoo()",
2796 output: "do{}while(a)\n\nfoo()",
2797 options: [
2798 { blankLine: "always", prev: "block-like", next: "*" }
2799 ],
2800 errors: [{ messageId: "expectedBlankLine" }]
2801 },
2802 {
2803 code: "for(;;){}\nfoo()",
2804 output: "for(;;){}\n\nfoo()",
2805 options: [
2806 { blankLine: "always", prev: "block-like", next: "*" }
2807 ],
2808 errors: [{ messageId: "expectedBlankLine" }]
2809 },
2810 {
2811 code: "for(a in b){}\nfoo()",
2812 output: "for(a in b){}\n\nfoo()",
2813 options: [
2814 { blankLine: "always", prev: "block-like", next: "*" }
2815 ],
2816 errors: [{ messageId: "expectedBlankLine" }]
2817 },
2818 {
2819 code: "for(a of b){}\nfoo()",
2820 output: "for(a of b){}\n\nfoo()",
2821 options: [
2822 { blankLine: "always", prev: "block-like", next: "*" }
2823 ],
2824 errors: [{ messageId: "expectedBlankLine" }]
2825 },
2826 {
2827 code: "a=function(){}\nfoo()",
2828 output: "a=function(){}\n\nfoo()",
2829 options: [
2830 { blankLine: "always", prev: "block-like", next: "*" }
2831 ],
2832 errors: [{ messageId: "expectedBlankLine" }]
2833 },
2834 {
2835 code: "a=()=>{}\nfoo()",
2836 output: "a=()=>{}\n\nfoo()",
2837 options: [
2838 { blankLine: "always", prev: "block-like", next: "*" }
2839 ],
2840 errors: [{ messageId: "expectedBlankLine" }]
2841 },
2842 {
2843 code: "function a(){}\nfoo()",
2844 output: "function a(){}\n\nfoo()",
2845 options: [
2846 { blankLine: "always", prev: "block-like", next: "*" }
2847 ],
2848 errors: [{ messageId: "expectedBlankLine" }]
2849 },
2850 {
2851 code: "let a=function(){}\nfoo()",
2852 output: "let a=function(){}\n\nfoo()",
2853 options: [
2854 { blankLine: "always", prev: "block-like", next: "*" }
2855 ],
2856 errors: [{ messageId: "expectedBlankLine" }]
2857 },
2858
2859 //----------------------------------------------------------------------
2860 // cjs-export
2861 //----------------------------------------------------------------------
2862
2863 {
2864 code: "module.exports=1\n\nfoo()",
2865 output: "module.exports=1\nfoo()",
2866 options: [
2867 { blankLine: "never", prev: "cjs-export", next: "*" }
2868 ],
2869 errors: [{ messageId: "unexpectedBlankLine" }]
2870 },
2871 {
2872 code: "module.exports=1\nfoo()",
2873 output: "module.exports=1\n\nfoo()",
2874 options: [
2875 { blankLine: "always", prev: "cjs-export", next: "*" }
2876 ],
2877 errors: [{ messageId: "expectedBlankLine" }]
2878 },
2879 {
2880 code: "module.exports.foo=1\nfoo()",
2881 output: "module.exports.foo=1\n\nfoo()",
2882 options: [
2883 { blankLine: "always", prev: "cjs-export", next: "*" }
2884 ],
2885 errors: [{ messageId: "expectedBlankLine" }]
2886 },
2887 {
2888 code: "module.exports[foo]=1\nfoo()",
2889 output: "module.exports[foo]=1\n\nfoo()",
2890 options: [
2891 { blankLine: "always", prev: "cjs-export", next: "*" }
2892 ],
2893 errors: [{ messageId: "expectedBlankLine" }]
2894 },
2895 {
2896 code: "exports.foo=1\nfoo()",
2897 output: "exports.foo=1\n\nfoo()",
2898 options: [
2899 { blankLine: "always", prev: "cjs-export", next: "*" }
2900 ],
2901 errors: [{ messageId: "expectedBlankLine" }]
2902 },
2903 {
2904 code: "exports[foo]=1\nfoo()",
2905 output: "exports[foo]=1\n\nfoo()",
2906 options: [
2907 { blankLine: "always", prev: "cjs-export", next: "*" }
2908 ],
2909 errors: [{ messageId: "expectedBlankLine" }]
2910 },
2911
2912 //----------------------------------------------------------------------
2913 // cjs-import
2914 //----------------------------------------------------------------------
2915
2916 {
2917 code: "const foo=require(\"foo\")\n\nfoo()",
2918 output: "const foo=require(\"foo\")\nfoo()",
2919 options: [
2920 { blankLine: "never", prev: "cjs-import", next: "*" }
2921 ],
2922 errors: [{ messageId: "unexpectedBlankLine" }]
2923 },
2924 {
2925 code: "const foo=require(\"foo\")\nfoo()",
2926 output: "const foo=require(\"foo\")\n\nfoo()",
2927 options: [
2928 { blankLine: "always", prev: "cjs-import", next: "*" }
2929 ],
2930 errors: [{ messageId: "expectedBlankLine" }]
2931 },
2932 {
2933 code: "const foo=require(\"foo\").Foo\nfoo()",
2934 output: "const foo=require(\"foo\").Foo\n\nfoo()",
2935 options: [
2936 { blankLine: "always", prev: "cjs-import", next: "*" }
2937 ],
2938 errors: [{ messageId: "expectedBlankLine" }]
2939 },
2940 {
2941 code: "const foo=require(\"foo\")[a]\nfoo()",
2942 output: "const foo=require(\"foo\")[a]\n\nfoo()",
2943 options: [
2944 { blankLine: "always", prev: "cjs-import", next: "*" }
2945 ],
2946 errors: [{ messageId: "expectedBlankLine" }]
2947 },
2948
2949 //----------------------------------------------------------------------
2950 // directive
2951 //----------------------------------------------------------------------
2952
2953 {
2954 code: "\"use strict\"\n\nfoo()",
2955 output: "\"use strict\"\nfoo()",
2956 options: [
2957 { blankLine: "never", prev: "directive", next: "*" }
2958 ],
2959 errors: [{ messageId: "unexpectedBlankLine" }]
2960 },
2961 {
2962 code: "\"use strict\"\nfoo()",
2963 output: "\"use strict\"\n\nfoo()",
2964 options: [
2965 { blankLine: "always", prev: "directive", next: "*" }
2966 ],
2967 errors: [{ messageId: "expectedBlankLine" }]
2968 },
2969 {
2970 code: "'use strict'\nfoo()",
2971 output: "'use strict'\n\nfoo()",
2972 options: [
2973 { blankLine: "always", prev: "directive", next: "*" }
2974 ],
2975 errors: [{ messageId: "expectedBlankLine" }]
2976 },
2977 {
2978 code: "'use asm'\nfoo()",
2979 output: "'use asm'\n\nfoo()",
2980 options: [
2981 { blankLine: "always", prev: "directive", next: "*" }
2982 ],
2983 errors: [{ messageId: "expectedBlankLine" }]
2984 },
2985
2986 //----------------------------------------------------------------------
2987 // multiline-block-like
2988 //----------------------------------------------------------------------
2989
2990 {
2991 code: "{\n}\n\nfoo()",
2992 output: "{\n}\nfoo()",
2993 options: [
2994 { blankLine: "never", prev: "block-like", next: "*" }
2995 ],
2996 errors: [{ messageId: "unexpectedBlankLine" }]
2997 },
2998 {
2999 code: "{\n}\nfoo()",
3000 output: "{\n}\n\nfoo()",
3001 options: [
3002 { blankLine: "always", prev: "block-like", next: "*" }
3003 ],
3004 errors: [{ messageId: "expectedBlankLine" }]
3005 },
3006 {
3007 code: "if(a){\n}\nfoo()",
3008 output: "if(a){\n}\n\nfoo()",
3009 options: [
3010 { blankLine: "always", prev: "block-like", next: "*" }
3011 ],
3012 errors: [{ messageId: "expectedBlankLine" }]
3013 },
3014 {
3015 code: "if(a){\n}else{\n}\nfoo()",
3016 output: "if(a){\n}else{\n}\n\nfoo()",
3017 options: [
3018 { blankLine: "always", prev: "block-like", next: "*" }
3019 ],
3020 errors: [{ messageId: "expectedBlankLine" }]
3021 },
3022 {
3023 code: "if(a){\n}else if(b){\n}\nfoo()",
3024 output: "if(a){\n}else if(b){\n}\n\nfoo()",
3025 options: [
3026 { blankLine: "always", prev: "block-like", next: "*" }
3027 ],
3028 errors: [{ messageId: "expectedBlankLine" }]
3029 },
3030 {
3031 code: "if(a){\n}else if(b){\n}else{\n}\nfoo()",
3032 output: "if(a){\n}else if(b){\n}else{\n}\n\nfoo()",
3033 options: [
3034 { blankLine: "always", prev: "block-like", next: "*" }
3035 ],
3036 errors: [{ messageId: "expectedBlankLine" }]
3037 },
3038 {
3039 code: "switch(a){\n}\nfoo()",
3040 output: "switch(a){\n}\n\nfoo()",
3041 options: [
3042 { blankLine: "always", prev: "block-like", next: "*" }
3043 ],
3044 errors: [{ messageId: "expectedBlankLine" }]
3045 },
3046 {
3047 code: "try{\n}catch(e){\n}\nfoo()",
3048 output: "try{\n}catch(e){\n}\n\nfoo()",
3049 options: [
3050 { blankLine: "always", prev: "block-like", next: "*" }
3051 ],
3052 errors: [{ messageId: "expectedBlankLine" }]
3053 },
3054 {
3055 code: "try{\n}finally{\n}\nfoo()",
3056 output: "try{\n}finally{\n}\n\nfoo()",
3057 options: [
3058 { blankLine: "always", prev: "block-like", next: "*" }
3059 ],
3060 errors: [{ messageId: "expectedBlankLine" }]
3061 },
3062 {
3063 code: "try{\n}catch(e){\n}finally{\n}\nfoo()",
3064 output: "try{\n}catch(e){\n}finally{\n}\n\nfoo()",
3065 options: [
3066 { blankLine: "always", prev: "block-like", next: "*" }
3067 ],
3068 errors: [{ messageId: "expectedBlankLine" }]
3069 },
3070 {
3071 code: "while(a){\n}\nfoo()",
3072 output: "while(a){\n}\n\nfoo()",
3073 options: [
3074 { blankLine: "always", prev: "block-like", next: "*" }
3075 ],
3076 errors: [{ messageId: "expectedBlankLine" }]
3077 },
3078 {
3079 code: "do{\n}while(a)\nfoo()",
3080 output: "do{\n}while(a)\n\nfoo()",
3081 options: [
3082 { blankLine: "always", prev: "block-like", next: "*" }
3083 ],
3084 errors: [{ messageId: "expectedBlankLine" }]
3085 },
3086 {
3087 code: "for(;;){\n}\nfoo()",
3088 output: "for(;;){\n}\n\nfoo()",
3089 options: [
3090 { blankLine: "always", prev: "block-like", next: "*" }
3091 ],
3092 errors: [{ messageId: "expectedBlankLine" }]
3093 },
3094 {
3095 code: "for(a in b){\n}\nfoo()",
3096 output: "for(a in b){\n}\n\nfoo()",
3097 options: [
3098 { blankLine: "always", prev: "block-like", next: "*" }
3099 ],
3100 errors: [{ messageId: "expectedBlankLine" }]
3101 },
3102 {
3103 code: "for(a of b){\n}\nfoo()",
3104 output: "for(a of b){\n}\n\nfoo()",
3105 options: [
3106 { blankLine: "always", prev: "block-like", next: "*" }
3107 ],
3108 errors: [{ messageId: "expectedBlankLine" }]
3109 },
3110 {
3111 code: "a=function(){\n}\nfoo()",
3112 output: "a=function(){\n}\n\nfoo()",
3113 options: [
3114 { blankLine: "always", prev: "block-like", next: "*" }
3115 ],
3116 errors: [{ messageId: "expectedBlankLine" }]
3117 },
3118 {
3119 code: "a=()=>{\n}\nfoo()",
3120 output: "a=()=>{\n}\n\nfoo()",
3121 options: [
3122 { blankLine: "always", prev: "block-like", next: "*" }
3123 ],
3124 errors: [{ messageId: "expectedBlankLine" }]
3125 },
3126 {
3127 code: "function a(){\n}\nfoo()",
3128 output: "function a(){\n}\n\nfoo()",
3129 options: [
3130 { blankLine: "always", prev: "block-like", next: "*" }
3131 ],
3132 errors: [{ messageId: "expectedBlankLine" }]
3133 },
3134 {
3135 code: "let a=function(){\n}\nfoo()",
3136 output: "let a=function(){\n}\n\nfoo()",
3137 options: [
3138 { blankLine: "always", prev: "block-like", next: "*" }
3139 ],
3140 errors: [{ messageId: "expectedBlankLine" }]
3141 },
3142
3143 //----------------------------------------------------------------------
3144 // block
3145 //----------------------------------------------------------------------
3146
3147 {
3148 code: "{}\n\nfoo()",
3149 output: "{}\nfoo()",
3150 options: [
3151 { blankLine: "never", prev: "block", next: "*" }
3152 ],
3153 errors: [{ messageId: "unexpectedBlankLine" }]
3154 },
3155 {
3156 code: "{}\nfoo()",
3157 output: "{}\n\nfoo()",
3158 options: [
3159 { blankLine: "always", prev: "block", next: "*" }
3160 ],
3161 errors: [{ messageId: "expectedBlankLine" }]
3162 },
3163
3164 //----------------------------------------------------------------------
3165 // empty
3166 //----------------------------------------------------------------------
3167
3168 {
3169 code: ";\n\nfoo()",
3170 output: ";\nfoo()",
3171 options: [
3172 { blankLine: "never", prev: "empty", next: "*" }
3173 ],
3174 errors: [{ messageId: "unexpectedBlankLine" }]
3175 },
3176 {
3177 code: ";\nfoo()",
3178 output: ";\n\nfoo()",
3179 options: [
3180 { blankLine: "always", prev: "empty", next: "*" }
3181 ],
3182 errors: [{ messageId: "expectedBlankLine" }]
3183 },
3184
3185 //----------------------------------------------------------------------
3186 // expression
3187 //----------------------------------------------------------------------
3188
3189 {
3190 code: "foo()\n\nfoo()",
3191 output: "foo()\nfoo()",
3192 options: [
3193 { blankLine: "never", prev: "expression", next: "*" }
3194 ],
3195 errors: [{ messageId: "unexpectedBlankLine" }]
3196 },
3197 {
3198 code: "foo()\nfoo()",
3199 output: "foo()\n\nfoo()",
3200 options: [
3201 { blankLine: "always", prev: "expression", next: "*" }
3202 ],
3203 errors: [{ messageId: "expectedBlankLine" }]
3204 },
3205
3206 //----------------------------------------------------------------------
3207 // multiline-expression
3208 //----------------------------------------------------------------------
3209
3210 {
3211 code: "foo()\n\nfoo(\n\tx,\n\ty\n)",
3212 output: "foo()\nfoo(\n\tx,\n\ty\n)",
3213 options: [
3214 { blankLine: "never", prev: "*", next: "multiline-expression" }
3215 ],
3216 errors: [{ messageId: "unexpectedBlankLine" }]
3217 },
3218 {
3219 code: "foo()\nfoo(\n\tx,\n\ty\n)",
3220 output: "foo()\n\nfoo(\n\tx,\n\ty\n)",
3221 options: [
3222 { blankLine: "always", prev: "*", next: "multiline-expression" }
3223 ],
3224 errors: [{ messageId: "expectedBlankLine" }]
3225 },
3226 {
3227 code: "() => {\n\tsomeArray.forEach(\n\t\tx => doSomething(x)\n\t);\n\treturn theThing;\n}",
3228 output: "() => {\n\tsomeArray.forEach(\n\t\tx => doSomething(x)\n\t);\n\n\treturn theThing;\n}",
3229 options: [
3230 { blankLine: "always", prev: "multiline-expression", next: "return" }
3231 ],
3232 errors: [{ messageId: "expectedBlankLine" }]
3233 },
3234
3235 //----------------------------------------------------------------------
3236 // break
3237 //----------------------------------------------------------------------
3238
3239 {
3240 code: "while(a){break\n\nfoo()}",
3241 output: "while(a){break\nfoo()}",
3242 options: [
3243 { blankLine: "never", prev: "break", next: "*" }
3244 ],
3245 errors: [{ messageId: "unexpectedBlankLine" }]
3246 },
3247 {
3248 code: "switch(a){case 0:break\n\nfoo()}",
3249 output: "switch(a){case 0:break\nfoo()}",
3250 options: [
3251 { blankLine: "never", prev: "break", next: "*" }
3252 ],
3253 errors: [{ messageId: "unexpectedBlankLine" }]
3254 },
3255 {
3256 code: "while(a){break\nfoo()}",
3257 output: "while(a){break\n\nfoo()}",
3258 options: [
3259 { blankLine: "always", prev: "break", next: "*" }
3260 ],
3261 errors: [{ messageId: "expectedBlankLine" }]
3262 },
3263 {
3264 code: "switch(a){case 0:break\nfoo()}",
3265 output: "switch(a){case 0:break\n\nfoo()}",
3266 options: [
3267 { blankLine: "always", prev: "break", next: "*" }
3268 ],
3269 errors: [{ messageId: "expectedBlankLine" }]
3270 },
3271
3272 //----------------------------------------------------------------------
3273 // case
3274 //----------------------------------------------------------------------
3275
3276 {
3277 code: "switch(a){case 0:\nfoo()\n\ndefault:}",
3278 output: "switch(a){case 0:\nfoo()\ndefault:}",
3279 options: [
3280 { blankLine: "never", prev: "case", next: "*" }
3281 ],
3282 errors: [{ messageId: "unexpectedBlankLine" }]
3283 },
3284 {
3285 code: "switch(a){case 0:\nfoo()\ndefault:}",
3286 output: "switch(a){case 0:\nfoo()\n\ndefault:}",
3287 options: [
3288 { blankLine: "always", prev: "case", next: "*" }
3289 ],
3290 errors: [{ messageId: "expectedBlankLine" }]
3291 },
3292
3293 //----------------------------------------------------------------------
3294 // class
3295 //----------------------------------------------------------------------
3296
3297 {
3298 code: "class A{}\n\nfoo()",
3299 output: "class A{}\nfoo()",
3300 options: [
3301 { blankLine: "never", prev: "class", next: "*" }
3302 ],
3303 errors: [{ messageId: "unexpectedBlankLine" }]
3304 },
3305 {
3306 code: "class A{}\nfoo()",
3307 output: "class A{}\n\nfoo()",
3308 options: [
3309 { blankLine: "always", prev: "class", next: "*" }
3310 ],
3311 errors: [{ messageId: "expectedBlankLine" }]
3312 },
3313
3314 //----------------------------------------------------------------------
3315 // const
3316 //----------------------------------------------------------------------
3317
3318 {
3319 code: "const a=1\n\nfoo()",
3320 output: "const a=1\nfoo()",
3321 options: [
3322 { blankLine: "never", prev: "const", next: "*" }
3323 ],
3324 errors: [{ messageId: "unexpectedBlankLine" }]
3325 },
3326 {
3327 code: "const a=1\nfoo()",
3328 output: "const a=1\n\nfoo()",
3329 options: [
3330 { blankLine: "always", prev: "const", next: "*" }
3331 ],
3332 errors: [{ messageId: "expectedBlankLine" }]
3333 },
3334
3335 //----------------------------------------------------------------------
3336 // continue
3337 //----------------------------------------------------------------------
3338
3339 {
3340 code: "while(a){continue\n\nfoo()}",
3341 output: "while(a){continue\nfoo()}",
3342 options: [
3343 { blankLine: "never", prev: "continue", next: "*" }
3344 ],
3345 errors: [{ messageId: "unexpectedBlankLine" }]
3346 },
3347 {
3348 code: "while(a){continue\nfoo()}",
3349 output: "while(a){continue\n\nfoo()}",
3350 options: [
3351 { blankLine: "always", prev: "continue", next: "*" }
3352 ],
3353 errors: [{ messageId: "expectedBlankLine" }]
3354 },
3355
3356 //----------------------------------------------------------------------
3357 // debugger
3358 //----------------------------------------------------------------------
3359
3360 {
3361 code: "debugger\n\nfoo()",
3362 output: "debugger\nfoo()",
3363 options: [
3364 { blankLine: "never", prev: "debugger", next: "*" }
3365 ],
3366 errors: [{ messageId: "unexpectedBlankLine" }]
3367 },
3368 {
3369 code: "debugger\nfoo()",
3370 output: "debugger\n\nfoo()",
3371 options: [
3372 { blankLine: "always", prev: "debugger", next: "*" }
3373 ],
3374 errors: [{ messageId: "expectedBlankLine" }]
3375 },
3376
3377 //----------------------------------------------------------------------
3378 // default
3379 //----------------------------------------------------------------------
3380
3381 {
3382 code: "switch(a){default:\nfoo()\n\ncase 0:}",
3383 output: "switch(a){default:\nfoo()\ncase 0:}",
3384 options: [
3385 { blankLine: "never", prev: "default", next: "*" }
3386 ],
3387 errors: [{ messageId: "unexpectedBlankLine" }]
3388 },
3389 {
3390 code: "switch(a){default:\nfoo()\ncase 0:}",
3391 output: "switch(a){default:\nfoo()\n\ncase 0:}",
3392 options: [
3393 { blankLine: "always", prev: "default", next: "*" }
3394 ],
3395 errors: [{ messageId: "expectedBlankLine" }]
3396 },
3397
3398 //----------------------------------------------------------------------
3399 // do
3400 //----------------------------------------------------------------------
3401
3402 {
3403 code: "do;while(a)\n\nfoo()",
3404 output: "do;while(a)\nfoo()",
3405 options: [
3406 { blankLine: "never", prev: "do", next: "*" }
3407 ],
3408 errors: [{ messageId: "unexpectedBlankLine" }]
3409 },
3410 {
3411 code: "do;while(a)\nfoo()",
3412 output: "do;while(a)\n\nfoo()",
3413 options: [
3414 { blankLine: "always", prev: "do", next: "*" }
3415 ],
3416 errors: [{ messageId: "expectedBlankLine" }]
3417 },
3418
3419 //----------------------------------------------------------------------
3420 // export
3421 //----------------------------------------------------------------------
3422
3423 {
3424 code: "export default 1\n\nfoo()",
3425 output: "export default 1\nfoo()",
3426 options: [
3427 { blankLine: "never", prev: "export", next: "*" }
3428 ],
3429 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3430 errors: [{ messageId: "unexpectedBlankLine" }]
3431 },
3432 {
3433 code: "export let a=1\n\nfoo()",
3434 output: "export let a=1\nfoo()",
3435 options: [
3436 { blankLine: "never", prev: "export", next: "*" }
3437 ],
3438 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3439 errors: [{ messageId: "unexpectedBlankLine" }]
3440 },
3441 {
3442 code: "var a = 0;export {a}\n\nfoo()",
3443 output: "var a = 0;export {a}\nfoo()",
3444 options: [
3445 { blankLine: "never", prev: "export", next: "*" }
3446 ],
3447 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3448 errors: [{ messageId: "unexpectedBlankLine" }]
3449 },
3450 {
3451 code: "export default 1\nfoo()",
3452 output: "export default 1\n\nfoo()",
3453 options: [
3454 { blankLine: "always", prev: "export", next: "*" }
3455 ],
3456 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3457 errors: [{ messageId: "expectedBlankLine" }]
3458 },
3459 {
3460 code: "export let a=1\nfoo()",
3461 output: "export let a=1\n\nfoo()",
3462 options: [
3463 { blankLine: "always", prev: "export", next: "*" }
3464 ],
3465 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3466 errors: [{ messageId: "expectedBlankLine" }]
3467 },
3468 {
3469 code: "var a = 0;export {a}\nfoo()",
3470 output: "var a = 0;export {a}\n\nfoo()",
3471 options: [
3472 { blankLine: "always", prev: "export", next: "*" }
3473 ],
3474 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3475 errors: [{ messageId: "expectedBlankLine" }]
3476 },
3477
3478 //----------------------------------------------------------------------
3479 // for
3480 //----------------------------------------------------------------------
3481
3482 {
3483 code: "for(;;);\n\nfoo()",
3484 output: "for(;;);\nfoo()",
3485 options: [
3486 { blankLine: "never", prev: "for", next: "*" }
3487 ],
3488 errors: [{ messageId: "unexpectedBlankLine" }]
3489 },
3490 {
3491 code: "for(a in b);\n\nfoo()",
3492 output: "for(a in b);\nfoo()",
3493 options: [
3494 { blankLine: "never", prev: "for", next: "*" }
3495 ],
3496 errors: [{ messageId: "unexpectedBlankLine" }]
3497 },
3498 {
3499 code: "for(a of b);\n\nfoo()",
3500 output: "for(a of b);\nfoo()",
3501 options: [
3502 { blankLine: "never", prev: "for", next: "*" }
3503 ],
3504 errors: [{ messageId: "unexpectedBlankLine" }]
3505 },
3506 {
3507 code: "for(;;);\nfoo()",
3508 output: "for(;;);\n\nfoo()",
3509 options: [
3510 { blankLine: "always", prev: "for", next: "*" }
3511 ],
3512 errors: [{ messageId: "expectedBlankLine" }]
3513 },
3514 {
3515 code: "for(a in b);\nfoo()",
3516 output: "for(a in b);\n\nfoo()",
3517 options: [
3518 { blankLine: "always", prev: "for", next: "*" }
3519 ],
3520 errors: [{ messageId: "expectedBlankLine" }]
3521 },
3522 {
3523 code: "for(a of b);\nfoo()",
3524 output: "for(a of b);\n\nfoo()",
3525 options: [
3526 { blankLine: "always", prev: "for", next: "*" }
3527 ],
3528 errors: [{ messageId: "expectedBlankLine" }]
3529 },
3530
3531 //----------------------------------------------------------------------
3532 // function
3533 //----------------------------------------------------------------------
3534
3535 {
3536 code: "function foo(){}\n\nfoo()",
3537 output: "function foo(){}\nfoo()",
3538 options: [
3539 { blankLine: "never", prev: "function", next: "*" }
3540 ],
3541 errors: [{ messageId: "unexpectedBlankLine" }]
3542 },
3543 {
3544 code: "function foo(){}\nfoo()",
3545 output: "function foo(){}\n\nfoo()",
3546 options: [
3547 { blankLine: "always", prev: "function", next: "*" }
3548 ],
3549 errors: [{ messageId: "expectedBlankLine" }]
3550 },
3551 {
3552 code: "async function foo(){}\nfoo()",
3553 output: "async function foo(){}\n\nfoo()",
3554 options: [
3555 { blankLine: "never", prev: "*", next: "*" },
3556 { blankLine: "always", prev: "function", next: "*" }
3557 ],
3558 errors: [{ messageId: "expectedBlankLine" }]
3559 },
3560
3561 //----------------------------------------------------------------------
3562 // if
3563 //----------------------------------------------------------------------
3564
3565 {
3566 code: "if(a);\n\nfoo()",
3567 output: "if(a);\nfoo()",
3568 options: [
3569 { blankLine: "never", prev: "if", next: "*" }
3570 ],
3571 errors: [{ messageId: "unexpectedBlankLine" }]
3572 },
3573 {
3574 code: "if(a);else;\n\nfoo()",
3575 output: "if(a);else;\nfoo()",
3576 options: [
3577 { blankLine: "never", prev: "if", next: "*" }
3578 ],
3579 errors: [{ messageId: "unexpectedBlankLine" }]
3580 },
3581 {
3582 code: "if(a);\nfoo()",
3583 output: "if(a);\n\nfoo()",
3584 options: [
3585 { blankLine: "always", prev: "if", next: "*" }
3586 ],
3587 errors: [{ messageId: "expectedBlankLine" }]
3588 },
3589 {
3590 code: "if(a);else;\nfoo()",
3591 output: "if(a);else;\n\nfoo()",
3592 options: [
3593 { blankLine: "always", prev: "if", next: "*" }
3594 ],
3595 errors: [{ messageId: "expectedBlankLine" }]
3596 },
3597
3598 //----------------------------------------------------------------------
3599 // iife
3600 //----------------------------------------------------------------------
3601
3602 {
3603 code: "(function(){\n})()\n\nvar a = 2;",
3604 output: "(function(){\n})()\nvar a = 2;",
3605 options: [
3606 { blankLine: "never", prev: "iife", next: "*" }
3607 ],
3608 errors: [{ messageId: "unexpectedBlankLine" }]
3609 },
3610 {
3611 code: "+(function(){\n})()\n\nvar a = 2;",
3612 output: "+(function(){\n})()\nvar a = 2;",
3613 options: [
3614 { blankLine: "never", prev: "iife", next: "*" }
3615 ],
3616 errors: [{ messageId: "unexpectedBlankLine" }]
3617 },
3618 {
3619 code: "(function(){\n})()\nvar a = 2;",
3620 output: "(function(){\n})()\n\nvar a = 2;",
3621 options: [
3622 { blankLine: "always", prev: "iife", next: "*" }
3623 ],
3624 errors: [{ messageId: "expectedBlankLine" }]
3625 },
3626 {
3627 code: "+(function(){\n})()\nvar a = 2;",
3628 output: "+(function(){\n})()\n\nvar a = 2;",
3629 options: [
3630 { blankLine: "always", prev: "iife", next: "*" }
3631 ],
3632 errors: [{ messageId: "expectedBlankLine" }]
3633 },
3634
3635 // Optional chaining
3636 {
3637 code: "(function(){\n})?.()\nvar a = 2;",
3638 output: "(function(){\n})?.()\n\nvar a = 2;",
3639 options: [{ blankLine: "always", prev: "iife", next: "*" }],
3640 parserOptions: { ecmaVersion: 2020 },
3641 errors: [{ messageId: "expectedBlankLine" }]
3642 },
3643 {
3644 code: "void (function(){\n})?.()\nvar a = 2;",
3645 output: "void (function(){\n})?.()\n\nvar a = 2;",
3646 options: [{ blankLine: "always", prev: "iife", next: "*" }],
3647 parserOptions: { ecmaVersion: 2020 },
3648 errors: [{ messageId: "expectedBlankLine" }]
3649 },
3650
3651 //----------------------------------------------------------------------
3652 // import
3653 //----------------------------------------------------------------------
3654
3655 {
3656 code: "import a from 'a'\n\nfoo()",
3657 output: "import a from 'a'\nfoo()",
3658 options: [
3659 { blankLine: "never", prev: "import", next: "*" }
3660 ],
3661 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3662 errors: [{ messageId: "unexpectedBlankLine" }]
3663 },
3664 {
3665 code: "import * as a from 'a'\n\nfoo()",
3666 output: "import * as a from 'a'\nfoo()",
3667 options: [
3668 { blankLine: "never", prev: "import", next: "*" }
3669 ],
3670 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3671 errors: [{ messageId: "unexpectedBlankLine" }]
3672 },
3673 {
3674 code: "import {a} from 'a'\n\nfoo()",
3675 output: "import {a} from 'a'\nfoo()",
3676 options: [
3677 { blankLine: "never", prev: "import", next: "*" }
3678 ],
3679 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3680 errors: [{ messageId: "unexpectedBlankLine" }]
3681 },
3682 {
3683 code: "import a from 'a'\nfoo()",
3684 output: "import a from 'a'\n\nfoo()",
3685 options: [
3686 { blankLine: "always", prev: "import", next: "*" }
3687 ],
3688 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3689 errors: [{ messageId: "expectedBlankLine" }]
3690 },
3691 {
3692 code: "import * as a from 'a'\nfoo()",
3693 output: "import * as a from 'a'\n\nfoo()",
3694 options: [
3695 { blankLine: "always", prev: "import", next: "*" }
3696 ],
3697 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3698 errors: [{ messageId: "expectedBlankLine" }]
3699 },
3700 {
3701 code: "import {a} from 'a'\nfoo()",
3702 output: "import {a} from 'a'\n\nfoo()",
3703 options: [
3704 { blankLine: "always", prev: "import", next: "*" }
3705 ],
3706 parserOptions: { ecmaVersion: 6, sourceType: "module" },
3707 errors: [{ messageId: "expectedBlankLine" }]
3708 },
3709
3710 //----------------------------------------------------------------------
3711 // let
3712 //----------------------------------------------------------------------
3713
3714 {
3715 code: "let a\n\nfoo()",
3716 output: "let a\nfoo()",
3717 options: [
3718 { blankLine: "never", prev: "let", next: "*" }
3719 ],
3720 errors: [{ messageId: "unexpectedBlankLine" }]
3721 },
3722 {
3723 code: "let a\nfoo()",
3724 output: "let a\n\nfoo()",
3725 options: [
3726 { blankLine: "always", prev: "let", next: "*" }
3727 ],
3728 errors: [{ messageId: "expectedBlankLine" }]
3729 },
3730
3731 //----------------------------------------------------------------------
3732 // return
3733 //----------------------------------------------------------------------
3734
3735 {
3736 code: "function foo(){return\n\nfoo()}",
3737 output: "function foo(){return\nfoo()}",
3738 options: [
3739 { blankLine: "never", prev: "return", next: "*" }
3740 ],
3741 errors: [{ messageId: "unexpectedBlankLine" }]
3742 },
3743 {
3744 code: "function foo(){return\nfoo()}",
3745 output: "function foo(){return\n\nfoo()}",
3746 options: [
3747 { blankLine: "always", prev: "return", next: "*" }
3748 ],
3749 errors: [{ messageId: "expectedBlankLine" }]
3750 },
3751
3752 //----------------------------------------------------------------------
3753 // switch
3754 //----------------------------------------------------------------------
3755
3756 {
3757 code: "switch(a){}\n\nfoo()",
3758 output: "switch(a){}\nfoo()",
3759 options: [
3760 { blankLine: "never", prev: "switch", next: "*" }
3761 ],
3762 errors: [{ messageId: "unexpectedBlankLine" }]
3763 },
3764 {
3765 code: "switch(a){}\nfoo()",
3766 output: "switch(a){}\n\nfoo()",
3767 options: [
3768 { blankLine: "always", prev: "switch", next: "*" }
3769 ],
3770 errors: [{ messageId: "expectedBlankLine" }]
3771 },
3772
3773 //----------------------------------------------------------------------
3774 // throw
3775 //----------------------------------------------------------------------
3776
3777 {
3778 code: "throw a\n\nfoo()",
3779 output: "throw a\nfoo()",
3780 options: [
3781 { blankLine: "never", prev: "throw", next: "*" }
3782 ],
3783 errors: [{ messageId: "unexpectedBlankLine" }]
3784 },
3785 {
3786 code: "throw a\nfoo()",
3787 output: "throw a\n\nfoo()",
3788 options: [
3789 { blankLine: "always", prev: "throw", next: "*" }
3790 ],
3791 errors: [{ messageId: "expectedBlankLine" }]
3792 },
3793
3794 //----------------------------------------------------------------------
3795 // try
3796 //----------------------------------------------------------------------
3797
3798 {
3799 code: "try{}catch(e){}\n\nfoo()",
3800 output: "try{}catch(e){}\nfoo()",
3801 options: [
3802 { blankLine: "never", prev: "try", next: "*" }
3803 ],
3804 errors: [{ messageId: "unexpectedBlankLine" }]
3805 },
3806 {
3807 code: "try{}finally{}\n\nfoo()",
3808 output: "try{}finally{}\nfoo()",
3809 options: [
3810 { blankLine: "never", prev: "try", next: "*" }
3811 ],
3812 errors: [{ messageId: "unexpectedBlankLine" }]
3813 },
3814 {
3815 code: "try{}catch(e){}finally{}\n\nfoo()",
3816 output: "try{}catch(e){}finally{}\nfoo()",
3817 options: [
3818 { blankLine: "never", prev: "try", next: "*" }
3819 ],
3820 errors: [{ messageId: "unexpectedBlankLine" }]
3821 },
3822 {
3823 code: "try{}catch(e){}\nfoo()",
3824 output: "try{}catch(e){}\n\nfoo()",
3825 options: [
3826 { blankLine: "always", prev: "try", next: "*" }
3827 ],
3828 errors: [{ messageId: "expectedBlankLine" }]
3829 },
3830 {
3831 code: "try{}finally{}\nfoo()",
3832 output: "try{}finally{}\n\nfoo()",
3833 options: [
3834 { blankLine: "always", prev: "try", next: "*" }
3835 ],
3836 errors: [{ messageId: "expectedBlankLine" }]
3837 },
3838 {
3839 code: "try{}catch(e){}finally{}\nfoo()",
3840 output: "try{}catch(e){}finally{}\n\nfoo()",
3841 options: [
3842 { blankLine: "always", prev: "try", next: "*" }
3843 ],
3844 errors: [{ messageId: "expectedBlankLine" }]
3845 },
3846
3847 //----------------------------------------------------------------------
3848 // var
3849 //----------------------------------------------------------------------
3850
3851 {
3852 code: "var a\n\nfoo()",
3853 output: "var a\nfoo()",
3854 options: [
3855 { blankLine: "never", prev: "var", next: "*" }
3856 ],
3857 errors: [{ messageId: "unexpectedBlankLine" }]
3858 },
3859 {
3860 code: "var a\nfoo()",
3861 output: "var a\n\nfoo()",
3862 options: [
3863 { blankLine: "always", prev: "var", next: "*" }
3864 ],
3865 errors: [{ messageId: "expectedBlankLine" }]
3866 },
3867
3868 //----------------------------------------------------------------------
3869 // while
3870 //----------------------------------------------------------------------
3871
3872 {
3873 code: "while(a);\n\nfoo()",
3874 output: "while(a);\nfoo()",
3875 options: [
3876 { blankLine: "never", prev: "while", next: "*" }
3877 ],
3878 errors: [{ messageId: "unexpectedBlankLine" }]
3879 },
3880 {
3881 code: "while(a);\nfoo()",
3882 output: "while(a);\n\nfoo()",
3883 options: [
3884 { blankLine: "always", prev: "while", next: "*" }
3885 ],
3886 errors: [{ messageId: "expectedBlankLine" }]
3887 },
3888
3889 //----------------------------------------------------------------------
3890 // with
3891 //----------------------------------------------------------------------
3892
3893 {
3894 code: "with(a);\n\nfoo()",
3895 output: "with(a);\nfoo()",
3896 options: [
3897 { blankLine: "never", prev: "with", next: "*" }
3898 ],
3899 errors: [{ messageId: "unexpectedBlankLine" }]
3900 },
3901 {
3902 code: "with(a);\nfoo()",
3903 output: "with(a);\n\nfoo()",
3904 options: [
3905 { blankLine: "always", prev: "with", next: "*" }
3906 ],
3907 errors: [{ messageId: "expectedBlankLine" }]
3908 },
3909
3910 //----------------------------------------------------------------------
3911 // multiline-const
3912 //----------------------------------------------------------------------
3913
3914 {
3915 code: "const a={\nb:1,\nc:2\n}\n\nconst d=3",
3916 output: "const a={\nb:1,\nc:2\n}\nconst d=3",
3917 options: [
3918 { blankLine: "never", prev: "multiline-const", next: "*" }
3919 ],
3920 errors: [{ messageId: "unexpectedBlankLine" }]
3921 },
3922 {
3923 code: "const a={\nb:1,\nc:2\n}\nconst d=3",
3924 output: "const a={\nb:1,\nc:2\n}\n\nconst d=3",
3925 options: [
3926 { blankLine: "always", prev: "multiline-const", next: "*" }
3927 ],
3928 errors: [{ messageId: "expectedBlankLine" }]
3929 },
3930 {
3931 code: "const a=1\n\nconst b={\nc:2,\nd:3\n}",
3932 output: "const a=1\nconst b={\nc:2,\nd:3\n}",
3933 options: [
3934 { blankLine: "never", prev: "*", next: "multiline-const" }
3935 ],
3936 errors: [{ messageId: "unexpectedBlankLine" }]
3937 },
3938 {
3939 code: "const a=1\nconst b={\nc:2,\nd:3\n}",
3940 output: "const a=1\n\nconst b={\nc:2,\nd:3\n}",
3941 options: [
3942 { blankLine: "always", prev: "*", next: "multiline-const" }
3943 ],
3944 errors: [{ messageId: "expectedBlankLine" }]
3945 },
3946
3947 //----------------------------------------------------------------------
3948 // multiline-let
3949 //----------------------------------------------------------------------
3950
3951 {
3952 code: "let a={\nb:1,\nc:2\n}\n\nlet d=3",
3953 output: "let a={\nb:1,\nc:2\n}\nlet d=3",
3954 options: [
3955 { blankLine: "never", prev: "multiline-let", next: "*" }
3956 ],
3957 errors: [{ messageId: "unexpectedBlankLine" }]
3958 },
3959 {
3960 code: "let a={\nb:1,\nc:2\n}\nlet d=3",
3961 output: "let a={\nb:1,\nc:2\n}\n\nlet d=3",
3962 options: [
3963 { blankLine: "always", prev: "multiline-let", next: "*" }
3964 ],
3965 errors: [{ messageId: "expectedBlankLine" }]
3966 },
3967 {
3968 code: "let a=1\n\nlet b={\nc:2,\nd:3\n}",
3969 output: "let a=1\nlet b={\nc:2,\nd:3\n}",
3970 options: [
3971 { blankLine: "never", prev: "*", next: "multiline-let" }
3972 ],
3973 errors: [{ messageId: "unexpectedBlankLine" }]
3974 },
3975 {
3976 code: "let a=1\nlet b={\nc:2,\nd:3\n}",
3977 output: "let a=1\n\nlet b={\nc:2,\nd:3\n}",
3978 options: [
3979 { blankLine: "always", prev: "*", next: "multiline-let" }
3980 ],
3981 errors: [{ messageId: "expectedBlankLine" }]
3982 },
3983
3984 //----------------------------------------------------------------------
3985 // multiline-var
3986 //----------------------------------------------------------------------
3987
3988 {
3989 code: "var a={\nb:1,\nc:2\n}\n\nvar d=3",
3990 output: "var a={\nb:1,\nc:2\n}\nvar d=3",
3991 options: [
3992 { blankLine: "never", prev: "multiline-var", next: "*" }
3993 ],
3994 errors: [{ messageId: "unexpectedBlankLine" }]
3995 },
3996 {
3997 code: "var a={\nb:1,\nc:2\n}\nvar d=3",
3998 output: "var a={\nb:1,\nc:2\n}\n\nvar d=3",
3999 options: [
4000 { blankLine: "always", prev: "multiline-var", next: "*" }
4001 ],
4002 errors: [{ messageId: "expectedBlankLine" }]
4003 },
4004 {
4005 code: "var a=1\n\nvar b={\nc:2,\nd:3\n}",
4006 output: "var a=1\nvar b={\nc:2,\nd:3\n}",
4007 options: [
4008 { blankLine: "never", prev: "*", next: "multiline-var" }
4009 ],
4010 errors: [{ messageId: "unexpectedBlankLine" }]
4011 },
4012 {
4013 code: "var a=1\nvar b={\nc:2,\nd:3\n}",
4014 output: "var a=1\n\nvar b={\nc:2,\nd:3\n}",
4015 options: [
4016 { blankLine: "always", prev: "*", next: "multiline-var" }
4017 ],
4018 errors: [{ messageId: "expectedBlankLine" }]
4019 },
4020
4021 //----------------------------------------------------------------------
4022 // singleline-const
4023 //----------------------------------------------------------------------
4024
4025 {
4026 code: "const a=1\n\nconst b=2",
4027 output: "const a=1\nconst b=2",
4028 options: [
4029 { blankLine: "never", prev: "singleline-const", next: "*" }
4030 ],
4031 errors: [{ messageId: "unexpectedBlankLine" }]
4032 },
4033 {
4034 code: "const a=1\nconst b=2",
4035 output: "const a=1\n\nconst b=2",
4036 options: [
4037 { blankLine: "always", prev: "singleline-const", next: "*" }
4038 ],
4039 errors: [{ messageId: "expectedBlankLine" }]
4040 },
4041 {
4042 code: "const a=1\n\nconst b=2",
4043 output: "const a=1\nconst b=2",
4044 options: [
4045 { blankLine: "never", prev: "*", next: "singleline-const" }
4046 ],
4047 errors: [{ messageId: "unexpectedBlankLine" }]
4048 },
4049 {
4050 code: "const a=1\nconst b=2",
4051 output: "const a=1\n\nconst b=2",
4052 options: [
4053 { blankLine: "always", prev: "*", next: "singleline-const" }
4054 ],
4055 errors: [{ messageId: "expectedBlankLine" }]
4056 },
4057
4058 //----------------------------------------------------------------------
4059 // singleline-let
4060 //----------------------------------------------------------------------
4061
4062 {
4063 code: "let a=1\n\nlet b=2",
4064 output: "let a=1\nlet b=2",
4065 options: [
4066 { blankLine: "never", prev: "singleline-let", next: "*" }
4067 ],
4068 errors: [{ messageId: "unexpectedBlankLine" }]
4069 },
4070 {
4071 code: "let a=1\nlet b=2",
4072 output: "let a=1\n\nlet b=2",
4073 options: [
4074 { blankLine: "always", prev: "singleline-let", next: "*" }
4075 ],
4076 errors: [{ messageId: "expectedBlankLine" }]
4077 },
4078 {
4079 code: "let a=1\n\nlet b=2",
4080 output: "let a=1\nlet b=2",
4081 options: [
4082 { blankLine: "never", prev: "*", next: "singleline-let" }
4083 ],
4084 errors: [{ messageId: "unexpectedBlankLine" }]
4085 },
4086 {
4087 code: "let a=1\nlet b=2",
4088 output: "let a=1\n\nlet b=2",
4089 options: [
4090 { blankLine: "always", prev: "*", next: "singleline-let" }
4091 ],
4092 errors: [{ messageId: "expectedBlankLine" }]
4093 },
4094
4095 //----------------------------------------------------------------------
4096 // singleline-var
4097 //----------------------------------------------------------------------
4098
4099 {
4100 code: "var a=1\n\nvar b=2",
4101 output: "var a=1\nvar b=2",
4102 options: [
4103 { blankLine: "never", prev: "singleline-var", next: "*" }
4104 ],
4105 errors: [{ messageId: "unexpectedBlankLine" }]
4106 },
4107 {
4108 code: "var a=1\nvar b=2",
4109 output: "var a=1\n\nvar b=2",
4110 options: [
4111 { blankLine: "always", prev: "singleline-var", next: "*" }
4112 ],
4113 errors: [{ messageId: "expectedBlankLine" }]
4114 },
4115 {
4116 code: "var a=1\n\nvar b=2",
4117 output: "var a=1\nvar b=2",
4118 options: [
4119 { blankLine: "never", prev: "*", next: "singleline-var" }
4120 ],
4121 errors: [{ messageId: "unexpectedBlankLine" }]
4122 },
4123 {
4124 code: "var a=1\nvar b=2",
4125 output: "var a=1\n\nvar b=2",
4126 options: [
4127 { blankLine: "always", prev: "*", next: "singleline-var" }
4128 ],
4129 errors: [{ messageId: "expectedBlankLine" }]
4130 },
4131
4132 //----------------------------------------------------------------------
4133 // Tests from newline-after-var
4134 //----------------------------------------------------------------------
4135
4136 // should disallow no line break in "always" mode
4137 {
4138 code: "var greet = 'hello';console.log(greet);",
4139 output: "var greet = 'hello';\n\nconsole.log(greet);",
4140 options: [
4141 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4142 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4143 ],
4144 errors: [{ messageId: "expectedBlankLine" }]
4145 },
4146 {
4147 code: "var greet = 'hello';var name = 'world';console.log(greet, name);",
4148 output: "var greet = 'hello';var name = 'world';\n\nconsole.log(greet, name);",
4149 options: [
4150 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4151 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4152 ],
4153 errors: [{ messageId: "expectedBlankLine" }]
4154 },
4155 {
4156 code: "var greet = 'hello', name = 'world';console.log(greet, name);",
4157 output: "var greet = 'hello', name = 'world';\n\nconsole.log(greet, name);",
4158 options: [
4159 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4160 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4161 ],
4162 errors: [{ messageId: "expectedBlankLine" }]
4163 },
4164
4165 // should disallow no blank line in "always" mode
4166 {
4167 code: "var greet = 'hello';\nconsole.log(greet);",
4168 output: "var greet = 'hello';\n\nconsole.log(greet);",
4169 options: [
4170 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4171 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4172 ],
4173 errors: [{ messageId: "expectedBlankLine" }]
4174 },
4175 {
4176 code: "var greet = 'hello'; \nconsole.log(greet);",
4177 output: "var greet = 'hello';\n \nconsole.log(greet);",
4178 options: [
4179 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4180 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4181 ],
4182 errors: [{ messageId: "expectedBlankLine" }]
4183 },
4184 {
4185 code: "var greet = 'hello'; // inline comment\nconsole.log(greet);",
4186 output: "var greet = 'hello'; // inline comment\n\nconsole.log(greet);",
4187 options: [
4188 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4189 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4190 ],
4191 errors: [{ messageId: "expectedBlankLine" }]
4192 },
4193 {
4194 code: "var greet = 'hello';\nvar name = 'world';\nconsole.log(greet, name);",
4195 output: "var greet = 'hello';\nvar name = 'world';\n\nconsole.log(greet, name);",
4196 options: [
4197 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4198 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4199 ],
4200 errors: [{ messageId: "expectedBlankLine" }]
4201 },
4202 {
4203 code: "var greet = 'hello', name = 'world';\nconsole.log(greet, name);",
4204 output: "var greet = 'hello', name = 'world';\n\nconsole.log(greet, name);",
4205 options: [
4206 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4207 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4208 ],
4209 errors: [{ messageId: "expectedBlankLine" }]
4210 },
4211 {
4212 code: "var greet = 'hello',\nname = 'world';\nconsole.log(greet, name);",
4213 output: "var greet = 'hello',\nname = 'world';\n\nconsole.log(greet, name);",
4214 options: [
4215 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4216 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4217 ],
4218 errors: [{ messageId: "expectedBlankLine" }]
4219 },
4220 {
4221 code: "let greet = 'hello';\nconsole.log(greet);",
4222 output: "let greet = 'hello';\n\nconsole.log(greet);",
4223 options: [
4224 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4225 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4226 ],
4227 errors: [{ messageId: "expectedBlankLine" }]
4228 },
4229 {
4230 code: "const greet = 'hello';\nconsole.log(greet);",
4231 output: "const greet = 'hello';\n\nconsole.log(greet);",
4232 options: [
4233 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4234 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4235 ],
4236 errors: [{ messageId: "expectedBlankLine" }]
4237 },
4238 {
4239 code: "function example() {\nvar greet = 'hello';\nconsole.log(greet);\n}",
4240 output: "function example() {\nvar greet = 'hello';\n\nconsole.log(greet);\n}",
4241 options: [
4242 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4243 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4244 ],
4245 errors: [{ messageId: "expectedBlankLine" }]
4246 },
4247 {
4248 code: "var f = function() {\nvar greet = 'hello';\nconsole.log(greet);\n};",
4249 output: "var f = function() {\nvar greet = 'hello';\n\nconsole.log(greet);\n};",
4250 options: [
4251 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4252 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4253 ],
4254 errors: [{ messageId: "expectedBlankLine" }]
4255 },
4256 {
4257 code: "() => {\nvar greet = 'hello';\nconsole.log(greet);\n}",
4258 output: "() => {\nvar greet = 'hello';\n\nconsole.log(greet);\n}",
4259 options: [
4260 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4261 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4262 ],
4263 errors: [{ messageId: "expectedBlankLine" }]
4264 },
4265
4266 // should disallow blank lines in "never" mode
4267 {
4268 code: "var greet = 'hello';\n\nconsole.log(greet);",
4269 output: "var greet = 'hello';\nconsole.log(greet);",
4270 options: [
4271 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4272 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4273 ],
4274 errors: [{ messageId: "unexpectedBlankLine" }]
4275 },
4276 {
4277 code: "var greet = 'hello';\n\n\nconsole.log(greet);",
4278 output: "var greet = 'hello';\nconsole.log(greet);",
4279 options: [
4280 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4281 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4282 ],
4283 errors: [{ messageId: "unexpectedBlankLine" }]
4284 },
4285 {
4286 code: "var greet = 'hello';\n\n\n\nconsole.log(greet);",
4287 output: "var greet = 'hello';\nconsole.log(greet);",
4288 options: [
4289 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4290 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4291 ],
4292 errors: [{ messageId: "unexpectedBlankLine" }]
4293 },
4294 {
4295 code: "var greet = 'hello'; \n\nconsole.log(greet);",
4296 output: "var greet = 'hello'; \nconsole.log(greet);",
4297 options: [
4298 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4299 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4300 ],
4301 errors: [{ messageId: "unexpectedBlankLine" }]
4302 },
4303 {
4304 code: "var greet = 'hello'; // inline comment\n\nconsole.log(greet);",
4305 output: "var greet = 'hello'; // inline comment\nconsole.log(greet);",
4306 options: [
4307 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4308 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4309 ],
4310 errors: [{ messageId: "unexpectedBlankLine" }]
4311 },
4312 {
4313 code: "var greet = 'hello';\nvar name = 'world';\n\nconsole.log(greet, name);",
4314 output: "var greet = 'hello';\nvar name = 'world';\nconsole.log(greet, name);",
4315 options: [
4316 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4317 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4318 ],
4319 errors: [{ messageId: "unexpectedBlankLine" }]
4320 },
4321 {
4322 code: "var greet = 'hello', name = 'world';\n\nconsole.log(greet, name);",
4323 output: "var greet = 'hello', name = 'world';\nconsole.log(greet, name);",
4324 options: [
4325 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4326 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4327 ],
4328 errors: [{ messageId: "unexpectedBlankLine" }]
4329 },
4330 {
4331 code: "var greet = 'hello',\nname = 'world';\n\nconsole.log(greet, name);",
4332 output: "var greet = 'hello',\nname = 'world';\nconsole.log(greet, name);",
4333 options: [
4334 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4335 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4336 ],
4337 errors: [{ messageId: "unexpectedBlankLine" }]
4338 },
4339 {
4340 code: "var greet = 'hello', // inline comment\nname = 'world'; // inline comment\n\nconsole.log(greet, name);",
4341 output: "var greet = 'hello', // inline comment\nname = 'world'; // inline comment\nconsole.log(greet, name);",
4342 options: [
4343 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4344 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4345 ],
4346 errors: [{ messageId: "unexpectedBlankLine" }]
4347 },
4348 {
4349 code: "let greet = 'hello';\n\nconsole.log(greet);",
4350 output: "let greet = 'hello';\nconsole.log(greet);",
4351 options: [
4352 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4353 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4354 ],
4355 errors: [{ messageId: "unexpectedBlankLine" }]
4356 },
4357 {
4358 code: "const greet = 'hello';\n\nconsole.log(greet);",
4359 output: "const greet = 'hello';\nconsole.log(greet);",
4360 options: [
4361 { blankLine: "never", prev: ["const", "let", "var"], next: "*" },
4362 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4363 ],
4364 errors: [{ messageId: "unexpectedBlankLine" }]
4365 },
4366
4367 // should disallow a comment on the next line that's not in turn followed by a blank in "always" mode
4368 {
4369 code: "var greet = 'hello';\n// next-line comment\nconsole.log(greet);",
4370 output: "var greet = 'hello';\n\n// next-line comment\nconsole.log(greet);",
4371 options: [
4372 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4373 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4374 ],
4375 errors: [{ messageId: "expectedBlankLine" }]
4376 },
4377 {
4378 code: "var greet = 'hello';\n/* block comment\nblock comment */\nconsole.log(greet);",
4379 output: "var greet = 'hello';\n\n/* block comment\nblock comment */\nconsole.log(greet);",
4380 options: [
4381 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4382 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4383 ],
4384 errors: [{ messageId: "expectedBlankLine" }]
4385 },
4386 {
4387 code: "var greet = 'hello',\nname = 'world';\n// next-line comment\nconsole.log(greet);",
4388 output: "var greet = 'hello',\nname = 'world';\n\n// next-line comment\nconsole.log(greet);",
4389 options: [
4390 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4391 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4392 ],
4393 errors: [{ messageId: "expectedBlankLine" }]
4394 },
4395 {
4396 code: "var greet = 'hello',\nname = 'world';\n/* block comment\nblock comment */\nconsole.log(greet);",
4397 output: "var greet = 'hello',\nname = 'world';\n\n/* block comment\nblock comment */\nconsole.log(greet);",
4398 options: [
4399 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4400 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4401 ],
4402 errors: [{ messageId: "expectedBlankLine" }]
4403 },
4404 {
4405 code: "var greet = 'hello';\n// next-line comment\n// second-line comment\nconsole.log(greet);",
4406 output: "var greet = 'hello';\n\n// next-line comment\n// second-line comment\nconsole.log(greet);",
4407 options: [
4408 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4409 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4410 ],
4411 errors: [{ messageId: "expectedBlankLine" }]
4412 },
4413 {
4414 code: "var greet = 'hello';\n// next-line comment\n/* block comment\nblock comment */\nconsole.log(greet);",
4415 output: "var greet = 'hello';\n\n// next-line comment\n/* block comment\nblock comment */\nconsole.log(greet);",
4416 options: [
4417 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4418 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4419 ],
4420 errors: [{ messageId: "expectedBlankLine" }]
4421 },
4422
4423 // https://github.com/eslint/eslint/issues/6834
4424 {
4425 code: `
4426 var a = 1
4427 ;(b || c).doSomething()
4428 `,
4429 output: `
4430 var a = 1
4431
4432 ;(b || c).doSomething()
4433 `,
4434 options: [
4435 { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
4436 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] }
4437 ],
4438 errors: [{ messageId: "expectedBlankLine" }]
4439 },
4440 {
4441 code: `
4442 var a = 1
4443
4444 ;(b || c).doSomething()
4445 `,
4446 output: `
4447 var a = 1
4448 ;(b || c).doSomething()
4449 `,
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 //----------------------------------------------------------------------
4458 // Tests from newline-before-return
4459 //----------------------------------------------------------------------
4460
4461 {
4462 code: "function a() {\nvar b; return;\n}",
4463 output: "function a() {\nvar b;\n\n return;\n}",
4464 options: [
4465 { blankLine: "always", prev: "*", next: "return" }
4466 ],
4467 errors: [{ messageId: "expectedBlankLine" }]
4468 },
4469 {
4470 code: "function a() {\nvar b;\nreturn;\n}",
4471 output: "function a() {\nvar b;\n\nreturn;\n}",
4472 options: [
4473 { blankLine: "always", prev: "*", next: "return" }
4474 ],
4475 errors: [{ messageId: "expectedBlankLine" }]
4476 },
4477 {
4478 code: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\ne();\nreturn d;\n}\n}",
4479 output: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\ne();\n\nreturn d;\n}\n}",
4480 options: [
4481 { blankLine: "always", prev: "*", next: "return" }
4482 ],
4483 errors: [{ messageId: "expectedBlankLine" }]
4484 },
4485 {
4486 code: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\ne(); return d;\n}\n}",
4487 output: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\ne();\n\n return d;\n}\n}",
4488 options: [
4489 { blankLine: "always", prev: "*", next: "return" }
4490 ],
4491 errors: [{ messageId: "expectedBlankLine" }]
4492 },
4493 {
4494 code: "function a() {\n while (b) {\nc();\nreturn;\n}\n}",
4495 output: "function a() {\n while (b) {\nc();\n\nreturn;\n}\n}",
4496 options: [
4497 { blankLine: "always", prev: "*", next: "return" }
4498 ],
4499 errors: [{ messageId: "expectedBlankLine" }]
4500 },
4501 {
4502 code: "function a() {\ndo {\nc();\nreturn;\n} while (b);\n}",
4503 output: "function a() {\ndo {\nc();\n\nreturn;\n} while (b);\n}",
4504 options: [
4505 { blankLine: "always", prev: "*", next: "return" }
4506 ],
4507 errors: [{ messageId: "expectedBlankLine" }]
4508 },
4509 {
4510 code: "function a() {\nfor (var b; b < c; b++) {\nc();\nreturn;\n}\n}",
4511 output: "function a() {\nfor (var b; b < c; b++) {\nc();\n\nreturn;\n}\n}",
4512 options: [
4513 { blankLine: "always", prev: "*", next: "return" }
4514 ],
4515 errors: [{ messageId: "expectedBlankLine" }]
4516 },
4517 {
4518 code: "function a() {\nfor (b in c) {\nd();\nreturn;\n}\n}",
4519 output: "function a() {\nfor (b in c) {\nd();\n\nreturn;\n}\n}",
4520 options: [
4521 { blankLine: "always", prev: "*", next: "return" }
4522 ],
4523 errors: [{ messageId: "expectedBlankLine" }]
4524 },
4525 {
4526 code: "function a() {\nfor (b of c) {\nd();\nreturn;\n}\n}",
4527 output: "function a() {\nfor (b of c) {\nd();\n\nreturn;\n}\n}",
4528 options: [
4529 { blankLine: "always", prev: "*", next: "return" }
4530 ],
4531 errors: [{ messageId: "expectedBlankLine" }]
4532 },
4533 {
4534 code: "function a() {\nif (b) {\nc();\n}\n//comment\nreturn b;\n}",
4535 output: "function a() {\nif (b) {\nc();\n}\n\n//comment\nreturn b;\n}",
4536 options: [
4537 { blankLine: "always", prev: "*", next: "return" }
4538 ],
4539 errors: [{ messageId: "expectedBlankLine" }]
4540 },
4541 {
4542 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}",
4543 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}",
4544 options: [
4545 { blankLine: "always", prev: "*", next: "return" }
4546 ],
4547 errors: [{ messageId: "expectedBlankLine" }, { messageId: "expectedBlankLine" }]
4548 },
4549 {
4550 code: "function a() {\nif (b) { return; } //comment\nreturn c;\n}",
4551 output: "function a() {\nif (b) { return; } //comment\n\nreturn c;\n}",
4552 options: [
4553 { blankLine: "always", prev: "*", next: "return" }
4554 ],
4555 errors: [{ messageId: "expectedBlankLine" }]
4556 },
4557 {
4558 code: "function a() {\nif (b) { return; } /*multi-line\ncomment*/\nreturn c;\n}",
4559 output: "function a() {\nif (b) { return; } /*multi-line\ncomment*/\n\nreturn c;\n}",
4560 options: [
4561 { blankLine: "always", prev: "*", next: "return" }
4562 ],
4563 errors: [{ messageId: "expectedBlankLine" }]
4564 },
4565 {
4566 code: "function a() {\nif (b) { return; }\n/*multi-line\ncomment*/ return c;\n}",
4567 output: "function a() {\nif (b) { return; }\n\n/*multi-line\ncomment*/ return c;\n}",
4568 options: [
4569 { blankLine: "always", prev: "*", next: "return" }
4570 ],
4571 errors: [{ messageId: "expectedBlankLine" }]
4572 },
4573 {
4574 code: "function a() {\nif (b) { return; } /*multi-line\ncomment*/ return c;\n}",
4575 output: "function a() {\nif (b) { return; } /*multi-line\ncomment*/\n\n return c;\n}",
4576 options: [
4577 { blankLine: "always", prev: "*", next: "return" }
4578 ],
4579 errors: [{ messageId: "expectedBlankLine" }]
4580 },
4581 {
4582 code: "var a;\nreturn;",
4583 output: "var a;\n\nreturn;",
4584 options: [
4585 { blankLine: "always", prev: "*", next: "return" }
4586 ],
4587 parserOptions: { ecmaFeatures: { globalReturn: true } },
4588 errors: [{ messageId: "expectedBlankLine" }]
4589 },
4590 {
4591 code: "var a; return;",
4592 output: "var a;\n\n return;",
4593 options: [
4594 { blankLine: "always", prev: "*", next: "return" }
4595 ],
4596 parserOptions: { ecmaFeatures: { globalReturn: true } },
4597 errors: [{ messageId: "expectedBlankLine" }]
4598 },
4599 {
4600 code: "function a() {\n{\n//comment\n}\nreturn\n}",
4601 output: "function a() {\n{\n//comment\n}\n\nreturn\n}",
4602 options: [
4603 { blankLine: "always", prev: "*", next: "return" }
4604 ],
4605 errors: [{ messageId: "expectedBlankLine" }]
4606 },
4607 {
4608 code: "function a() {\n{\n//comment\n} return\n}",
4609 output: "function a() {\n{\n//comment\n}\n\n return\n}",
4610 options: [
4611 { blankLine: "always", prev: "*", next: "return" }
4612 ],
4613 errors: [{ messageId: "expectedBlankLine" }]
4614 },
4615 {
4616 code: "function a() {\nvar c;\nwhile (b) {\n c = d; //comment\n}\nreturn c;\n}",
4617 output: "function a() {\nvar c;\nwhile (b) {\n c = d; //comment\n}\n\nreturn c;\n}",
4618 options: [
4619 { blankLine: "always", prev: "*", next: "return" }
4620 ],
4621 errors: [{ messageId: "expectedBlankLine" }]
4622 },
4623 {
4624 code: "function a() {\nfor (var b; b < c; b++) {\nif (d) {\nbreak; //comment\n}\nreturn;\n}\n}",
4625 output: "function a() {\nfor (var b; b < c; b++) {\nif (d) {\nbreak; //comment\n}\n\nreturn;\n}\n}",
4626 options: [
4627 { blankLine: "always", prev: "*", next: "return" }
4628 ],
4629 errors: [{ messageId: "expectedBlankLine" }]
4630 },
4631 {
4632 code: "function a() {\nvar b; /*multi-line\ncomment*/\nreturn c;\n}",
4633 output: "function a() {\nvar b; /*multi-line\ncomment*/\n\nreturn c;\n}",
4634 options: [
4635 { blankLine: "always", prev: "*", next: "return" }
4636 ],
4637 errors: [{ messageId: "expectedBlankLine" }]
4638 },
4639 {
4640 code: "function a() {\nvar b;\n/*multi-line\ncomment*/ return c;\n}",
4641 output: "function a() {\nvar b;\n\n/*multi-line\ncomment*/ return c;\n}",
4642 options: [
4643 { blankLine: "always", prev: "*", next: "return" }
4644 ],
4645 errors: [{ messageId: "expectedBlankLine" }]
4646 },
4647 {
4648 code: "function a() {\nvar b; /*multi-line\ncomment*/ return c;\n}",
4649 output: "function a() {\nvar b; /*multi-line\ncomment*/\n\n return c;\n}",
4650 options: [
4651 { blankLine: "always", prev: "*", next: "return" }
4652 ],
4653 errors: [{ messageId: "expectedBlankLine" }]
4654 },
4655 {
4656 code: "function a() {\nvar b;\n//comment\nreturn;\n}",
4657 output: "function a() {\nvar b;\n\n//comment\nreturn;\n}",
4658 options: [
4659 { blankLine: "always", prev: "*", next: "return" }
4660 ],
4661 errors: [{ messageId: "expectedBlankLine" }]
4662 },
4663 {
4664 code: "function a() {\nvar b; //comment\nreturn;\n}",
4665 output: "function a() {\nvar b; //comment\n\nreturn;\n}",
4666 options: [
4667 { blankLine: "always", prev: "*", next: "return" }
4668 ],
4669 errors: [{ messageId: "expectedBlankLine" }]
4670 },
4671 {
4672 code: "function a() {\nvar b;\n/* comment */ return;\n}",
4673 output: "function a() {\nvar b;\n\n/* comment */ return;\n}",
4674 options: [
4675 { blankLine: "always", prev: "*", next: "return" }
4676 ],
4677 errors: [{ messageId: "expectedBlankLine" }]
4678 },
4679 {
4680 code: "function a() {\nvar b;\n//comment\n/* comment */ return;\n}",
4681 output: "function a() {\nvar b;\n\n//comment\n/* comment */ return;\n}",
4682 options: [
4683 { blankLine: "always", prev: "*", next: "return" }
4684 ],
4685 errors: [{ messageId: "expectedBlankLine" }]
4686 },
4687 {
4688 code: "function a() {\nvar b; /* comment */ return;\n}",
4689 output: "function a() {\nvar b; /* comment */\n\n return;\n}",
4690 options: [
4691 { blankLine: "always", prev: "*", next: "return" }
4692 ],
4693 errors: [{ messageId: "expectedBlankLine" }]
4694 },
4695 {
4696 code: "function a() {\nvar b; /* comment */\nreturn;\n}",
4697 output: "function a() {\nvar b; /* comment */\n\nreturn;\n}",
4698 options: [
4699 { blankLine: "always", prev: "*", next: "return" }
4700 ],
4701 errors: [{ messageId: "expectedBlankLine" }]
4702 },
4703 {
4704 code: "function a() {\nvar b;\nreturn; //comment\n}",
4705 output: "function a() {\nvar b;\n\nreturn; //comment\n}",
4706 options: [
4707 { blankLine: "always", prev: "*", next: "return" }
4708 ],
4709 errors: [{ messageId: "expectedBlankLine" }]
4710 },
4711 {
4712 code: "function a() {\nvar b; return; //comment\n}",
4713 output: "function a() {\nvar b;\n\n return; //comment\n}",
4714 options: [
4715 { blankLine: "always", prev: "*", next: "return" }
4716 ],
4717 errors: [{ messageId: "expectedBlankLine" }]
4718 },
4719
4720 //----------------------------------------------------------------------
4721 // From JSCS disallowPaddingNewLinesAfterBlocks
4722 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/disallow-padding-newlines-after-blocks.js
4723 //----------------------------------------------------------------------
4724
4725 {
4726 code: "if(true){}\n\nvar a = 2;",
4727 output: "if(true){}\nvar a = 2;",
4728 options: [
4729 { blankLine: "never", prev: "block-like", next: "*" }
4730 ],
4731 errors: [{ messageId: "unexpectedBlankLine" }]
4732 },
4733 {
4734 code: "if(true){\nif(true) {}\n\nvar a = 2;}",
4735 output: "if(true){\nif(true) {}\nvar a = 2;}",
4736 options: [
4737 { blankLine: "never", prev: "block-like", next: "*" }
4738 ],
4739 errors: [{ messageId: "unexpectedBlankLine" }]
4740 },
4741 {
4742 code: "(function(){\n})()\n\nvar a = 2;",
4743 output: "(function(){\n})()\nvar a = 2;",
4744 options: [
4745 { blankLine: "never", prev: "block-like", next: "*" }
4746 ],
4747 errors: [{ messageId: "unexpectedBlankLine" }]
4748 },
4749 {
4750 code: "+(function(){\n})()\n\nvar a = 2;",
4751 output: "+(function(){\n})()\nvar a = 2;",
4752 options: [
4753 { blankLine: "never", prev: "block-like", next: "*" }
4754 ],
4755 errors: [{ messageId: "unexpectedBlankLine" }]
4756 },
4757 {
4758 code: "var a = function() {};\n\nvar b = 2;",
4759 output: "var a = function() {};\nvar b = 2;",
4760 options: [
4761 { blankLine: "never", prev: "block-like", next: "*" }
4762 ],
4763 errors: [{ messageId: "unexpectedBlankLine" }]
4764 },
4765
4766 //----------------------------------------------------------------------
4767 // From JSCS disallowPaddingNewLinesBeforeExport
4768 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/disallow-padding-newlines-before-export.js
4769 //----------------------------------------------------------------------
4770
4771 {
4772 code: "var a = 2;\n\nmodule.exports = a;",
4773 output: "var a = 2;\nmodule.exports = a;",
4774 options: [
4775 { blankLine: "never", prev: "*", next: "cjs-export" }
4776 ],
4777 errors: [{ messageId: "unexpectedBlankLine" }]
4778 },
4779
4780 //----------------------------------------------------------------------
4781 // From JSCS disallowPaddingNewLinesBeforeExport
4782 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/disallow-padding-newlines-before-keywords.js
4783 //----------------------------------------------------------------------
4784
4785 {
4786 code: "function x() { var a;\n\nreturn; }",
4787 output: "function x() { var a;\nreturn; }",
4788 options: [
4789 { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] }
4790 ],
4791 errors: [{ messageId: "unexpectedBlankLine" }]
4792 },
4793 {
4794 code: "function x() { var a = true;\n\nif (a) { a = !a; }; }",
4795 output: "function x() { var a = true;\nif (a) { a = !a; }; }",
4796 options: [
4797 { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] }
4798 ],
4799 errors: [{ messageId: "unexpectedBlankLine" }]
4800 },
4801 {
4802 code: "function x() { var a = true;\n\nfor (var i = 0; i < 10; i++) { a = !a; }; }",
4803 output: "function x() { var a = true;\nfor (var i = 0; i < 10; i++) { a = !a; }; }",
4804 options: [
4805 { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] }
4806 ],
4807 errors: [{ messageId: "unexpectedBlankLine" }]
4808 },
4809 {
4810 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; } }",
4811 output: "function x() { var y = true;\nswitch (\"Oranges\") { case \"Oranges\": y = !y;\nbreak;\ncase \"Apples\": y = !y;\nbreak; default: y = !y; } }",
4812 options: [
4813 { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] }
4814 ],
4815 errors: [
4816 { messageId: "unexpectedBlankLine" },
4817 { messageId: "unexpectedBlankLine" },
4818 { messageId: "unexpectedBlankLine" },
4819 { messageId: "unexpectedBlankLine" }
4820 ]
4821 },
4822 {
4823 code: "function x() {try { var a;\n\nthrow 0; } catch (e) { var b = 0;\n\nthrow e; } }",
4824 output: "function x() {try { var a;\nthrow 0; } catch (e) { var b = 0;\nthrow e; } }",
4825 options: [
4826 { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] }
4827 ],
4828 errors: [
4829 { messageId: "unexpectedBlankLine" },
4830 { messageId: "unexpectedBlankLine" }
4831 ]
4832 },
4833 {
4834 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; }",
4835 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; }",
4836 options: [
4837 { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] }
4838 ],
4839 errors: [
4840 { messageId: "unexpectedBlankLine" },
4841 { messageId: "unexpectedBlankLine" },
4842 { messageId: "unexpectedBlankLine" }
4843 ]
4844 },
4845
4846 //----------------------------------------------------------------------
4847 // From JSCS requirePaddingNewLinesAfterBlocks
4848 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/require-padding-newlines-after-blocks.js
4849 //----------------------------------------------------------------------
4850
4851 {
4852 code: "if(true){}\nvar a = 2;",
4853 output: "if(true){}\n\nvar a = 2;",
4854 options: [
4855 { blankLine: "always", prev: "block-like", next: "*" }
4856 ],
4857 errors: [{ messageId: "expectedBlankLine" }]
4858 },
4859 {
4860 code: "var a = function() {\n};\nvar b = 2;",
4861 output: "var a = function() {\n};\n\nvar b = 2;",
4862 options: [
4863 { blankLine: "always", prev: "block-like", next: "*" }
4864 ],
4865 errors: [{ messageId: "expectedBlankLine" }]
4866 },
4867 {
4868 code: "if(true){\nif(true) {}\nvar a = 2;}",
4869 output: "if(true){\nif(true) {}\n\nvar a = 2;}",
4870 options: [
4871 { blankLine: "always", prev: "block-like", next: "*" }
4872 ],
4873 errors: [{ messageId: "expectedBlankLine" }]
4874 },
4875 {
4876 code: "(function(){\n})()\nvar a = 2;",
4877 output: "(function(){\n})()\n\nvar a = 2;",
4878 options: [
4879 { blankLine: "always", prev: "block-like", next: "*" }
4880 ],
4881 errors: [{ messageId: "expectedBlankLine" }]
4882 },
4883 {
4884 code: "var a = function() {\n};\nvar b = 2;",
4885 output: "var a = function() {\n};\n\nvar b = 2;",
4886 options: [
4887 { blankLine: "always", prev: "multiline-block-like", next: "*" }
4888 ],
4889 errors: [{ messageId: "expectedBlankLine" }]
4890 },
4891 {
4892 code: "(function(){\n})()\nvar a = 2;",
4893 output: "(function(){\n})()\n\nvar a = 2;",
4894 options: [
4895 { blankLine: "always", prev: "multiline-block-like", next: "*" }
4896 ],
4897 errors: [{ messageId: "expectedBlankLine" }]
4898 },
4899
4900 //----------------------------------------------------------------------
4901 // From JSCS requirePaddingNewLinesBeforeExport
4902 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/require-padding-newlines-before-export.js
4903 //----------------------------------------------------------------------
4904
4905 {
4906 code: "var a = 2;\nmodule.exports = a;",
4907 output: "var a = 2;\n\nmodule.exports = a;",
4908 options: [
4909 { blankLine: "always", prev: "*", next: "cjs-export" }
4910 ],
4911 errors: [{ messageId: "expectedBlankLine" }]
4912 },
4913
4914 //----------------------------------------------------------------------
4915 // From JSCS requirePaddingNewlinesBeforeKeywords
4916 // https://github.com/jscs-dev/node-jscs/blob/44f9b86eb0757fd4ca05a81a50450c5f1b25c37b/test/specs/rules/require-padding-newlines-before-keywords.js
4917 //----------------------------------------------------------------------
4918
4919 {
4920 code: "function x() { var a; return; }",
4921 output: "function x() { var a;\n\n return; }",
4922 options: [
4923 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
4924 ],
4925 errors: [{ messageId: "expectedBlankLine" }]
4926 },
4927 {
4928 code: "function x() { var a = true; for (var i = 0; i < 10; i++) { a = !a; }; }",
4929 output: "function x() { var a = true;\n\n for (var i = 0; i < 10; i++) { a = !a; }; }",
4930 options: [
4931 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
4932 ],
4933 errors: [{ messageId: "expectedBlankLine" }]
4934 },
4935 {
4936 code: "function x() { var y = true; switch (\"Oranges\") { case \"Oranges\": y = !y; break; case \"Apples\": y = !y; break; default: y = !y; } }",
4937 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; } }",
4938 options: [
4939 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
4940 ],
4941 errors: [
4942 { messageId: "expectedBlankLine" },
4943 { messageId: "expectedBlankLine" },
4944 { messageId: "expectedBlankLine" },
4945 { messageId: "expectedBlankLine" },
4946 { messageId: "expectedBlankLine" }
4947 ]
4948 },
4949 {
4950 code: "function x() { var a = true; while (!a) { a = !a; }; }",
4951 output: "function x() { var a = true;\n\n while (!a) { a = !a; }; }",
4952 options: [
4953 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
4954 ],
4955 errors: [{ messageId: "expectedBlankLine" }]
4956 },
4957 {
4958 code: "function x() {try { var a; throw 0; } catch (e) { var b = 0; throw e; } }",
4959 output: "function x() {try { var a;\n\n throw 0; } catch (e) { var b = 0;\n\n throw e; } }",
4960 options: [
4961 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
4962 ],
4963 errors: [
4964 { messageId: "expectedBlankLine" },
4965 { messageId: "expectedBlankLine" }
4966 ]
4967 },
4968 {
4969 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; }",
4970 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; }",
4971 options: [
4972 { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] }
4973 ],
4974 errors: [
4975 { messageId: "expectedBlankLine" },
4976 { messageId: "expectedBlankLine" },
4977 { messageId: "expectedBlankLine" }
4978 ]
4979 }
4980 ]
4981 });