File tree 2 files changed +48
-1
lines changed
2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -67,9 +67,11 @@ const create = context => {
67
67
}
68
68
69
69
const dedented = stripIndent ( joined ) ;
70
+ const trimmed = dedented . replace ( new RegExp ( `^${ eol } |${ eol } [ \t]*$` , 'g' ) , '' ) ;
71
+
70
72
const fixed
71
73
= eol
72
- + indentString ( dedented . trim ( ) , 1 , { indent : parentMargin + indent } )
74
+ + indentString ( trimmed , 1 , { indent : parentMargin + indent } )
73
75
+ eol
74
76
+ parentMargin ;
75
77
Original file line number Diff line number Diff line change @@ -486,6 +486,24 @@ test({
486
486
\`
487
487
` ) ,
488
488
} ,
489
+ {
490
+ name : 'Lines with whitespaces are kept trimmed' ,
491
+ code : fixInput ( `
492
+ outdent\`
493
+ ••Line1
494
+ ••
495
+ ••Line2
496
+ \`
497
+ ` ) ,
498
+ errors,
499
+ output : fixInput ( `
500
+ outdent\`
501
+ ••Line1
502
+
503
+ ••Line2
504
+ \`
505
+ ` ) ,
506
+ } ,
489
507
] ,
490
508
/** @type {import('eslint').RuleTester.ValidTestCase[] } */
491
509
valid : [
@@ -586,6 +604,33 @@ test({
586
604
••after
587
605
\`
588
606
` ) ,
607
+ {
608
+ name : 'Trailing spaces in the last line are preserved' ,
609
+ code : fixInput ( `
610
+ outdent\`
611
+ ••Line with trailing spaces••••
612
+ \`
613
+ ` ) ,
614
+ } ,
615
+ {
616
+ name : 'Trailing spaces in non-last line are preserved' ,
617
+ code : fixInput ( `
618
+ outdent\`
619
+ ••Line with trailing spaces••••
620
+ ••Line without trailing spaces
621
+ \`
622
+ ` ) ,
623
+ } ,
624
+ {
625
+ name : 'Empty lines are preserved' ,
626
+ code : fixInput ( `
627
+ outdent\`
628
+ ••Line1
629
+
630
+ ••Line2
631
+ \`
632
+ ` ) ,
633
+ } ,
589
634
] ,
590
635
} ) ;
591
636
You can’t perform that action at this time.
0 commit comments