Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(css_formatter): improve CSS numeric formatting #5052

Merged
merged 6 commits into from
Feb 9, 2025

Conversation

ah-yu
Copy link
Contributor

@ah-yu ah-yu commented Feb 7, 2025

Summary

Improve CSS numeric formatting with two changes:

  • For cases like .5em, ensure the numeric part is formatted as a number rather than simply printing the token as-is.
  • Remove trailing zeros in cases like x.0000.
    Prettier formats such numbers differently across languages. In JavaScript, x.0000 is formatted as x.0, whereas in CSS, it is formatted as x.

Closes #5031
Closes #5005

Test Plan

Added tests

@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 labels Feb 7, 2025
Copy link

codspeed-hq bot commented Feb 7, 2025

CodSpeed Performance Report

Merging #5052 will not alter performance

Comparing ah-yu:fix/num-fmt (9dc87f3) with next (de27f6f)

Summary

✅ 94 untouched benchmarks

@dyc3
Copy link
Contributor

dyc3 commented Feb 7, 2025

This would also effectively close #5005, right? Since this makes the formatter conflict with that rule.

@ematipico
Copy link
Member

I'm in favour with closing the rule, there's no need for that now

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Thank you!

.changeset/improve_formatting_of_numbers_in_css.md Outdated Show resolved Hide resolved
crates/biome_formatter/src/token/number.rs Show resolved Hide resolved
@ah-yu
Copy link
Contributor Author

ah-yu commented Feb 8, 2025

This would also effectively close #5005, right? Since this makes the formatter conflict with that rule.

Yes, I think the formatter has already handled the trailing zeros for us.

@ah-yu ah-yu merged commit 1099147 into biomejs:next Feb 9, 2025
13 checks passed
@ah-yu ah-yu deleted the fix/num-fmt branch February 9, 2025 12:31
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-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.

3 participants