+
Skip to content

Conversation

ematipico
Copy link
Member

@ematipico ematipico commented Jul 28, 2025

Summary

This PR refactors how the formatter formats trivias. Up until now, all sorts of trivia were formatted using generic functions such as: format_replaced, format_removed, format_skipped_token_trivia, etc.

These functions, however, have a shared logic that can't be overridden by specialised formatters.

In this PR, we introduce a trait called FormatToken, which exposes functions such as format_replaced and more. Those functions, now, must be implemented within the language formatters, which means that biome_formatter no longer knows how to do that.

This refactor has some small repercussions on the separated lists, where now we need to pass generic functions on_skipped and on_removed, because the generic formatter doesn't know how to print their trivia anymore.

With this change, we can implement a specialised version of fmt_skipped that doesn't rely on the nestle logic: #5356

Test Plan

The current CI should stay all green

Docs

Copy link

changeset-bot bot commented Jul 28, 2025

⚠️ No Changeset found

Latest commit: 7676748

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions github-actions bot added 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 L-Grit Language: GritQL labels Jul 28, 2025
@ematipico ematipico force-pushed the refactor/format-with-specialised-tokens branch from 4a9f3fa to d161316 Compare July 28, 2025 14:41
Copy link

codspeed-hq bot commented Jul 28, 2025

CodSpeed Performance Report

Merging #7052 will not alter performance

Comparing refactor/format-with-specialised-tokens (a94c114) with main (b091ddf)1

Summary

✅ 115 untouched benchmarks

Footnotes

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

@ematipico ematipico force-pushed the refactor/format-with-specialised-tokens branch from d161316 to 48e43b3 Compare July 28, 2025 15:01
@ematipico ematipico requested review from a team and dyc3 July 28, 2025 15:11
@ematipico ematipico marked this pull request as ready for review July 28, 2025 15:11
Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is good, I think the massive diff could be avoidable. See below.

@ematipico ematipico force-pushed the refactor/format-with-specialised-tokens branch from 48e43b3 to c662a38 Compare July 28, 2025 16:33
@ematipico ematipico requested a review from dyc3 July 28, 2025 16:33
@ematipico ematipico force-pushed the refactor/format-with-specialised-tokens branch from c662a38 to 7676748 Compare July 28, 2025 16:34
Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! The contributing docs for the formatter will likely need to be updated too. Not going to block on that for this PR.

@ematipico ematipico merged commit f75fea2 into main Jul 28, 2025
29 of 45 checks passed
@ematipico ematipico deleted the refactor/format-with-specialised-tokens branch July 28, 2025 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Formatter Area: formatter L-CSS Language: CSS L-Grit Language: GritQL L-HTML Language: HTML 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.

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载