-
-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(css_formatter): fix CSS formatter converts custom identifiers to …
…lowecase (#3254)
- Loading branch information
1 parent
cc65fe8
commit c502f6a
Showing
25 changed files
with
116 additions
and
559 deletions.
There are no files selected for viewing
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
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,18 +1,10 @@ | ||
use crate::css::value::identifier::FormatCssIdentifierOptions; | ||
use crate::prelude::*; | ||
use crate::separated::FormatAstSeparatedListWithOptionsExtension; | ||
use biome_css_syntax::CssLayerNameList; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssLayerNameList; | ||
impl FormatRule<CssLayerNameList> for FormatCssLayerNameList { | ||
type Context = CssFormatContext; | ||
fn fmt(&self, node: &CssLayerNameList, f: &mut CssFormatter) -> FormatResult<()> { | ||
f.join() | ||
.entries(node.format_separated_with_options( | ||
".", | ||
FormatCssIdentifierOptions::default().prevent_lowercase(true), | ||
)) | ||
.finish() | ||
f.join().entries(node.format_separated(".")).finish() | ||
} | ||
} |
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,51 +1,14 @@ | ||
use crate::{prelude::*, utils::string_utils::FormatTokenAsLowercase}; | ||
use crate::prelude::*; | ||
use biome_css_syntax::{CssIdentifier, CssIdentifierFields}; | ||
use biome_formatter::{write, FormatRuleWithOptions}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Default, Debug, Clone, Copy)] | ||
pub(crate) struct FormatCssIdentifier { | ||
prevent_lowercase: bool, | ||
} | ||
|
||
#[derive(Default, Debug, Clone, Copy)] | ||
pub(crate) struct FormatCssIdentifierOptions { | ||
pub(crate) prevent_lowercase: bool, | ||
} | ||
|
||
impl FormatCssIdentifierOptions { | ||
pub(crate) fn prevent_lowercase(mut self, prevent_lowercase: bool) -> Self { | ||
self.prevent_lowercase = prevent_lowercase; | ||
self | ||
} | ||
} | ||
|
||
impl FormatRuleWithOptions<CssIdentifier> for FormatCssIdentifier { | ||
type Options = FormatCssIdentifierOptions; | ||
|
||
fn with_options(mut self, options: Self::Options) -> Self { | ||
self.prevent_lowercase = options.prevent_lowercase; | ||
self | ||
} | ||
} | ||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssIdentifier; | ||
|
||
impl FormatNodeRule<CssIdentifier> for FormatCssIdentifier { | ||
fn fmt_fields(&self, node: &CssIdentifier, f: &mut CssFormatter) -> FormatResult<()> { | ||
let CssIdentifierFields { value_token } = node.as_fields(); | ||
|
||
if self.prevent_lowercase { | ||
return write!(f, [value_token.format()]); | ||
} | ||
|
||
// Identifiers in CSS are used all over the place. Type selectors, | ||
// declaration names, value definitions, and plenty more. For the most | ||
// part, these identifiers are case-insensitive, meaning they can | ||
// safely be re-written in any casing, and for formatting we want them | ||
// to always be in lowercase. | ||
// | ||
// Other kinds of identifiers (custom identifiers and dashed | ||
// identifiers) are defined to be case-sensitive, which is why they | ||
// have their own types to be parsed and formatted separately, ensuring | ||
// that only identifiers which _can_ be re-written this way are. | ||
write!(f, [FormatTokenAsLowercase::from(value_token?)]) | ||
write!(f, [value_token.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
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
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
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
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
Oops, something went wrong.