Skip to content

Conversation

@ematipico
Copy link
Member

Summary

This is a proposal to add trailingNewline to the Biome formatter.

I would like to know what @biomejs/core-contributors and @biomejs/maintainers think about it.

I would plan to add this option as long as we document the unsafety of removing the trailing newline from the files. Hence, this will never be the default.

For example, there are various historical issues about files that don't have a newline:

A user also raised a concern regarding POSIX. However, this seems to be more bounced (I asked Claude Code about this)

A file without a trailing newline doesn't strictly conform to the POSIX definition of a "text file," because it contains a final sequence of characters that doesn't meet the definition of a "line." So in a narrow, pedantic reading of the standard, such a file isn't a well-formed text file.
What's Misleading
However, this doesn't mean the file is therefore classified as a "binary file." That's a false dichotomy. POSIX doesn't define binary files as "anything that isn't a text file." In practice:

Binary files typically contain non-printable characters, null bytes, or data not intended to be interpreted as character-encoded text
A file missing a trailing newline is still character data, still human-readable, still processed as text by virtually every tool—it's just non-conforming text

Still, it seems to be a concern to acknowledge, and maybe document.

Here's what I was thinking:

  • if we accept it, we add some resources to the docs, so users are aware of the possible issues
  • if we don't, we can document on our website why we decided against this option

Note

The majority of the code was created with Claude Code, but I to intervene too because at some point the AI didn't know how to connect the dots. The AI updated all the configs and tests.

I updated the snapshots to make the newline more evident, since it wasn't before. I wrote some gluecode to make the feature working via Workspace, and edited the changeset

Test Plan

New tests added.

Docs

TBD

@changeset-bot
Copy link

changeset-bot bot commented Dec 2, 2025

🦋 Changeset detected

Latest commit: 1b63a75

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
@biomejs/biome Minor
@biomejs/cli-win32-x64 Minor
@biomejs/cli-win32-arm64 Minor
@biomejs/cli-darwin-x64 Minor
@biomejs/cli-darwin-arm64 Minor
@biomejs/cli-linux-x64 Minor
@biomejs/cli-linux-arm64 Minor
@biomejs/cli-linux-x64-musl Minor
@biomejs/cli-linux-arm64-musl Minor
@biomejs/wasm-web Minor
@biomejs/wasm-bundler Minor
@biomejs/wasm-nodejs Minor
@biomejs/backend-jsonrpc Patch
@biomejs/js-api Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ematipico ematipico changed the title feat(lsp): report progress while scanning the project (#7961) feat(formatter): trailing newline Dec 2, 2025
@github-actions github-actions bot added A-CLI Area: CLI A-Project Area: project A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages L-CSS Language: CSS L-JSON Language: JSON and super languages L-HTML Language: HTML and super languages L-Grit Language: GritQL A-Type-Inference Area: type inference labels Dec 2, 2025
@ematipico ematipico force-pushed the feat/ending-newline branch from 8b279bb to f2e5e48 Compare December 2, 2025 13:30
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 2, 2025

CodSpeed Performance Report

Merging #8334 will not alter performance

Comparing feat/ending-newline (1b63a75) with next (da85e3c)1

Summary

✅ 58 untouched
⏩ 95 skipped2

Footnotes

  1. No successful run was found on next (4f7909d) during the generation of this report, so da85e3c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 95 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@arendjr
Copy link
Contributor

arendjr commented Dec 2, 2025

Not a fan of the option, but if there is user demand and proper documentation, then I don’t mind indeed.

@ematipico
Copy link
Member Author

Also considered naming the option unsafeTrailingNewline, but I thought it would be too much of an opinion

Copy link
Contributor

dyc3 commented Dec 2, 2025

I share @arendjr 's sentiment. The logic is simple enough, so it's not a huge deal I suppose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Formatter Area: formatter A-Project Area: project A-Type-Inference Area: type inference L-CSS Language: CSS L-Grit Language: GritQL L-HTML Language: HTML and super languages L-JavaScript Language: JavaScript and super languages L-JSON Language: JSON and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants