Skip to content

Commit

Permalink
feat(css_formatter): use format_number_token utils for css number
Browse files Browse the repository at this point in the history
  • Loading branch information
denbezrukov committed May 8, 2024
1 parent b29ac6f commit 296e463
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 224 deletions.
8 changes: 3 additions & 5 deletions crates/biome_css_formatter/src/css/value/number.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::prelude::*;
use biome_css_syntax::{CssNumber, CssNumberFields};
use biome_formatter::write;
use biome_css_syntax::CssNumber;
use biome_formatter::token::number::format_number_token;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssNumber;
impl FormatNodeRule<CssNumber> for FormatCssNumber {
fn fmt_fields(&self, node: &CssNumber, f: &mut CssFormatter) -> FormatResult<()> {
let CssNumberFields { value_token } = node.as_fields();

write!(f, [value_token.format()])
format_number_token(&node.value_token()?).fmt(f)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
source: crates/biome_formatter_test/src/snapshot_builder.rs
info: css/color/functional_colors.css
---

# Input

```css
Expand Down Expand Up @@ -60,17 +59,15 @@ Quote style: Double Quotes
color: rgb(100%, 0%, 60%);
color: rgba(51, 170, 51, 0.1);
color: hsl(.75turn, 60%, 70%);
color: hsla(240, 100%, 50%, .05);
color: hsla(240, 100%, 50%, 0.05);
}

.whitespace {
color: rgba(51 170 51 / 0.4);
color: rgba(
51 170 51 / 40%);
color: hsl(270 60% 50% / .15);
color: hsla(240 100% 50% / .05);
color: hsl(270 60% 50% / 0.15);
color: hsla(240 100% 50% / 0.05);
color: hsla(240 100% 50% / 5%);
}
```


20 changes: 20 additions & 0 deletions crates/biome_css_formatter/tests/specs/css/number.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
hr {
opacity: .25;
}

h3 {
font-size: calc(1.3rem + .6vw);
}
h4 {
font-size: calc(1.275rem + .3vw);
}
sup {
top: -.5em;
}
.row {
--bs-gutter-x: 1.5rem;
--bs-gutter-y: 0;
margin-top: calc(var(--bs-gutter-y) * -1);
margin-right: calc(var(--bs-gutter-x) * -.5);
margin-left: calc(var(--bs-gutter-x) * -.5);
}
67 changes: 67 additions & 0 deletions crates/biome_css_formatter/tests/specs/css/number.css.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
source: crates/biome_formatter_test/src/snapshot_builder.rs
info: css/number.css
---
# Input

```css
hr {
opacity: .25;
}

h3 {
font-size: calc(1.3rem + .6vw);
}
h4 {
font-size: calc(1.275rem + .3vw);
}
sup {
top: -.5em;
}
.row {
--bs-gutter-x: 1.5rem;
--bs-gutter-y: 0;
margin-top: calc(var(--bs-gutter-y) * -1);
margin-right: calc(var(--bs-gutter-x) * -.5);
margin-left: calc(var(--bs-gutter-x) * -.5);
}

```


=============================

# Outputs

## Output 1

-----
Indent style: Tab
Indent width: 2
Line ending: LF
Line width: 80
Quote style: Double Quotes
-----

```css
hr {
opacity: 0.25;
}

h3 {
font-size: calc(1.3rem + .6vw);
}
h4 {
font-size: calc(1.275rem + .3vw);
}
sup {
top: -.5em;
}
.row {
--bs-gutter-x: 1.5rem;
--bs-gutter-y: 0;
margin-top: calc(var(--bs-gutter-y) * -1);
margin-right: calc(var(--bs-gutter-x) * -0.5);
margin-left: calc(var(--bs-gutter-x) * -0.5);
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
source: crates/biome_formatter_test/src/snapshot_builder.rs
info: css/color/functional-syntax.css
---

# Input

```css
Expand All @@ -28,11 +27,9 @@ info: css/color/functional-syntax.css
color: rgb(100%, 0%, 60%);
color: rgba(51, 170, 51, 0.1);
- color: hsl(0.75turn, 60%, 70%);
- color: hsl(270 60% 50% / 0.15);
- color: hsla(240, 100%, 50%, 0.05);
+ color: hsl(.75turn, 60%, 70%);
+ color: hsl(270 60% 50% / .15);
+ color: hsla(240, 100%, 50%, .05);
color: hsl(270 60% 50% / 0.15);
color: hsla(240, 100%, 50%, 0.05);
}
```

Expand All @@ -44,9 +41,7 @@ info: css/color/functional-syntax.css
color: rgb(100%, 0%, 60%);
color: rgba(51, 170, 51, 0.1);
color: hsl(.75turn, 60%, 70%);
color: hsl(270 60% 50% / .15);
color: hsla(240, 100%, 50%, .05);
color: hsl(270 60% 50% / 0.15);
color: hsla(240, 100%, 50%, 0.05);
}
```


This file was deleted.

Loading

0 comments on commit 296e463

Please sign in to comment.