Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ryan-m-walker
Copy link
Contributor

Summary

I noticed while working on issue #6183 that the some CSS dimension units are being formatted inconsistently than how they are handled by Prettier. Most units are formatted to lowercase but a few are formatted with some uppercase letters, both in most documentation examples and in Prettier. Specifically Q, hZ and kHz. This PR adds a new FormatDimensionUnit util based on the FormatTokenAsLowercase that maps the special units to the correct formatting. My understanding is the the formatter is aimed to maintain parity with Prettier so I figured I'd open a quick PR with this change.

Let me know if a patch makes sense here. This change could change user's existing formatted code so wasn't sure if patch made the most sense or not

Test Plan

crates/biome_css_formatter/tests/specs/css/units.css.snap snapshot test updated to reflect the new formatting

Docs

n/a

AI Usage Disclosure

Really didn't use much AI at all. All code was hand written.

@changeset-bot
Copy link

changeset-bot bot commented Nov 20, 2025

🦋 Changeset detected

Latest commit: bc9dc9e

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

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

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

@github-actions github-actions bot added A-Formatter Area: formatter L-CSS Language: CSS labels Nov 20, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 20, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces FormatDimensionUnit, a new CSS dimension formatter that properly capitalises unit suffixes according to CSS specifications. The formatter replaces the previous FormatTokenAsLowercase approach in both regular and unknown dimension value handlers. The implementation includes a helper function mapping lowercase variants (hz, khz, q) to their correct forms (Hz, kHz, Q), with corresponding test updates to validate the formatting behaviour.

Possibly related PRs

Suggested reviewers

  • siketyan

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately describes the main change: updating CSS dimension unit formatting to match Prettier's handling of non-lowercase units.
Description check ✅ Passed The description provides clear context about the formatting inconsistency, references relevant documentation and playground examples, and explains the technical approach taken.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2050629 and bc9dc9e.

📒 Files selected for processing (1)
  • .changeset/wise-dots-rush.md (1 hunks)

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb1458b and 903d475.

⛔ Files ignored due to path filters (1)
  • crates/biome_css_formatter/tests/specs/css/units.css.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (4)
  • .changeset/wise-dots-rush.md (1 hunks)
  • crates/biome_css_formatter/src/css/value/regular_dimension.rs (2 hunks)
  • crates/biome_css_formatter/src/css/value/unknown_dimension.rs (2 hunks)
  • crates/biome_css_formatter/src/utils/string_utils.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
crates/biome_css_formatter/src/css/value/unknown_dimension.rs (1)
crates/biome_css_formatter/src/utils/string_utils.rs (2)
  • from (24-26)
  • from (305-307)
crates/biome_css_formatter/src/utils/string_utils.rs (4)
crates/biome_html_formatter/src/utils/formatters.rs (1)
  • fmt (22-34)
crates/biome_css_formatter/src/lib.rs (8)
  • fmt (192-201)
  • fmt (245-247)
  • fmt (310-326)
  • format (45-45)
  • format (58-60)
  • format (75-80)
  • format (95-97)
  • format (342-344)
crates/biome_formatter/src/builders.rs (2)
  • token (251-259)
  • text (279-283)
crates/biome_css_formatter/src/trivia.rs (1)
  • format_replaced (30-38)
crates/biome_css_formatter/src/css/value/regular_dimension.rs (1)
crates/biome_css_formatter/src/utils/string_utils.rs (2)
  • from (24-26)
  • from (305-307)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: autofix
  • GitHub Check: Test Node.js API
🔇 Additional comments (5)
crates/biome_css_formatter/src/css/value/unknown_dimension.rs (1)

1-4: LGTM!

The import and usage correctly apply the new FormatDimensionUnit formatter to the unit token.

Also applies to: 21-21

.changeset/wise-dots-rush.md (1)

1-25: LGTM!

Clear documentation with helpful before/after examples.

crates/biome_css_formatter/src/css/value/regular_dimension.rs (1)

1-1: LGTM!

Correctly applies the new FormatDimensionUnit formatter.

Also applies to: 18-18

crates/biome_css_formatter/src/utils/string_utils.rs (2)

300-308: Structure looks good.

The struct definition and From implementation follow the established pattern from FormatTokenAsLowercase.


310-338: Test coverage gap confirmed—add lowercase unit test cases.

The current snapshot tests only cover uppercase inputs (5HZ, 5KHZ, 5Q). There are no test cases for already-lowercase units (5hz, 5khz, 5q), which means the match logic in the formatter code is never exercised by the tests. Add test cases for lowercase inputs to crates/biome_css_formatter/tests/specs/css/units.css to ensure complete coverage of the casing conversion logic.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 20, 2025

CodSpeed Performance Report

Merging #8175 will not alter performance

Comparing ryan-m-walker:fix/fix-css-formatting-non-lowercase-dimensions (bc9dc9e) with main (fb1458b)1

Summary

✅ 29 untouched
⏩ 126 skipped2

Footnotes

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

  2. 126 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.

@ryan-m-walker ryan-m-walker changed the title fix(css) updating formatting of non-lowercase CSS dimension units fix(css): updating formatting of non-lowercase CSS dimension units Nov 20, 2025
@ematipico ematipico added this pull request to the merge queue Nov 20, 2025
Merged via the queue into biomejs:main with commit 0c8349e Nov 20, 2025
15 of 16 checks passed
@github-actions github-actions bot mentioned this pull request Nov 19, 2025
ryan-m-walker added a commit to ryan-m-walker/biome that referenced this pull request Nov 23, 2025
l0ngvh pushed a commit to l0ngvh/biome that referenced this pull request Dec 21, 2025
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants