-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(css_formatter): format scope and layer at-rules (#1346)
- Loading branch information
1 parent
c7a035a
commit 4a66375
Showing
15 changed files
with
598 additions
and
39 deletions.
There are no files selected for viewing
16 changes: 13 additions & 3 deletions
16
crates/biome_css_formatter/src/css/auxiliary/layer_declaration.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
use crate::prelude::*; | ||
use biome_css_syntax::CssLayerDeclaration; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssLayerDeclaration, CssLayerDeclarationFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssLayerDeclaration; | ||
impl FormatNodeRule<CssLayerDeclaration> for FormatCssLayerDeclaration { | ||
fn fmt_fields(&self, node: &CssLayerDeclaration, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssLayerDeclarationFields { references, block } = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[ | ||
group(&indent(&references.format())), | ||
space(), | ||
block.format() | ||
] | ||
) | ||
} | ||
} |
18 changes: 15 additions & 3 deletions
18
crates/biome_css_formatter/src/css/auxiliary/layer_reference.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
use crate::prelude::*; | ||
use biome_css_syntax::CssLayerReference; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssLayerReference, CssLayerReferenceFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssLayerReference; | ||
impl FormatNodeRule<CssLayerReference> for FormatCssLayerReference { | ||
fn fmt_fields(&self, node: &CssLayerReference, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssLayerReferenceFields { | ||
references, | ||
semicolon_token, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[ | ||
group(&indent(&references.format())), | ||
semicolon_token.format() | ||
] | ||
) | ||
} | ||
} |
20 changes: 17 additions & 3 deletions
20
crates/biome_css_formatter/src/css/auxiliary/scope_edge.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
use crate::prelude::*; | ||
use biome_css_syntax::CssScopeEdge; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssScopeEdge, CssScopeEdgeFields}; | ||
use biome_formatter::{format_args, write}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssScopeEdge; | ||
impl FormatNodeRule<CssScopeEdge> for FormatCssScopeEdge { | ||
fn fmt_fields(&self, node: &CssScopeEdge, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssScopeEdgeFields { | ||
l_paren_token, | ||
selectors, | ||
r_paren_token, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[group(&format_args![ | ||
l_paren_token.format(), | ||
soft_block_indent(&selectors.format()), | ||
r_paren_token.format() | ||
])] | ||
) | ||
} | ||
} |
9 changes: 6 additions & 3 deletions
9
crates/biome_css_formatter/src/css/auxiliary/scope_range_end.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
use crate::prelude::*; | ||
use biome_css_syntax::CssScopeRangeEnd; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssScopeRangeEnd, CssScopeRangeEndFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssScopeRangeEnd; | ||
impl FormatNodeRule<CssScopeRangeEnd> for FormatCssScopeRangeEnd { | ||
fn fmt_fields(&self, node: &CssScopeRangeEnd, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssScopeRangeEndFields { to_token, end } = node.as_fields(); | ||
|
||
write!(f, [to_token.format(), space(), end.format()]) | ||
} | ||
} |
22 changes: 19 additions & 3 deletions
22
crates/biome_css_formatter/src/css/auxiliary/scope_range_interval.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
use crate::prelude::*; | ||
use biome_css_syntax::CssScopeRangeInterval; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssScopeRangeInterval, CssScopeRangeIntervalFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssScopeRangeInterval; | ||
impl FormatNodeRule<CssScopeRangeInterval> for FormatCssScopeRangeInterval { | ||
fn fmt_fields(&self, node: &CssScopeRangeInterval, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssScopeRangeIntervalFields { | ||
start, | ||
to_token, | ||
end, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[ | ||
start.format(), | ||
space(), | ||
to_token.format(), | ||
space(), | ||
end.format() | ||
] | ||
) | ||
} | ||
} |
9 changes: 6 additions & 3 deletions
9
crates/biome_css_formatter/src/css/auxiliary/scope_range_start.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
use crate::prelude::*; | ||
use biome_css_syntax::CssScopeRangeStart; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssScopeRangeStart, CssScopeRangeStartFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssScopeRangeStart; | ||
impl FormatNodeRule<CssScopeRangeStart> for FormatCssScopeRangeStart { | ||
fn fmt_fields(&self, node: &CssScopeRangeStart, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssScopeRangeStartFields { start } = node.as_fields(); | ||
|
||
write!(f, [start.format()]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
crates/biome_css_formatter/src/css/statements/layer_at_rule.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
use crate::prelude::*; | ||
use biome_css_syntax::CssLayerAtRule; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssLayerAtRule, CssLayerAtRuleFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssLayerAtRule; | ||
impl FormatNodeRule<CssLayerAtRule> for FormatCssLayerAtRule { | ||
fn fmt_fields(&self, node: &CssLayerAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssLayerAtRuleFields { layer_token, layer } = node.as_fields(); | ||
|
||
write!(f, [layer_token.format(), space(), layer.format()]) | ||
} | ||
} |
22 changes: 19 additions & 3 deletions
22
crates/biome_css_formatter/src/css/statements/scope_at_rule.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
use crate::prelude::*; | ||
use biome_css_syntax::CssScopeAtRule; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssScopeAtRule, CssScopeAtRuleFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssScopeAtRule; | ||
impl FormatNodeRule<CssScopeAtRule> for FormatCssScopeAtRule { | ||
fn fmt_fields(&self, node: &CssScopeAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssScopeAtRuleFields { | ||
scope_token, | ||
range, | ||
block, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[ | ||
scope_token.format(), | ||
space(), | ||
range.format(), | ||
space(), | ||
block.format() | ||
] | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
crates/biome_css_formatter/tests/specs/css/atrule/layer.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
@layer framework, override , foo , bar.baz ; | ||
@layer bar.baz ; | ||
|
||
@layer override{ | ||
@keyframes slide-left { | ||
from { translate: 0; } | ||
to { translate: -100% 0; } | ||
} | ||
} | ||
|
||
@layer | ||
framework | ||
{ | ||
@keyframes slide-left { | ||
from { margin-left: 0; } | ||
to { margin-left: -100%; } | ||
} | ||
} | ||
|
||
@layer {} | ||
@layer { | ||
} | ||
|
||
@layer | ||
|
||
reset.type | ||
|
||
{ | ||
strong { font-weight: bold; } | ||
} | ||
|
||
@layer framework { | ||
.title { font-weight: 100; } | ||
|
||
@layer | ||
theme { | ||
h1, h2 { color: maroon; } | ||
} | ||
} | ||
|
||
@layer reset { | ||
[hidden] { display: none; } | ||
} | ||
|
||
@layer framework { | ||
@layer default { p { margin-block: 0.75em; } } | ||
@layer theme { p { color: red; } } | ||
} | ||
|
||
@layer framework.theme { | ||
/* These styles will be added to the theme layer inside the framework layer */ | ||
blockquote { color: rebeccapurple; } | ||
} | ||
|
||
@layer framework | ||
|
||
{ | ||
@media ONLY screen AND (color) { | ||
article { | ||
padding: 1rem 3rem; | ||
} | ||
} | ||
.title { font-weight: 100; } | ||
|
||
@layer theme { | ||
h1, h2 { color: maroon; } | ||
} | ||
} |
Oops, something went wrong.