Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(css_formatter): media and container queries #1294

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
use crate::prelude::*;
use biome_css_syntax::CssContainerAndQuery;
use biome_rowan::AstNode;
use biome_css_syntax::{CssContainerAndQuery, CssContainerAndQueryFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssContainerAndQuery;
impl FormatNodeRule<CssContainerAndQuery> for FormatCssContainerAndQuery {
fn fmt_fields(&self, node: &CssContainerAndQuery, f: &mut CssFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssContainerAndQueryFields {
left,
and_token,
right,
} = node.as_fields();

write!(
f,
[
left.format(),
space(),
and_token.format(),
space(),
right.format()
]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::prelude::*;
use biome_css_syntax::CssContainerNotQuery;
use biome_rowan::AstNode;
use biome_css_syntax::{CssContainerNotQuery, CssContainerNotQueryFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssContainerNotQuery;
impl FormatNodeRule<CssContainerNotQuery> for FormatCssContainerNotQuery {
fn fmt_fields(&self, node: &CssContainerNotQuery, f: &mut CssFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssContainerNotQueryFields { not_token, query } = node.as_fields();

write!(f, [not_token.format(), space(), query.format()])
}
}
22 changes: 19 additions & 3 deletions crates/biome_css_formatter/src/css/auxiliary/container_or_query.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
use crate::prelude::*;
use biome_css_syntax::CssContainerOrQuery;
use biome_rowan::AstNode;
use biome_css_syntax::{CssContainerOrQuery, CssContainerOrQueryFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssContainerOrQuery;
impl FormatNodeRule<CssContainerOrQuery> for FormatCssContainerOrQuery {
fn fmt_fields(&self, node: &CssContainerOrQuery, f: &mut CssFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssContainerOrQueryFields {
left,
or_token,
right,
} = node.as_fields();

write!(
f,
[
left.format(),
space(),
or_token.format(),
space(),
right.format()
]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::*;
use biome_css_syntax::CssContainerQueryInParens;
use biome_rowan::AstNode;
use biome_css_syntax::{CssContainerQueryInParens, CssContainerQueryInParensFields};
use biome_formatter::{format_args, write};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssContainerQueryInParens;
impl FormatNodeRule<CssContainerQueryInParens> for FormatCssContainerQueryInParens {
Expand All @@ -9,6 +10,19 @@ impl FormatNodeRule<CssContainerQueryInParens> for FormatCssContainerQueryInPare
node: &CssContainerQueryInParens,
f: &mut CssFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssContainerQueryInParensFields {
l_paren_token,
query,
r_paren_token,
} = node.as_fields();

write!(
f,
[group(&format_args![
l_paren_token.format(),
soft_block_indent(&query.format()),
r_paren_token.format()
])]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::*;
use biome_css_syntax::CssContainerSizeFeatureInParens;
use biome_rowan::AstNode;
use biome_css_syntax::{CssContainerSizeFeatureInParens, CssContainerSizeFeatureInParensFields};
use biome_formatter::{format_args, write};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssContainerSizeFeatureInParens;
impl FormatNodeRule<CssContainerSizeFeatureInParens> for FormatCssContainerSizeFeatureInParens {
Expand All @@ -9,6 +10,19 @@ impl FormatNodeRule<CssContainerSizeFeatureInParens> for FormatCssContainerSizeF
node: &CssContainerSizeFeatureInParens,
f: &mut CssFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssContainerSizeFeatureInParensFields {
l_paren_token,
feature,
r_paren_token,
} = node.as_fields();

write!(
f,
[group(&format_args![
l_paren_token.format(),
soft_block_indent(&feature.format()),
r_paren_token.format()
])]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::*;
use biome_css_syntax::CssContainerStyleAndQuery;
use biome_rowan::AstNode;
use biome_css_syntax::{CssContainerStyleAndQuery, CssContainerStyleAndQueryFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssContainerStyleAndQuery;
impl FormatNodeRule<CssContainerStyleAndQuery> for FormatCssContainerStyleAndQuery {
Expand All @@ -9,6 +10,21 @@ impl FormatNodeRule<CssContainerStyleAndQuery> for FormatCssContainerStyleAndQue
node: &CssContainerStyleAndQuery,
f: &mut CssFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssContainerStyleAndQueryFields {
left,
and_token,
right,
} = node.as_fields();

write!(
f,
[
left.format(),
space(),
and_token.format(),
space(),
right.format()
]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::*;
use biome_css_syntax::CssContainerStyleInParens;
use biome_rowan::AstNode;
use biome_css_syntax::{CssContainerStyleInParens, CssContainerStyleInParensFields};
use biome_formatter::{format_args, write};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssContainerStyleInParens;
impl FormatNodeRule<CssContainerStyleInParens> for FormatCssContainerStyleInParens {
Expand All @@ -9,6 +10,19 @@ impl FormatNodeRule<CssContainerStyleInParens> for FormatCssContainerStyleInPare
node: &CssContainerStyleInParens,
f: &mut CssFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssContainerStyleInParensFields {
l_paren_token,
query,
r_paren_token,
} = node.as_fields();

write!(
f,
[group(&format_args![
l_paren_token.format(),
&soft_block_indent(&query.format()),
r_paren_token.format()
])]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;
use biome_css_syntax::CssContainerStyleNotQuery;
use biome_rowan::AstNode;
use biome_css_syntax::{CssContainerStyleNotQuery, CssContainerStyleNotQueryFields};
use biome_formatter::write;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssContainerStyleNotQuery;
impl FormatNodeRule<CssContainerStyleNotQuery> for FormatCssContainerStyleNotQuery {
Expand All @@ -9,6 +9,8 @@ impl FormatNodeRule<CssContainerStyleNotQuery> for FormatCssContainerStyleNotQue
node: &CssContainerStyleNotQuery,
f: &mut CssFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssContainerStyleNotQueryFields { not_token, query } = node.as_fields();

write!(f, [not_token.format(), space(), query.format()])
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::*;
use biome_css_syntax::CssContainerStyleOrQuery;
use biome_rowan::AstNode;
use biome_css_syntax::{CssContainerStyleOrQuery, CssContainerStyleOrQueryFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssContainerStyleOrQuery;
impl FormatNodeRule<CssContainerStyleOrQuery> for FormatCssContainerStyleOrQuery {
Expand All @@ -9,6 +10,21 @@ impl FormatNodeRule<CssContainerStyleOrQuery> for FormatCssContainerStyleOrQuery
node: &CssContainerStyleOrQuery,
f: &mut CssFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssContainerStyleOrQueryFields {
left,
or_token,
right,
} = node.as_fields();

write!(
f,
[
left.format(),
space(),
or_token.format(),
space(),
right.format()
]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::*;
use biome_css_syntax::CssContainerStyleQueryInParens;
use biome_rowan::AstNode;
use biome_css_syntax::{CssContainerStyleQueryInParens, CssContainerStyleQueryInParensFields};
use biome_formatter::{format_args, write};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssContainerStyleQueryInParens;
impl FormatNodeRule<CssContainerStyleQueryInParens> for FormatCssContainerStyleQueryInParens {
Expand All @@ -9,6 +10,24 @@ impl FormatNodeRule<CssContainerStyleQueryInParens> for FormatCssContainerStyleQ
node: &CssContainerStyleQueryInParens,
f: &mut CssFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssContainerStyleQueryInParensFields {
style_token,
l_paren_token,
query,
r_paren_token,
} = node.as_fields();

write!(
f,
[
style_token.format(),
space(),
group(&format_args![
l_paren_token.format(),
soft_block_indent(&query.format()),
r_paren_token.format()
])
]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
use crate::prelude::*;
use biome_css_syntax::CssMediaAndCondition;
use biome_rowan::AstNode;
use biome_css_syntax::{CssMediaAndCondition, CssMediaAndConditionFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssMediaAndCondition;
impl FormatNodeRule<CssMediaAndCondition> for FormatCssMediaAndCondition {
fn fmt_fields(&self, node: &CssMediaAndCondition, f: &mut CssFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssMediaAndConditionFields {
left,
and_token,
right,
} = node.as_fields();

write!(
f,
[
left.format(),
space(),
and_token.format(),
space(),
right.format()
]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
use crate::prelude::*;
use biome_css_syntax::CssMediaAndTypeQuery;
use biome_rowan::AstNode;
use biome_css_syntax::{CssMediaAndTypeQuery, CssMediaAndTypeQueryFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssMediaAndTypeQuery;
impl FormatNodeRule<CssMediaAndTypeQuery> for FormatCssMediaAndTypeQuery {
fn fmt_fields(&self, node: &CssMediaAndTypeQuery, f: &mut CssFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssMediaAndTypeQueryFields {
left,
and_token,
right,
} = node.as_fields();

write!(
f,
[
left.format(),
space(),
and_token.format(),
space(),
right.format()
]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::*;
use biome_css_syntax::CssMediaConditionInParens;
use biome_rowan::AstNode;
use biome_css_syntax::{CssMediaConditionInParens, CssMediaConditionInParensFields};
use biome_formatter::{format_args, write};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssMediaConditionInParens;
impl FormatNodeRule<CssMediaConditionInParens> for FormatCssMediaConditionInParens {
Expand All @@ -9,6 +10,19 @@ impl FormatNodeRule<CssMediaConditionInParens> for FormatCssMediaConditionInPare
node: &CssMediaConditionInParens,
f: &mut CssFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssMediaConditionInParensFields {
l_paren_token,
condition,
r_paren_token,
} = node.as_fields();

write!(
f,
[group(&format_args![
l_paren_token.format(),
soft_block_indent(&condition.format()),
r_paren_token.format()
])]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::prelude::*;
use biome_css_syntax::CssMediaConditionQuery;
use biome_rowan::AstNode;
use biome_css_syntax::{CssMediaConditionQuery, CssMediaConditionQueryFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssMediaConditionQuery;
impl FormatNodeRule<CssMediaConditionQuery> for FormatCssMediaConditionQuery {
fn fmt_fields(&self, node: &CssMediaConditionQuery, f: &mut CssFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssMediaConditionQueryFields { condition } = node.as_fields();

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