Skip to content

Commit

Permalink
feat(css_parser): implement css unknown at rule parsing (#3136)
Browse files Browse the repository at this point in the history
  • Loading branch information
denbezrukov authored Jun 9, 2024
1 parent 2a4d372 commit 32027ee
Show file tree
Hide file tree
Showing 49 changed files with 2,540 additions and 36,180 deletions.
15 changes: 11 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
#### Bug fixes

- Fix [#3069](https://github.com/biomejs/biome/issues/3069), prevent overwriting paths when using `--staged` or `--changed` options. Contributed by @unvalley
- Fix the bug where whitespace after the & character in CSS nesting was incorrectly trimmed, ensuring proper targeting of child classes [#3061](https://github.com/biomejs/biome/issues/3061). Contributed by @denbezrukov
- Fix [#3091](https://github.com/biomejs/biome/issues/3091). Allows the parser to handle nested style rules and at-rules properly, enhancing the parser's compatibility with the CSS Nesting Module. Contributed by @denbezrukov
- Fix [#3068](https://github.com/biomejs/biome/issues/3068) where the CSS formatter was inadvertently converting variable declarations and function calls to lowercase. Contributed by @denbezrukov
- Fix [#3055](https://github.com/biomejs/biome/issues/3055) CSS: Layout using named grid lines is now correctly parsed. Contributed by @denbezrukov

### Configuration

Expand All @@ -33,6 +29,10 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

### Formatter

#### Bug fixes
- Fix the bug where whitespace after the & character in CSS nesting was incorrectly trimmed, ensuring proper targeting of child classes [#3061](https://github.com/biomejs/biome/issues/3061). Contributed by @denbezrukov
- Fix [#3068](https://github.com/biomejs/biome/issues/3068) where the CSS formatter was inadvertently converting variable declarations and function calls to lowercase. Contributed by @denbezrukov

### JavaScript APIs

### Linter
Expand Down Expand Up @@ -61,6 +61,13 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

### Parser

#### New features
- Implemented CSS Unknown At-Rule parsing, allowing the parser to gracefully handle unsupported or unrecognized CSS at-rules. Contributed by @denbezrukov

#### Bug fixes
- Fix [#3055](https://github.com/biomejs/biome/issues/3055) CSS: Layout using named grid lines is now correctly parsed. Contributed by @denbezrukov
- Fix [#3091](https://github.com/biomejs/biome/issues/3091). Allows the parser to handle nested style rules and at-rules properly, enhancing the parser's compatibility with the CSS Nesting Module. Contributed by @denbezrukov

## 1.8.0 (2024-06-04)

### Analyzer
Expand Down
38 changes: 38 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.

67 changes: 67 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.

2 changes: 2 additions & 0 deletions crates/biome_css_formatter/src/css/any/at_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ impl FormatRule<AnyCssAtRule> for FormatAnyCssAtRule {
AnyCssAtRule::CssScopeAtRule(node) => node.format().fmt(f),
AnyCssAtRule::CssStartingStyleAtRule(node) => node.format().fmt(f),
AnyCssAtRule::CssSupportsAtRule(node) => node.format().fmt(f),
AnyCssAtRule::CssUnknownBlockAtRule(node) => node.format().fmt(f),
AnyCssAtRule::CssUnknownValueAtRule(node) => node.format().fmt(f),
AnyCssAtRule::CssValueAtRule(node) => node.format().fmt(f),
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/biome_css_formatter/src/css/any/conditional_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ impl FormatRule<AnyCssConditionalBlock> for FormatAnyCssConditionalBlock {
type Context = CssFormatContext;
fn fmt(&self, node: &AnyCssConditionalBlock, f: &mut CssFormatter) -> FormatResult<()> {
match node {
AnyCssConditionalBlock::AnyCssDeclarationOrRuleBlock(node) => node.format().fmt(f),
AnyCssConditionalBlock::AnyCssRuleBlock(node) => node.format().fmt(f),
AnyCssConditionalBlock::CssBogusBlock(node) => node.format().fmt(f),
AnyCssConditionalBlock::CssDeclarationOrRuleBlock(node) => node.format().fmt(f),
AnyCssConditionalBlock::CssRuleBlock(node) => node.format().fmt(f),
}
}
}
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 @@ -24,4 +24,5 @@ pub(crate) mod bogus_scope_range;
pub(crate) mod bogus_selector;
pub(crate) mod bogus_sub_selector;
pub(crate) mod bogus_url_modifier;
pub(crate) mod unknown_at_rule_component_list;
pub(crate) mod value_at_rule_generic_value;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::FormatBogusNodeRule;
use biome_css_syntax::CssUnknownAtRuleComponentList;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssUnknownAtRuleComponentList;
impl FormatBogusNodeRule<CssUnknownAtRuleComponentList> for FormatCssUnknownAtRuleComponentList {}
2 changes: 2 additions & 0 deletions crates/biome_css_formatter/src/css/statements/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ pub(crate) mod property_at_rule;
pub(crate) mod scope_at_rule;
pub(crate) mod starting_style_at_rule;
pub(crate) mod supports_at_rule;
pub(crate) mod unknown_block_at_rule;
pub(crate) mod unknown_value_at_rule;
pub(crate) mod value_at_rule;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::prelude::*;
use biome_css_syntax::{CssUnknownBlockAtRule, CssUnknownBlockAtRuleFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssUnknownBlockAtRule;
impl FormatNodeRule<CssUnknownBlockAtRule> for FormatCssUnknownBlockAtRule {
fn fmt_fields(&self, node: &CssUnknownBlockAtRule, f: &mut CssFormatter) -> FormatResult<()> {
let CssUnknownBlockAtRuleFields {
name,
components,
block,
} = node.as_fields();

write!(f, [name.format(), space(), components.format()])?;

if components.map_or(false, |components| components.items().next().is_some()) {
write!(f, [space()])?;
}

write!(f, [block.format()])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crate::prelude::*;
use biome_css_syntax::{CssUnknownValueAtRule, CssUnknownValueAtRuleFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssUnknownValueAtRule;
impl FormatNodeRule<CssUnknownValueAtRule> for FormatCssUnknownValueAtRule {
fn fmt_fields(&self, node: &CssUnknownValueAtRule, f: &mut CssFormatter) -> FormatResult<()> {
let CssUnknownValueAtRuleFields {
name,
components,
semicolon_token,
} = node.as_fields();

write!(f, [name.format()])?;

if let Ok(components) = components {
if components.items().next().is_some() {
write!(f, [space()])?;
}
write!(f, [components.format()])?;
}

write!(f, [semicolon_token.format()])
}
}
Loading

0 comments on commit 32027ee

Please sign in to comment.