-
-
Notifications
You must be signed in to change notification settings - Fork 487
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): formatting support for supports at-rules (#1348)
- Loading branch information
1 parent
3e8f11c
commit dc7685b
Showing
11 changed files
with
863 additions
and
21 deletions.
There are no files selected for viewing
22 changes: 19 additions & 3 deletions
22
crates/biome_css_formatter/src/css/auxiliary/supports_and_condition.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::CssSupportsAndCondition; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssSupportsAndCondition, CssSupportsAndConditionFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssSupportsAndCondition; | ||
impl FormatNodeRule<CssSupportsAndCondition> for FormatCssSupportsAndCondition { | ||
fn fmt_fields(&self, node: &CssSupportsAndCondition, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssSupportsAndConditionFields { | ||
left, | ||
and_token, | ||
right, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[ | ||
left.format(), | ||
space(), | ||
and_token.format(), | ||
soft_line_break_or_space(), | ||
right.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/auxiliary/supports_not_condition.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::CssSupportsNotCondition; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssSupportsNotCondition, CssSupportsNotConditionFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssSupportsNotCondition; | ||
impl FormatNodeRule<CssSupportsNotCondition> for FormatCssSupportsNotCondition { | ||
fn fmt_fields(&self, node: &CssSupportsNotCondition, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssSupportsNotConditionFields { not_token, query } = node.as_fields(); | ||
|
||
write!(f, [not_token.format(), space(), query.format()]) | ||
} | ||
} |
22 changes: 19 additions & 3 deletions
22
crates/biome_css_formatter/src/css/auxiliary/supports_or_condition.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::CssSupportsOrCondition; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssSupportsOrCondition, CssSupportsOrConditionFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssSupportsOrCondition; | ||
impl FormatNodeRule<CssSupportsOrCondition> for FormatCssSupportsOrCondition { | ||
fn fmt_fields(&self, node: &CssSupportsOrCondition, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssSupportsOrConditionFields { | ||
left, | ||
or_token, | ||
right, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[ | ||
left.format(), | ||
space(), | ||
or_token.format(), | ||
soft_line_break_or_space(), | ||
right.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
22 changes: 19 additions & 3 deletions
22
crates/biome_css_formatter/src/css/statements/supports_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::CssSupportsAtRule; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssSupportsAtRule, CssSupportsAtRuleFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssSupportsAtRule; | ||
impl FormatNodeRule<CssSupportsAtRule> for FormatCssSupportsAtRule { | ||
fn fmt_fields(&self, node: &CssSupportsAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssSupportsAtRuleFields { | ||
supports_token, | ||
condition, | ||
block, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[ | ||
supports_token.format(), | ||
space(), | ||
group(&indent(&condition.format())), | ||
space(), | ||
block.format() | ||
] | ||
) | ||
} | ||
} |
178 changes: 178 additions & 0 deletions
178
crates/biome_css_formatter/tests/specs/css/atrule/supports.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,178 @@ | ||
@supports (display: grid) { | ||
div { | ||
display: grid; | ||
} | ||
} | ||
|
||
@supports (display: flex) { | ||
body { | ||
color: blue; | ||
} | ||
|
||
@media screen and (min-width: 900px) { | ||
article { | ||
display: flex; | ||
} | ||
} | ||
} | ||
@supports ( display : flex ) {} | ||
@supports not (display: flex) {} | ||
@SUPPORTS not (display: flex) {} | ||
@supports (box-shadow: 0 0 2px black inset ) or (-moz-box-shadow: 0 0 2px black inset ) or (-webkit-box-shadow: 0 0 2px black inset ) or (-o-box-shadow: 0 0 2px black inset ) {} | ||
@supports ( box-shadow: 0 0 2px black inset ) | ||
|
||
or | ||
( -moz-box-shadow: 0 0 2px black inset ) or | ||
|
||
( -webkit-box-shadow: 0 0 2px black inset ) or | ||
( | ||
-o-box-shadow: 0 0 2px black inset ) { | ||
|
||
} | ||
@supports ( transition-property : color ) or ( ( animation-name : foo ) and ( transform : rotate(10deg) ) ) {} | ||
@supports(transition-property:color)or ((animation-name:foo)and (transform:rotate(10deg))){} | ||
@supports (( | ||
display: flex)) {} | ||
@supports (display: flex !important) {} | ||
@supports NOT (display: flex) {} | ||
@supports ((transition-property: color) OR (animation-name: foo)) AND (transform: rotate(10deg)) {} | ||
@supports (transition-property: color) OR ((animation-name: foo) AND (transform: rotate(10deg)) | ||
|
||
) {} | ||
@supports (NOT (display: flex)) {} | ||
|
||
@supports selector(col || td) { | ||
col.selected || td { | ||
background: tan; | ||
} | ||
} | ||
|
||
@supports selector( | ||
:focus-visible | ||
) { | ||
a:focus-visible { | ||
background: yellow; | ||
} | ||
} | ||
|
||
@supports ( | ||
--element(".minwidth")) { | ||
|
||
} | ||
|
||
@supports (ident: 1) { | ||
* { background: red; } | ||
} | ||
|
||
@supports ((ident: 1)) { | ||
* { background: red; } | ||
} | ||
|
||
@supports (ident: "str") { | ||
* { background: red; } | ||
} | ||
|
||
@supports ((ident: "str")) { | ||
* { background: red; } | ||
} | ||
|
||
@supports func(10, 20, 40) { | ||
* { background: red; } | ||
} | ||
|
||
@supports (func(10, 20, 40)) { | ||
* { background: red; } | ||
} | ||
|
||
@supports ( func( 10 , 20 , 40 ) ) { | ||
* { background: red; } | ||
} | ||
|
||
@supports (animation-name: test) { | ||
@keyframes anim { | ||
from { | ||
color: black; | ||
} | ||
to { | ||
color: white | ||
} | ||
} | ||
} | ||
|
||
@supports (--foo: green) { | ||
body { | ||
color: var(--varName); | ||
} | ||
} | ||
|
||
@supports not selector(:is(a, b)) { | ||
ul > li, | ||
ol > li { | ||
color: red; | ||
} | ||
} | ||
|
||
@supports selector( | ||
:nth-child( | ||
1n of a | ||
|
||
, | ||
b)) { | ||
:is( | ||
:nth-child(1n of ul, ol) a, | ||
details > summary | ||
) { | ||
color: red | ||
} | ||
} | ||
|
||
@supports (animation-name: test) { | ||
@keyframes anim { | ||
from { | ||
color: black; | ||
} | ||
to { | ||
color: white | ||
} | ||
} | ||
} | ||
|
||
@supports selector(:focus-visible) { | ||
a:focus-visible { | ||
background: yellow; | ||
} | ||
} | ||
|
||
@supports (width: calc(100px)) { | ||
div { | ||
background: red; | ||
} | ||
} | ||
|
||
@supports (func(1)) { | ||
* { background: red; } | ||
} | ||
|
||
@supports ( selector( col || td ) ) { | ||
col.selected || td { | ||
background: tan; | ||
} | ||
} | ||
|
||
@supports ( func("example") ) { | ||
* { background: red; } | ||
} | ||
|
||
@supports ( --var: "test" ) { | ||
* { background: red; } | ||
} | ||
|
||
@supports (--var) { | ||
* { background: red; } | ||
} | ||
|
||
@supports (--element(".minwidth")) { | ||
[--self] { | ||
background: greenyellow; | ||
} | ||
} |
Oops, something went wrong.