Skip to content

Commit

Permalink
Fix trailing newline
Browse files Browse the repository at this point in the history
  • Loading branch information
dangoslen committed Nov 11, 2023
1 parent 906525b commit b579163
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions __tests__/changelog-updater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ test('should keep the trailing newline', async () => {
- Update \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))
## [v0.9.0]
`)
})

Expand Down
8 changes: 7 additions & 1 deletion src/changelog-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function writeEntry(
// Push a copy of the last line to the end of the contents and include the line-ending
// It will be overwritten when we re-write all the contents
const lastLine = contents[contents.length - 1]
const length = contents.push(`${lastLine}${EOL}`)
const length = contents.push(lastLine)

// Copy the contents from the last line up until the line of the entry we want to write
for (let i = length - 1; i > lineNumber; i--) {
Expand All @@ -190,6 +190,12 @@ function writeEntry(
// Write the entry
contents[lineNumber] = changelogEntry

// If the last line was empty, assume it is a trailing newline
// Append an additional newline to write the trailing newline
if (lastLine == '') {

Check failure on line 195 in src/changelog-updater.ts

View workflow job for this annotation

GitHub Actions / unit-tests

Expected '===' and instead saw '=='
contents.push('')
}

// Write the contents out, joining with EOL
fs.writeFileSync(changelogPath, contents.join(EOL))
}
Expand Down

0 comments on commit b579163

Please sign in to comment.