-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(format/css): implement formatters for new tailwind nodes #7241
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d94c1ea
feat(format/css): implement formatters for tailwind syntax
dyc3 eb2863f
chore: add changeset for the new option
dyc3 906dace
fix: compile errors
dyc3 bd3215f
chore: fix css formatter quick_test
dyc3 4d5d0de
test: enable the parser option for css formattter tests
dyc3 f1355fd
test: add test cases
dyc3 56de633
fix: formatter for `@apply` class list
dyc3 027cd91
feat: add tailwind to `try_from_language_id`
dyc3 307ea78
chore: fix clippy
dyc3 2dad4e8
fix(cli): fix `tailwindDirectives` css parser option not getting pass…
dyc3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
20 changes: 17 additions & 3 deletions
20
crates/biome_css_formatter/src/tailwind/auxiliary/functional_utility_name.rs
This file contains hidden or 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::TwFunctionalUtilityName; | ||
| use biome_rowan::AstNode; | ||
| use biome_css_syntax::{TwFunctionalUtilityName, TwFunctionalUtilityNameFields}; | ||
| use biome_formatter::write; | ||
|
|
||
| #[derive(Debug, Clone, Default)] | ||
| pub(crate) struct FormatTwFunctionalUtilityName; | ||
| impl FormatNodeRule<TwFunctionalUtilityName> for FormatTwFunctionalUtilityName { | ||
| fn fmt_fields(&self, node: &TwFunctionalUtilityName, f: &mut CssFormatter) -> FormatResult<()> { | ||
| format_css_verbatim_node(node.syntax()).fmt(f) | ||
| let TwFunctionalUtilityNameFields { | ||
| identifier, | ||
| minus_token, | ||
| star_token, | ||
| } = node.as_fields(); | ||
|
|
||
| write!( | ||
| f, | ||
| [ | ||
| identifier.format(), | ||
| minus_token.format(), | ||
| star_token.format() | ||
| ] | ||
| ) | ||
| } | ||
| } |
19 changes: 16 additions & 3 deletions
19
crates/biome_css_formatter/src/tailwind/auxiliary/value_theme_reference.rs
This file contains hidden or 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::TwValueThemeReference; | ||
| use biome_rowan::AstNode; | ||
| use biome_css_syntax::{TwValueThemeReference, TwValueThemeReferenceFields}; | ||
| use biome_formatter::write; | ||
| #[derive(Debug, Clone, Default)] | ||
| pub(crate) struct FormatTwValueThemeReference; | ||
| impl FormatNodeRule<TwValueThemeReference> for FormatTwValueThemeReference { | ||
| fn fmt_fields(&self, node: &TwValueThemeReference, f: &mut CssFormatter) -> FormatResult<()> { | ||
| format_css_verbatim_node(node.syntax()).fmt(f) | ||
| let TwValueThemeReferenceFields { | ||
| reference, | ||
| minus_token, | ||
| star_token, | ||
| } = node.as_fields(); | ||
|
|
||
| write!( | ||
| f, | ||
| [ | ||
| reference.format(), | ||
| minus_token.format(), | ||
| star_token.format() | ||
| ] | ||
| ) | ||
| } | ||
| } |
This file contains hidden or 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
21 changes: 18 additions & 3 deletions
21
crates/biome_css_formatter/src/tailwind/statements/apply_at_rule.rs
This file contains hidden or 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,25 @@ | ||
| use crate::prelude::*; | ||
| use biome_css_syntax::TwApplyAtRule; | ||
| use biome_rowan::AstNode; | ||
| use biome_css_syntax::{TwApplyAtRule, TwApplyAtRuleFields}; | ||
| use biome_formatter::write; | ||
|
|
||
| #[derive(Debug, Clone, Default)] | ||
| pub(crate) struct FormatTwApplyAtRule; | ||
| impl FormatNodeRule<TwApplyAtRule> for FormatTwApplyAtRule { | ||
| fn fmt_fields(&self, node: &TwApplyAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
| format_css_verbatim_node(node.syntax()).fmt(f) | ||
| let TwApplyAtRuleFields { | ||
| apply_token, | ||
| classes, | ||
| semicolon_token, | ||
| } = node.as_fields(); | ||
|
|
||
| write!( | ||
| f, | ||
| [ | ||
| apply_token.format(), | ||
| space(), | ||
| classes.format(), | ||
| semicolon_token.format() | ||
| ] | ||
| ) | ||
| } | ||
| } |
21 changes: 18 additions & 3 deletions
21
crates/biome_css_formatter/src/tailwind/statements/config_at_rule.rs
This file contains hidden or 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,25 @@ | ||
| use crate::prelude::*; | ||
| use biome_css_syntax::TwConfigAtRule; | ||
| use biome_rowan::AstNode; | ||
| use biome_css_syntax::{TwConfigAtRule, TwConfigAtRuleFields}; | ||
| use biome_formatter::write; | ||
|
|
||
| #[derive(Debug, Clone, Default)] | ||
| pub(crate) struct FormatTwConfigAtRule; | ||
| impl FormatNodeRule<TwConfigAtRule> for FormatTwConfigAtRule { | ||
| fn fmt_fields(&self, node: &TwConfigAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
| format_css_verbatim_node(node.syntax()).fmt(f) | ||
| let TwConfigAtRuleFields { | ||
| config_token, | ||
| path, | ||
| semicolon_token, | ||
| } = node.as_fields(); | ||
|
|
||
| write!( | ||
| f, | ||
| [ | ||
| config_token.format(), | ||
| space(), | ||
| path.format(), | ||
| semicolon_token.format() | ||
| ] | ||
| ) | ||
| } | ||
| } |
22 changes: 19 additions & 3 deletions
22
crates/biome_css_formatter/src/tailwind/statements/custom_variant_at_rule.rs
This file contains hidden or 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::TwCustomVariantAtRule; | ||
| use biome_rowan::AstNode; | ||
| use biome_css_syntax::{TwCustomVariantAtRule, TwCustomVariantAtRuleFields}; | ||
| use biome_formatter::write; | ||
|
|
||
| #[derive(Debug, Clone, Default)] | ||
| pub(crate) struct FormatTwCustomVariantAtRule; | ||
| impl FormatNodeRule<TwCustomVariantAtRule> for FormatTwCustomVariantAtRule { | ||
| fn fmt_fields(&self, node: &TwCustomVariantAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
| format_css_verbatim_node(node.syntax()).fmt(f) | ||
| let TwCustomVariantAtRuleFields { | ||
| custom_variant_token, | ||
| name, | ||
| selector, | ||
| } = node.as_fields(); | ||
|
|
||
| write!( | ||
| f, | ||
| [ | ||
| custom_variant_token.format(), | ||
| space(), | ||
| name.format(), | ||
| space(), | ||
| selector.format() | ||
| ] | ||
| ) | ||
| } | ||
| } |
21 changes: 18 additions & 3 deletions
21
crates/biome_css_formatter/src/tailwind/statements/plugin_at_rule.rs
This file contains hidden or 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,25 @@ | ||
| use crate::prelude::*; | ||
| use biome_css_syntax::TwPluginAtRule; | ||
| use biome_rowan::AstNode; | ||
| use biome_css_syntax::{TwPluginAtRule, TwPluginAtRuleFields}; | ||
| use biome_formatter::write; | ||
|
|
||
| #[derive(Debug, Clone, Default)] | ||
| pub(crate) struct FormatTwPluginAtRule; | ||
| impl FormatNodeRule<TwPluginAtRule> for FormatTwPluginAtRule { | ||
| fn fmt_fields(&self, node: &TwPluginAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
| format_css_verbatim_node(node.syntax()).fmt(f) | ||
| let TwPluginAtRuleFields { | ||
| plugin_token, | ||
| name, | ||
| semicolon_token, | ||
| } = node.as_fields(); | ||
|
|
||
| write!( | ||
| f, | ||
| [ | ||
| plugin_token.format(), | ||
| space(), | ||
| name.format(), | ||
| semicolon_token.format() | ||
| ] | ||
| ) | ||
| } | ||
| } |
21 changes: 18 additions & 3 deletions
21
crates/biome_css_formatter/src/tailwind/statements/reference_at_rule.rs
This file contains hidden or 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,25 @@ | ||
| use crate::prelude::*; | ||
| use biome_css_syntax::TwReferenceAtRule; | ||
| use biome_rowan::AstNode; | ||
| use biome_css_syntax::{TwReferenceAtRule, TwReferenceAtRuleFields}; | ||
| use biome_formatter::write; | ||
|
|
||
| #[derive(Debug, Clone, Default)] | ||
| pub(crate) struct FormatTwReferenceAtRule; | ||
| impl FormatNodeRule<TwReferenceAtRule> for FormatTwReferenceAtRule { | ||
| fn fmt_fields(&self, node: &TwReferenceAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
| format_css_verbatim_node(node.syntax()).fmt(f) | ||
| let TwReferenceAtRuleFields { | ||
| reference_token, | ||
| path, | ||
| semicolon_token, | ||
| } = node.as_fields(); | ||
|
|
||
| write!( | ||
| f, | ||
| [ | ||
| reference_token.format(), | ||
| space(), | ||
| path.format(), | ||
| semicolon_token.format() | ||
| ] | ||
| ) | ||
| } | ||
| } |
20 changes: 17 additions & 3 deletions
20
crates/biome_css_formatter/src/tailwind/statements/source_at_rule.rs
This file contains hidden or 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::TwSourceAtRule; | ||
| use biome_rowan::AstNode; | ||
| use biome_css_syntax::{TwSourceAtRule, TwSourceAtRuleFields}; | ||
| use biome_formatter::write; | ||
| #[derive(Debug, Clone, Default)] | ||
| pub(crate) struct FormatTwSourceAtRule; | ||
| impl FormatNodeRule<TwSourceAtRule> for FormatTwSourceAtRule { | ||
| fn fmt_fields(&self, node: &TwSourceAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
| format_css_verbatim_node(node.syntax()).fmt(f) | ||
| let TwSourceAtRuleFields { | ||
| source_token, | ||
| path, | ||
| semicolon_token, | ||
| } = node.as_fields(); | ||
|
|
||
| write!( | ||
| f, | ||
| [ | ||
| source_token.format(), | ||
| space(), | ||
| path.format(), | ||
| semicolon_token.format() | ||
| ] | ||
| ) | ||
| } | ||
| } |
17 changes: 14 additions & 3 deletions
17
crates/biome_css_formatter/src/tailwind/statements/theme_at_rule.rs
This file contains hidden or 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,21 @@ | ||
| use crate::prelude::*; | ||
| use biome_css_syntax::TwThemeAtRule; | ||
| use biome_rowan::AstNode; | ||
| use biome_css_syntax::{TwThemeAtRule, TwThemeAtRuleFields}; | ||
| use biome_formatter::write; | ||
|
|
||
| #[derive(Debug, Clone, Default)] | ||
| pub(crate) struct FormatTwThemeAtRule; | ||
| impl FormatNodeRule<TwThemeAtRule> for FormatTwThemeAtRule { | ||
| fn fmt_fields(&self, node: &TwThemeAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
| format_css_verbatim_node(node.syntax()).fmt(f) | ||
| let TwThemeAtRuleFields { | ||
| theme_token, | ||
| name, | ||
| block, | ||
| } = node.as_fields(); | ||
|
|
||
| write!(f, [theme_token.format()])?; | ||
| if let Some(name) = name { | ||
| write!(f, [space(), name.format()])?; | ||
| } | ||
| write!(f, [space(), block.format()]) | ||
| } | ||
| } |
22 changes: 19 additions & 3 deletions
22
crates/biome_css_formatter/src/tailwind/statements/utility_at_rule.rs
This file contains hidden or 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::TwUtilityAtRule; | ||
| use biome_rowan::AstNode; | ||
| use biome_css_syntax::{TwUtilityAtRule, TwUtilityAtRuleFields}; | ||
| use biome_formatter::write; | ||
|
|
||
| #[derive(Debug, Clone, Default)] | ||
| pub(crate) struct FormatTwUtilityAtRule; | ||
| impl FormatNodeRule<TwUtilityAtRule> for FormatTwUtilityAtRule { | ||
| fn fmt_fields(&self, node: &TwUtilityAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
| format_css_verbatim_node(node.syntax()).fmt(f) | ||
| let TwUtilityAtRuleFields { | ||
| utility_token, | ||
| name, | ||
| block, | ||
| } = node.as_fields(); | ||
|
|
||
| write!( | ||
| f, | ||
| [ | ||
| utility_token.format(), | ||
| space(), | ||
| name.format(), | ||
| space(), | ||
| block.format() | ||
| ] | ||
| ) | ||
| } | ||
| } |
22 changes: 19 additions & 3 deletions
22
crates/biome_css_formatter/src/tailwind/statements/variant_at_rule.rs
This file contains hidden or 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::TwVariantAtRule; | ||
| use biome_rowan::AstNode; | ||
| use biome_css_syntax::{TwVariantAtRule, TwVariantAtRuleFields}; | ||
| use biome_formatter::write; | ||
|
|
||
| #[derive(Debug, Clone, Default)] | ||
| pub(crate) struct FormatTwVariantAtRule; | ||
| impl FormatNodeRule<TwVariantAtRule> for FormatTwVariantAtRule { | ||
| fn fmt_fields(&self, node: &TwVariantAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
| format_css_verbatim_node(node.syntax()).fmt(f) | ||
| let TwVariantAtRuleFields { | ||
| variant_token, | ||
| name, | ||
| block, | ||
| } = node.as_fields(); | ||
|
|
||
| write!( | ||
| f, | ||
| [ | ||
| variant_token.format(), | ||
| space(), | ||
| name.format(), | ||
| space(), | ||
| block.format() | ||
| ] | ||
| ) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
3 changes: 3 additions & 0 deletions
3
crates/biome_css_formatter/tests/specs/css/tailwind/long-apply.css
This file contains hidden or 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,3 @@ | ||
| .foo { | ||
| @apply text-blue-500 hover:text-blue-600 accent-red accent-blue accent-green text-sm text-md hover:underline md:grid; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.