@@ -58,20 +58,22 @@ function filterEmptyContext(data: unknown): unknown {
58
58
function trimTrailingSpaces ( yamlString : string ) : string {
59
59
const hasTrailingNewline = yamlString . endsWith ( '\n' ) ;
60
60
const lines = yamlString . split ( '\n' ) ;
61
- const trimmedLines = lines . map ( ( line , index ) => {
62
- if ( index === lines . length - 1 && line === '' && hasTrailingNewline ) {
61
+ const trimmedLines = lines
62
+ . map ( ( line , index ) => {
63
+ if ( index === lines . length - 1 && line === '' && hasTrailingNewline ) {
64
+ return undefined ;
65
+ }
66
+ // Preserve empty lines
67
+ if ( line . trim ( ) === '' ) return '' ;
68
+ // Trim trailing spaces, preserving indentation
69
+ const match = line . match ( / ^ ( \s * ) ( .* ) $ / ) ;
70
+ if ( match ) {
71
+ const [ , indent , content ] = match ;
72
+ return indent + content . trimEnd ( ) ;
73
+ }
63
74
return line ;
64
- }
65
- // Preserve empty lines
66
- if ( line . trim ( ) === '' ) return '' ;
67
- // Trim trailing spaces, preserving indentation
68
- const match = line . match ( / ^ ( \s * ) ( .* ) $ / ) ;
69
- if ( match ) {
70
- const [ , indent , content ] = match ;
71
- return indent + content . trimEnd ( ) ;
72
- }
73
- return line ;
74
- } ) ;
75
+ } )
76
+ . filter ( ( line ) => line !== undefined ) ;
75
77
76
78
return trimmedLines . join ( '\n' ) ;
77
79
}
0 commit comments