Skip to content

feat: Ensure single final newline - #502

Closed
humtta wants to merge 2 commits into
typstyle-rs:masterfrom
humtta-forks:feat/single-final-newline
Closed

humtta wants to merge 2 commits into
typstyle-rs:masterfrom
humtta-forks:feat/single-final-newline

Conversation

@humtta

@humtta humtta commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR ensures that formatted files end with exactly one newline.

Changes

  • Normalize the formatter output to remove trailing newlines and append one final newline.
  • Add unit tests covering inputs with no trailing newline and with multiple trailing newlines.
  • Document the feature in CHANGELOG.

Testing

Compiled and ran the binary on files with no trailing newlines and with multiple trailing newlines. Also ran the unit tests; all of them passed successfully.

@QuadnucYard

Copy link
Copy Markdown
Collaborator

This is intended behavior.

@humtta

humtta commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

I might be missing something, but is there any reason why this is the expected behavior? Formatters usually normalize extra (or missing) trailing newlines.

@QuadnucYard

Copy link
Copy Markdown
Collaborator

I might be missing something, but is there any reason why this is the expected behavior? Formatters usually normalize extra (or missing) trailing newlines.

This is markup, not code in the general sense. Blank lines can be intentional. As long as we preserve newlines in the body, the ending should be no exception.

Of course, we could have an option to control the behavior. But by default, we tend to preserve. You can still turn on the trimming option in VSCode if you like, as an alternative.

@humtta

humtta commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

That's fine. If you think it's reasonable, I can implement a --trim-final-newlines flag in another PR.

@humtta
humtta deleted the feat/single-final-newline branch September 23, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants