@@ -467,4 +467,132 @@ describe('linting algorithms', () => {
467
467
` ) ;
468
468
} ) ;
469
469
} ) ;
470
+
471
+ describe ( 'if/else consistency' , ( ) => {
472
+ const ruleId = 'if-else-consistency' ;
473
+ it ( 'rejects single-line if with multiline else' , async ( ) => {
474
+ await assertLint (
475
+ positioned `
476
+ <emu-alg>
477
+ 1. ${ M } If some condition holds, do something.
478
+ 1. Else,
479
+ 1. Do something else.
480
+ </emu-alg>` ,
481
+ {
482
+ ruleId,
483
+ nodeType,
484
+ message : '"If" steps should be multiline whenever their corresponding "Else" is' ,
485
+ }
486
+ ) ;
487
+ } ) ;
488
+
489
+ it ( 'rejects single-line if with multiline else-if' , async ( ) => {
490
+ await assertLint (
491
+ positioned `
492
+ <emu-alg>
493
+ 1. ${ M } If some condition holds, do something.
494
+ 1. Else if another condition holds, then
495
+ 1. Do something else.
496
+ 1. Else,
497
+ 1. Do something yet otherwise.
498
+ </emu-alg>` ,
499
+ {
500
+ ruleId,
501
+ nodeType,
502
+ message : '"If" steps should be multiline whenever their corresponding "Else" is' ,
503
+ }
504
+ ) ;
505
+ } ) ;
506
+
507
+ it ( 'rejects single-line else-if with multiline else' , async ( ) => {
508
+ await assertLint (
509
+ positioned `
510
+ <emu-alg>
511
+ 1. If some condition holds, do something.
512
+ 1. ${ M } Else if another condition holds, do something else.
513
+ 1. Else,
514
+ 1. Do something yet otherwise.
515
+ </emu-alg>` ,
516
+ {
517
+ ruleId,
518
+ nodeType,
519
+ message : '"If" steps should be multiline whenever their corresponding "Else" is' ,
520
+ }
521
+ ) ;
522
+ } ) ;
523
+
524
+ it ( 'rejects multi-line if with single-line else' , async ( ) => {
525
+ await assertLint (
526
+ positioned `
527
+ <emu-alg>
528
+ 1. If some condition holds, then
529
+ 1. Do something.
530
+ 1. ${ M } Else do something else.
531
+ </emu-alg>` ,
532
+ {
533
+ ruleId,
534
+ nodeType,
535
+ message : '"Else" steps should be multiline whenever their corresponding "If" is' ,
536
+ }
537
+ ) ;
538
+ } ) ;
539
+
540
+ it ( 'rejects multi-line if with single-line else-f' , async ( ) => {
541
+ await assertLint (
542
+ positioned `
543
+ <emu-alg>
544
+ 1. If some condition holds, then
545
+ 1. Do something.
546
+ 1. ${ M } Else if another condition holds do something else.
547
+ 1. Else, do something yet otherwise.
548
+ </emu-alg>` ,
549
+ {
550
+ ruleId,
551
+ nodeType,
552
+ message : '"Else" steps should be multiline whenever their corresponding "If" is' ,
553
+ }
554
+ ) ;
555
+ } ) ;
556
+
557
+ it ( 'rejects multi-line else-if with single-line else' , async ( ) => {
558
+ await assertLint (
559
+ positioned `
560
+ <emu-alg>
561
+ 1. If some condition holds, then
562
+ 1. Do something.
563
+ 1. Else if another condition holds, then
564
+ 1. Do something else.
565
+ 1. ${ M } Else, do something yet otherwise.
566
+ </emu-alg>` ,
567
+ {
568
+ ruleId,
569
+ nodeType,
570
+ message : '"Else" steps should be multiline whenever their corresponding "If" is' ,
571
+ }
572
+ ) ;
573
+ } ) ;
574
+
575
+ it ( 'negative' , async ( ) => {
576
+ await assertLintFree ( `
577
+ <emu-alg>
578
+ 1. If some condition holds, do something simple.
579
+ 1. Else, do something yet otherwise simple.
580
+ 1. If some condition holds, do something simple.
581
+ 1. Else if another condition holds, do something else simple.
582
+ 1. Else, do something yet otherwise simple.
583
+ 1. NOTE: Also works for multiline.
584
+ 1. If some condition holds, then
585
+ 1. Do something simple.
586
+ 1. Else,
587
+ 1. Do something yet otherwise simple.
588
+ 1. If some condition holds, then
589
+ 1. Do something simple.
590
+ 1. Else if another condition holds, then
591
+ 1. Do something else simple.
592
+ 1. Else,
593
+ 1. Do something yet otherwise simple.
594
+ </emu-alg>
595
+ ` ) ;
596
+ } ) ;
597
+ } ) ;
470
598
} ) ;
0 commit comments