Skip to content

Commit bd7b4b5

Browse files
authored
Merge pull request #156 from vishnoianil/fix-newline
Remove trailing new line from the downloaded yaml file
2 parents 1808a39 + 5a27c93 commit bd7b4b5

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/utils/yamlConfig.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,22 @@ function filterEmptyContext(data: unknown): unknown {
5858
function trimTrailingSpaces(yamlString: string): string {
5959
const hasTrailingNewline = yamlString.endsWith('\n');
6060
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+
}
6374
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);
7577

7678
return trimmedLines.join('\n');
7779
}

0 commit comments

Comments
 (0)