File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -7,18 +7,20 @@ import _ from 'lodash';
7
7
import glob from 'glob' ;
8
8
9
9
const trimCode = ( code ) => {
10
- let lines = code . trim ( ) . split ( '\n' ) ;
10
+ let lines = code . replace ( / ^ \n / , '' ) . trimEnd ( ) . split ( '\n' ) ;
11
11
12
- const indendation = lines [ lines . length - 1 ] . match ( / ^ \s + / ) ;
12
+ const firsLineIndentation = lines [ 0 ] . match ( / ^ \s + / ) ;
13
+ const lastLineIndentation = lines [ lines . length - 1 ] . match ( / ^ \s + / ) ;
13
14
14
- const indentSize = indendation ? indendation [ 0 ] . length : 0 ;
15
+ const firstIndentSize = firsLineIndentation ? firsLineIndentation [ 0 ] . length : 0 ;
16
+ const lastIndentSize = lastLineIndentation ? lastLineIndentation [ 0 ] . length : 0 ;
15
17
16
18
lines = lines . map ( ( line , index ) => {
17
19
if ( index === 0 ) {
18
- return line ;
20
+ return line . slice ( Math . min ( firstIndentSize , lastIndentSize ) ) ;
19
21
}
20
22
21
- return line . slice ( indentSize ) ;
23
+ return line . slice ( lastIndentSize ) ;
22
24
} ) ;
23
25
24
26
return lines . join ( '\n' ) ;
You can’t perform that action at this time.
0 commit comments