Repository navigation
fix: avoid double newline at EOF when file starts with a shebang - #2527
Open
Dextheking1 wants to merge 2 commits into
Open
Dextheking1 wants to merge 2 commits into
Dextheking1 wants to merge 2 commits into
Conversation
Files whose first child is an inline node (e.g. a shebang line) had their trailing statement group closed with a hardline, and genericPrint then appended another one via fileShouldEndWithHardline, leaving a blank line at the end of the file. Fixes prettier#2430
Previous run (2026-09-24) failed with purged logs; local full suite (1174 tests, AST_COMPARE=1), eslint, prettier and the standalone build all pass. Re-running to get a fresh signal.
Dextheking1
marked this pull request as ready for review
October 24, 2026 04:09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A file starting with a shebang line ended up with two newlines at the end of the file:
formatted to
...exit($status);\n\ninstead of a single trailing newline.The shebang is parsed as a leading
inlinenode, so the statements after it get wrapped in a group whose trailingafterhardline was emitted in addition to the final hardline thatfileShouldEndWithHardlinealready appends for the program node. The fix skips the group's trailing hardline when it runs to the end of a node that already ends with a hardline.Also adds a snapshot test reproducing the exact input from the issue, and updates two existing snapshots (
tests/inline,tests/parens) that had the same spurious trailing blank line. Full test suite passes: 101 suites, 596 tests, 580 snapshots.Fixes #2430