Skip to content

Commit

Permalink
feat(css_parser): implement CSS unicode range (#3251)
Browse files Browse the repository at this point in the history
Co-authored-by: ty <[email protected]>
  • Loading branch information
denbezrukov and togami2864 committed Jun 22, 2024
1 parent c502f6a commit 6ad7fbf
Show file tree
Hide file tree
Showing 35 changed files with 3,280 additions and 118 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

## Unreleased

### Parser

#### New features

- Implement [CSS unicode range](https://github.com/biomejs/biome/pull/3251). Contributed by @denbezrukov
-
### Formatter

#### Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,48 +655,3 @@ invalid.css:26:46 lint/nursery/noUnknownUnit ━━━━━━━━━━━
```

```
invalid.css:27:31 lint/nursery/noUnknownUnit ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Unexpected unknown unit: F
25 │ a { background: /* comment */ image-set('img1x.png' 1x, 'img2x.png' 2x) left 20x / 15% 60% repeat-x; }
26 │ a { background-image: image-set('img1x.png' 1pix, 'img2x.png' 2x); }
> 27 │ @font-face { color: U+0100-024F; }
│ ^
28 │ a { unicode-range: U+0100-024F; }
i See MDN web docs for more details.
i Use a known unit instead, such as:
- px
- em
- rem
- etc.
```

```
invalid.css:28:30 lint/nursery/noUnknownUnit ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Unexpected unknown unit: F
26 │ a { background-image: image-set('img1x.png' 1pix, 'img2x.png' 2x); }
27 │ @font-face { color: U+0100-024F; }
> 28 │ a { unicode-range: U+0100-024F; }
│ ^
i See MDN web docs for more details.
i Use a known unit instead, such as:
- px
- em
- rem
- etc.
```
45 changes: 45 additions & 0 deletions crates/biome_css_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 98 additions & 0 deletions crates/biome_css_factory/src/generated/syntax_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/biome_css_formatter/src/css/any/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub(crate) mod supports_and_combinable_condition;
pub(crate) mod supports_condition;
pub(crate) mod supports_in_parens;
pub(crate) mod supports_or_combinable_condition;
pub(crate) mod unicode_value;
pub(crate) mod url_modifier;
pub(crate) mod url_value;
pub(crate) mod value;
Expand Down
17 changes: 17 additions & 0 deletions crates/biome_css_formatter/src/css/any/unicode_value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file.

use crate::prelude::*;
use biome_css_syntax::AnyCssUnicodeValue;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatAnyCssUnicodeValue;
impl FormatRule<AnyCssUnicodeValue> for FormatAnyCssUnicodeValue {
type Context = CssFormatContext;
fn fmt(&self, node: &AnyCssUnicodeValue, f: &mut CssFormatter) -> FormatResult<()> {
match node {
AnyCssUnicodeValue::CssBogusUnicodeRangeValue(node) => node.format().fmt(f),
AnyCssUnicodeValue::CssUnicodeCodepoint(node) => node.format().fmt(f),
AnyCssUnicodeValue::CssUnicodeRangeInterval(node) => node.format().fmt(f),
AnyCssUnicodeValue::CssUnicodeRangeWildcard(node) => node.format().fmt(f),
}
}
}
1 change: 1 addition & 0 deletions crates/biome_css_formatter/src/css/any/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl FormatRule<AnyCssValue> for FormatAnyCssValue {
AnyCssValue::CssNumber(node) => node.format().fmt(f),
AnyCssValue::CssRatio(node) => node.format().fmt(f),
AnyCssValue::CssString(node) => node.format().fmt(f),
AnyCssValue::CssUnicodeRange(node) => node.format().fmt(f),
}
}
}
4 changes: 4 additions & 0 deletions crates/biome_css_formatter/src/css/auxiliary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ pub(crate) mod supports_condition_in_parens;
pub(crate) mod supports_feature_declaration;
pub(crate) mod supports_not_condition;
pub(crate) mod supports_or_condition;
pub(crate) mod unicode_codepoint;
pub(crate) mod unicode_range;
pub(crate) mod unicode_range_interval;
pub(crate) mod unicode_range_wildcard;
pub(crate) mod universal_namespace_prefix;
pub(crate) mod url_function;
pub(crate) mod value_at_rule_declaration_clause;
Expand Down
13 changes: 13 additions & 0 deletions crates/biome_css_formatter/src/css/auxiliary/unicode_codepoint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::prelude::*;
use biome_css_syntax::{CssUnicodeCodepoint, CssUnicodeCodepointFields};
use biome_formatter::write;

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

write!(f, [value_token.format(),])
}
}
16 changes: 16 additions & 0 deletions crates/biome_css_formatter/src/css/auxiliary/unicode_range.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::prelude::*;
use biome_css_syntax::{CssUnicodeRange, CssUnicodeRangeFields};
use biome_formatter::write;

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

write!(f, [prefix_token.format(), value.format()])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::prelude::*;
use biome_css_syntax::{CssUnicodeRangeInterval, CssUnicodeRangeIntervalFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssUnicodeRangeInterval;
impl FormatNodeRule<CssUnicodeRangeInterval> for FormatCssUnicodeRangeInterval {
fn fmt_fields(&self, node: &CssUnicodeRangeInterval, f: &mut CssFormatter) -> FormatResult<()> {
let CssUnicodeRangeIntervalFields {
start,
minus_token,
end,
} = node.as_fields();
write!(f, [start.format(), minus_token.format(), end.format()])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::prelude::*;
use biome_css_syntax::{CssUnicodeRangeWildcard, CssUnicodeRangeWildcardFields};
use biome_formatter::write;

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

write!(f, [value_token.format(),])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::FormatBogusNodeRule;
use biome_css_syntax::CssBogusUnicodeRangeValue;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssBogusUnicodeRangeValue;
impl FormatBogusNodeRule<CssBogusUnicodeRangeValue> for FormatCssBogusUnicodeRangeValue {}
1 change: 1 addition & 0 deletions crates/biome_css_formatter/src/css/bogus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub(crate) mod bogus_rule;
pub(crate) mod bogus_scope_range;
pub(crate) mod bogus_selector;
pub(crate) mod bogus_sub_selector;
pub(crate) mod bogus_unicode_range_value;
pub(crate) mod bogus_url_modifier;
pub(crate) mod unknown_at_rule_component_list;
pub(crate) mod value_at_rule_generic_value;
Loading

0 comments on commit 6ad7fbf

Please sign in to comment.