Conversation
A single-line comment sets `empty_lines_allowance = 1`; when the comment is the last element before end-of-file, that adds a trailing empty-line break point, which `LineBuilder::build` rendered as a blank line before the final newline - accumulating on every reformat (`format(format(x)) != format(x)`). Drop trailing empty lines from the line list in `build`. Memory updated + pushed (with your "more internal" rationale recorded).
PR SummaryLow Risk Overview
Adds formatter regression coverage via Reviewed by Cursor Bugbot for commit 1fb1213. Bugbot is set up for automated code reviews on this repo. Configure here. |
eytan-starkware
left a comment
There was a problem hiding this comment.
@eytan-starkware reviewed 14 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

Summary
Fixes the Cairo formatter to strip extra trailing newlines from formatted output. Previously, files ending with a trailing comment (or other constructs that produced empty trailing lines) would have an extra blank line appended. The
LineBuilder::buildmethod now removes any empty trailing lines before joining, ensuring the output ends with exactly one newline. Trailing newlines have also been removed from several corelib and test files to reflect the corrected formatter behavior.A new formatter test case (
trailing_comment.cairo) is added to cover files that end with a comment and no trailing blank line.Type of change
Please check one:
Why is this change needed?
The formatter was emitting an extra trailing newline at the end of files that ended with certain constructs such as trailing comments. This caused formatted output to differ from the expected single-newline termination, producing spurious diffs when formatting was applied repeatedly.
What was the behavior or documentation before?
Files ending with a trailing comment or similar construct would be formatted with an extra blank line appended at the end of the file.
What is the behavior or documentation after?
The formatter strips any empty trailing lines before emitting output, so files end with exactly one newline regardless of their content. Files that previously had a spurious trailing newline in the corelib and test suite have been corrected to match.
Related issue or discussion (if any)
None specified.
Additional context
The fix is localized to
LineBuilder::buildinformatter_impl.rs, where a loop removes empty strings from the end of the line vector before joining them with"\n"and appending the final newline.