-
-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
48e0ddd
commit 4dac0be
Showing
7 changed files
with
438 additions
and
13 deletions.
There are no files selected for viewing
19 changes: 16 additions & 3 deletions
19
crates/biome_css_formatter/src/css/auxiliary/attribute_matcher.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,23 @@ | ||
use crate::prelude::*; | ||
use biome_css_syntax::CssAttributeMatcher; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssAttributeMatcher, CssAttributeMatcherFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssAttributeMatcher; | ||
impl FormatNodeRule<CssAttributeMatcher> for FormatCssAttributeMatcher { | ||
fn fmt_fields(&self, node: &CssAttributeMatcher, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssAttributeMatcherFields { | ||
operator, | ||
value, | ||
modifier, | ||
} = node.as_fields(); | ||
|
||
write!(f, [operator.format(), value.format()])?; | ||
|
||
if modifier.is_some() { | ||
write!(f, [space(), modifier.format()])?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
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/attribute_name.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::CssAttributeName; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssAttributeName, CssAttributeNameFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssAttributeName; | ||
impl FormatNodeRule<CssAttributeName> for FormatCssAttributeName { | ||
fn fmt_fields(&self, node: &CssAttributeName, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssAttributeNameFields { namespace, name } = node.as_fields(); | ||
|
||
write!(f, [namespace.format(), name.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/selectors/attribute_selector.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::CssAttributeSelector; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssAttributeSelector, CssAttributeSelectorFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssAttributeSelector; | ||
impl FormatNodeRule<CssAttributeSelector> for FormatCssAttributeSelector { | ||
fn fmt_fields(&self, node: &CssAttributeSelector, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssAttributeSelectorFields { | ||
l_brack_token, | ||
name, | ||
matcher, | ||
r_brack_token, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[ | ||
l_brack_token.format(), | ||
name.format(), | ||
matcher.format(), | ||
r_brack_token.format() | ||
] | ||
) | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
crates/biome_css_formatter/tests/specs/css/selectors/attribute_selector.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,114 @@ | ||
[attr] {} | ||
|
||
[ attr ] {} | ||
|
||
|
||
[ svg | a ] {} | ||
|
||
[ foo|att = val] {} | ||
|
||
[ *| att] {} | ||
|
||
[ |att] {} | ||
|
||
input[type="radio" i] {} | ||
img[alt~="person" i][src*="lorem" i] {} | ||
input[type="radio" s] {} | ||
img[alt~="person" s][src*="lorem" s] {} | ||
|
||
|
||
a[id = test] {} | ||
a[id= "test"] {} | ||
a[id = 'test'] {} | ||
a[id= func("foo")] {} | ||
a[class= "(╯°□°)╯︵ ┻━┻" ]{} | ||
|
||
[lang] {} | ||
[ lang] {} | ||
[lang ] {} | ||
[ lang ] {} | ||
[ lang ] {} | ||
[ | ||
lang | ||
] {} | ||
span[lang] {} | ||
span[ lang] {} | ||
span[lang ] {} | ||
span[ lang ] {} | ||
span[ lang ] {} | ||
span[lang='pt'] {} | ||
span[lang ='pt'] {} | ||
span[lang= 'pt'] {} | ||
span[lang = 'pt'] {} | ||
span[lang = 'pt'] {} | ||
span[lang='pt' ] {} | ||
span[lang='pt' ] {} | ||
span[ | ||
lang | ||
= | ||
'pt' | ||
] {} | ||
span[ lang ~= 'en-us' ] {} | ||
span[ lang ~= 'en-us' ] {} | ||
span[ lang |='zh' ] {} | ||
span[ | ||
lang | ||
~= | ||
'en-us' | ||
] {} | ||
a[ href ^= '#' ] {} | ||
a[ href *= 'example' ] {} | ||
a[ | ||
href | ||
*= | ||
'example' | ||
] {} | ||
input[ type = 'radio' i ] {} | ||
input[ type = 'radio' i ] {} | ||
input[ type ~= 'radio' i ] {} | ||
input[ type ~= 'radio' i ] {} | ||
input[ | ||
type | ||
~= | ||
'radio' | ||
i | ||
] {} | ||
img[ alt = 'person' ][ src = 'lorem' ] {} | ||
img[ alt = 'person' ][ src = 'lorem' ] {} | ||
img[ alt ~= 'person' ][ src *= 'lorem' ] {} | ||
img[ alt ~= 'person' ][ src *= 'lorem' ] {} | ||
img[ | ||
alt | ||
~= | ||
'person' | ||
][ | ||
src | ||
*= | ||
'lorem' | ||
] {} | ||
|
||
[foo|att=val] {} | ||
[ foo | att = val ] {} | ||
[ foo | att = val ] {} | ||
[ | ||
foo | ||
| | ||
att | ||
= | ||
val | ||
] {} | ||
[*|att] {} | ||
[ * | att ] {} | ||
[ * | att ] {} | ||
[ | ||
* | ||
| | ||
att | ||
] {} | ||
[|att] {} | ||
[ | att ] {} | ||
[ | att ] {} | ||
[ | ||
| | ||
att | ||
] {} |
Oops, something went wrong.