File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed
Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -67,9 +67,11 @@ const create = context => {
6767 }
6868
6969 const dedented = stripIndent ( joined ) ;
70+ const trimmed = dedented . replace ( new RegExp ( `^${ eol } |${ eol } [ \t]*$` , 'g' ) , '' ) ;
71+
7072 const fixed
7173 = eol
72- + indentString ( dedented . trim ( ) , 1 , { indent : parentMargin + indent } )
74+ + indentString ( trimmed , 1 , { indent : parentMargin + indent } )
7375 + eol
7476 + parentMargin ;
7577
Original file line number Diff line number Diff line change @@ -486,6 +486,24 @@ test({
486486 \`
487487 ` ) ,
488488 } ,
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+ } ,
489507 ] ,
490508 /** @type {import('eslint').RuleTester.ValidTestCase[] } */
491509 valid : [
@@ -586,6 +604,33 @@ test({
586604 ••after
587605 \`
588606 ` ) ,
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+ } ,
589634 ] ,
590635} ) ;
591636
You can’t perform that action at this time.
0 commit comments