From 7e259eb5850ac36dbcbbe010527f5cc9608fe6e6 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Sun, 2 Feb 2025 11:45:16 -0500 Subject: [PATCH] feat(format/html): add option for whitespace sensitivity --- crates/biome_html_formatter/src/context.rs | 15 ++++++++++++--- .../src/html/auxiliary/element.rs | 14 ++++++-------- .../tests/specs/html/attributes/break.html.snap | 2 +- .../html/attributes/multiline/break.html.snap | 5 ++--- .../html/attributes/multiline/no-break.html.snap | 5 ++--- .../specs/html/attributes/no-break.html.snap | 2 +- .../specs/html/attributes/self-closing.html.snap | 2 +- .../specs/html/attributes/single-quotes.html.snap | 2 +- .../elements/bracket-same-line/element.html.snap | 4 ++-- .../bracket-same-line/self-closing.html.snap | 4 ++-- .../html/elements/empty-extra-lines.html.snap | 2 +- .../inline/tags-dont-hug-content-2.html.snap | 2 +- .../inline/tags-dont-hug-content.html.snap | 2 +- .../tags-hug-content-longer-w-attr.html.snap | 4 ++-- .../inline/tags-hug-content-w-attr.html.snap | 4 ++-- .../elements/inline/tags-hug-content.html.snap | 2 +- .../html/elements/pre-with-brackets.html.snap | 2 +- .../html/elements/pre-with-braille.html.snap | 2 +- .../tests/specs/html/elements/pre.html.snap | 2 +- .../specs/html/elements/spacing/case0.html.snap | 2 +- .../specs/html/elements/spacing/case1.html.snap | 2 +- .../specs/html/elements/spacing/case2.html.snap | 2 +- .../specs/html/elements/spacing/case3.html.snap | 2 +- .../specs/html/elements/spacing/case4.html.snap | 2 +- .../tests/specs/html/example.html.snap | 2 +- .../tests/specs/html/long-content.html.snap | 2 +- .../tests/specs/html/many-children.html.snap | 2 +- .../tests/specs/html/self-closing.html.snap | 2 +- .../@biomejs/backend-jsonrpc/src/workspace.ts | 2 +- packages/@biomejs/biome/configuration_schema.json | 7 ++++++- 30 files changed, 57 insertions(+), 47 deletions(-) diff --git a/crates/biome_html_formatter/src/context.rs b/crates/biome_html_formatter/src/context.rs index 86f7e7631006..b811e2fbcda7 100644 --- a/crates/biome_html_formatter/src/context.rs +++ b/crates/biome_html_formatter/src/context.rs @@ -245,7 +245,11 @@ impl FormatOptions for HtmlFormatOptions { )] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub enum WhitespaceSensitivity { - /// Leading and trailing whitespace in content is considered significant for inline elements. + /// The formatter considers whitespace significant for elements that have an "inline" display style by default in + /// browser's user agent style sheets. + #[default] + Css, + /// Leading and trailing whitespace in content is considered significant for all elements. /// /// The formatter should leave at least one whitespace character if whitespace is present. /// Otherwise, if there is no whitespace, it should not add any after `>` or before `<`. In other words, if there's no whitespace, the text content should hug the tags. @@ -256,7 +260,6 @@ pub enum WhitespaceSensitivity { /// >content /// ``` - #[default] Strict, /// Whitespace is considered insignificant. The formatter is free to remove or add whitespace as it sees fit. Ignore, @@ -265,6 +268,7 @@ pub enum WhitespaceSensitivity { impl fmt::Display for WhitespaceSensitivity { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { + Self::Css => std::write!(f, "css"), Self::Strict => std::write!(f, "strict"), Self::Ignore => std::write!(f, "ignore"), } @@ -276,14 +280,19 @@ impl FromStr for WhitespaceSensitivity { fn from_str(s: &str) -> Result { match s { + "css" => Ok(Self::Css), "strict" => Ok(Self::Strict), "ignore" => Ok(Self::Ignore), - _ => Err("Value not supported for WhitespaceSensitivity. Supported values are 'strict' and 'ignore'."), + _ => Err("Value not supported for WhitespaceSensitivity. Supported values are 'css', 'strict' and 'ignore'."), } } } impl WhitespaceSensitivity { + pub const fn is_css(&self) -> bool { + matches!(self, Self::Css) + } + pub const fn is_strict(&self) -> bool { matches!(self, Self::Strict) } diff --git a/crates/biome_html_formatter/src/html/auxiliary/element.rs b/crates/biome_html_formatter/src/html/auxiliary/element.rs index 303fd542fe69..6e4100e77c17 100644 --- a/crates/biome_html_formatter/src/html/auxiliary/element.rs +++ b/crates/biome_html_formatter/src/html/auxiliary/element.rs @@ -46,6 +46,8 @@ impl FormatNodeRule for FormatHtmlElement { .as_ref() .is_some_and(|tag_name| tag_name.text().eq_ignore_ascii_case(tag)) }); + let is_whitespace_sensitive = whitespace_sensitivity.is_strict() + || (whitespace_sensitivity.is_css() && is_inline_tag); let content_has_leading_whitespace = children .syntax() @@ -85,14 +87,10 @@ impl FormatNodeRule for FormatHtmlElement { // to borrow, while the child formatters are responsible for actually printing // the tokens. `HtmlElementList` prints them if they are borrowed, otherwise // they are printed by their original formatter. - let should_borrow_opening_r_angle = whitespace_sensitivity.is_strict() - && is_inline_tag - && !children.is_empty() - && !content_has_leading_whitespace; - let should_borrow_closing_tag = whitespace_sensitivity.is_strict() - && is_inline_tag - && !children.is_empty() - && !content_has_trailing_whitespace; + let should_borrow_opening_r_angle = + is_whitespace_sensitive && !children.is_empty() && !content_has_leading_whitespace; + let should_borrow_closing_tag = + is_whitespace_sensitive && !children.is_empty() && !content_has_trailing_whitespace; let borrowed_r_angle = if should_borrow_opening_r_angle { opening_element.r_angle_token().ok() diff --git a/crates/biome_html_formatter/tests/specs/html/attributes/break.html.snap b/crates/biome_html_formatter/tests/specs/html/attributes/break.html.snap index 2d9240e867ba..275cbdf9582c 100644 --- a/crates/biome_html_formatter/tests/specs/html/attributes/break.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/attributes/break.html.snap @@ -23,7 +23,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/attributes/multiline/break.html.snap b/crates/biome_html_formatter/tests/specs/html/attributes/multiline/break.html.snap index 8763542d2abe..f27c79b104ed 100644 --- a/crates/biome_html_formatter/tests/specs/html/attributes/multiline/break.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/attributes/multiline/break.html.snap @@ -1,6 +1,5 @@ --- source: crates/biome_formatter_test/src/snapshot_builder.rs -assertion_line: 211 info: attributes/multiline/break.html --- # Input @@ -24,7 +23,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- @@ -41,7 +40,7 @@ Line ending: LF Line width: 80 Attribute Position: Multiline Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/attributes/multiline/no-break.html.snap b/crates/biome_html_formatter/tests/specs/html/attributes/multiline/no-break.html.snap index a769093c37f8..4d16d9d00493 100644 --- a/crates/biome_html_formatter/tests/specs/html/attributes/multiline/no-break.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/attributes/multiline/no-break.html.snap @@ -1,6 +1,5 @@ --- source: crates/biome_formatter_test/src/snapshot_builder.rs -assertion_line: 211 info: attributes/multiline/no-break.html --- # Input @@ -24,7 +23,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- @@ -41,7 +40,7 @@ Line ending: LF Line width: 80 Attribute Position: Multiline Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/attributes/no-break.html.snap b/crates/biome_html_formatter/tests/specs/html/attributes/no-break.html.snap index 86dfeb88747e..7c8d272cbd9c 100644 --- a/crates/biome_html_formatter/tests/specs/html/attributes/no-break.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/attributes/no-break.html.snap @@ -23,7 +23,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/attributes/self-closing.html.snap b/crates/biome_html_formatter/tests/specs/html/attributes/self-closing.html.snap index 045fb3d54755..ae803eab5545 100644 --- a/crates/biome_html_formatter/tests/specs/html/attributes/self-closing.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/attributes/self-closing.html.snap @@ -23,7 +23,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/attributes/single-quotes.html.snap b/crates/biome_html_formatter/tests/specs/html/attributes/single-quotes.html.snap index 68452ea837ea..b6ad62a0073c 100644 --- a/crates/biome_html_formatter/tests/specs/html/attributes/single-quotes.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/attributes/single-quotes.html.snap @@ -23,7 +23,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/bracket-same-line/element.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/bracket-same-line/element.html.snap index 8d4c06008440..e9346ea33517 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/bracket-same-line/element.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/bracket-same-line/element.html.snap @@ -31,7 +31,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- @@ -54,7 +54,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: true -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/bracket-same-line/self-closing.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/bracket-same-line/self-closing.html.snap index ca85d98363d7..46151a55be75 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/bracket-same-line/self-closing.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/bracket-same-line/self-closing.html.snap @@ -29,7 +29,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- @@ -52,7 +52,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: true -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/empty-extra-lines.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/empty-extra-lines.html.snap index 90ceca6fb59d..b0e4a27db8db 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/empty-extra-lines.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/empty-extra-lines.html.snap @@ -25,7 +25,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-dont-hug-content-2.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-dont-hug-content-2.html.snap index 7608f8ef9138..521e4193caa0 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-dont-hug-content-2.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-dont-hug-content-2.html.snap @@ -25,7 +25,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-dont-hug-content.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-dont-hug-content.html.snap index f869bb33ceff..1ad665f6f53a 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-dont-hug-content.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-dont-hug-content.html.snap @@ -23,7 +23,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-hug-content-longer-w-attr.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-hug-content-longer-w-attr.html.snap index 122290daad0f..efbd61fd8579 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-hug-content-longer-w-attr.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-hug-content-longer-w-attr.html.snap @@ -1,6 +1,6 @@ --- source: crates/biome_formatter_test/src/snapshot_builder.rs -info: elements/inline/tags-hug-content-longer.html +info: elements/inline/tags-hug-content-longer-w-attr.html --- # Input @@ -22,7 +22,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-hug-content-w-attr.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-hug-content-w-attr.html.snap index 8452986ab40a..e7c95fba1feb 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-hug-content-w-attr.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-hug-content-w-attr.html.snap @@ -1,6 +1,6 @@ --- source: crates/biome_formatter_test/src/snapshot_builder.rs -info: elements/inline/tags-hug-content.html +info: elements/inline/tags-hug-content-w-attr.html --- # Input @@ -22,7 +22,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-hug-content.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-hug-content.html.snap index 7da5d286d27e..c5f527b24cef 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-hug-content.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/inline/tags-hug-content.html.snap @@ -23,7 +23,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/pre-with-brackets.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/pre-with-brackets.html.snap index 6b93ad0a9983..a4bb69cb9525 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/pre-with-brackets.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/pre-with-brackets.html.snap @@ -32,7 +32,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/pre-with-braille.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/pre-with-braille.html.snap index 492fa8d86f89..eee95fc56671 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/pre-with-braille.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/pre-with-braille.html.snap @@ -54,7 +54,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/pre.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/pre.html.snap index bfd240c6302b..71111b20126f 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/pre.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/pre.html.snap @@ -35,7 +35,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/spacing/case0.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/spacing/case0.html.snap index 18f0ddbe3347..65897059d574 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/spacing/case0.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/spacing/case0.html.snap @@ -28,7 +28,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/spacing/case1.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/spacing/case1.html.snap index c0b5716b6523..5d35e0f684ab 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/spacing/case1.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/spacing/case1.html.snap @@ -30,7 +30,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/spacing/case2.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/spacing/case2.html.snap index 39808168461f..88c437c6332a 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/spacing/case2.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/spacing/case2.html.snap @@ -28,7 +28,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/spacing/case3.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/spacing/case3.html.snap index 2dc18e2c6fe2..cbc18b08b4c3 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/spacing/case3.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/spacing/case3.html.snap @@ -28,7 +28,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/elements/spacing/case4.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/spacing/case4.html.snap index d2e4eb99dcca..f3ef81b76581 100644 --- a/crates/biome_html_formatter/tests/specs/html/elements/spacing/case4.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/elements/spacing/case4.html.snap @@ -25,7 +25,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/example.html.snap b/crates/biome_html_formatter/tests/specs/html/example.html.snap index 03c7d15b0d9d..d2a98d56936b 100644 --- a/crates/biome_html_formatter/tests/specs/html/example.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/example.html.snap @@ -23,7 +23,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/long-content.html.snap b/crates/biome_html_formatter/tests/specs/html/long-content.html.snap index 8a1d08733990..c3e140aed4e9 100644 --- a/crates/biome_html_formatter/tests/specs/html/long-content.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/long-content.html.snap @@ -23,7 +23,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/many-children.html.snap b/crates/biome_html_formatter/tests/specs/html/many-children.html.snap index 17bc525e90d3..ee5b3afa23dc 100644 --- a/crates/biome_html_formatter/tests/specs/html/many-children.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/many-children.html.snap @@ -26,7 +26,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/crates/biome_html_formatter/tests/specs/html/self-closing.html.snap b/crates/biome_html_formatter/tests/specs/html/self-closing.html.snap index 60c4ae519990..e08e7dfe2711 100644 --- a/crates/biome_html_formatter/tests/specs/html/self-closing.html.snap +++ b/crates/biome_html_formatter/tests/specs/html/self-closing.html.snap @@ -25,7 +25,7 @@ Line ending: LF Line width: 80 Attribute Position: Auto Bracket same line: false -Whitespace sensitivity: strict +Whitespace sensitivity: css Indent script and style: false ----- diff --git a/packages/@biomejs/backend-jsonrpc/src/workspace.ts b/packages/@biomejs/backend-jsonrpc/src/workspace.ts index a2ae255f5fe1..bf02a7b1095c 100644 --- a/packages/@biomejs/backend-jsonrpc/src/workspace.ts +++ b/packages/@biomejs/backend-jsonrpc/src/workspace.ts @@ -856,7 +856,7 @@ As a consequence of this, the formatter must format blocks that look like this ( Note that this is only necessary for inline elements. Block elements do not have this restriction. */ -export type WhitespaceSensitivity = "strict" | "ignore"; +export type WhitespaceSensitivity = "css" | "strict" | "ignore"; export type ArrowParentheses = "always" | "asNeeded"; export type QuoteProperties = "asNeeded" | "preserve"; export type Semicolons = "always" | "asNeeded"; diff --git a/packages/@biomejs/biome/configuration_schema.json b/packages/@biomejs/biome/configuration_schema.json index b24c21fc1658..c3c38210af2f 100644 --- a/packages/@biomejs/biome/configuration_schema.json +++ b/packages/@biomejs/biome/configuration_schema.json @@ -5025,7 +5025,12 @@ "description": "Whitespace sensitivity for HTML formatting.\n\nThe following two cases won't produce the same output:\n\n| | html | output | | -------------- | :------------: | :----------: | | with spaces | `1 2 3` | 1 2 3 | | without spaces | `123` | 123 |\n\nThis happens because whitespace is significant in inline elements.\n\nAs a consequence of this, the formatter must format blocks that look like this (assume a small line width, <20): ```html really long content ``` as this, where the content hugs the tags: ```html really long content ```\n\nNote that this is only necessary for inline elements. Block elements do not have this restriction.", "oneOf": [ { - "description": "Leading and trailing whitespace in content is considered significant for inline elements.\n\nThe formatter should leave at least one whitespace character if whitespace is present. Otherwise, if there is no whitespace, it should not add any after `>` or before `<`. In other words, if there's no whitespace, the text content should hug the tags.\n\nExample of text hugging the tags: ```html content ```", + "description": "The formatter considers whitespace significant for elements that have an \"inline\" display style by default in browser's user agent style sheets.", + "type": "string", + "enum": ["css"] + }, + { + "description": "Leading and trailing whitespace in content is considered significant for all elements.\n\nThe formatter should leave at least one whitespace character if whitespace is present. Otherwise, if there is no whitespace, it should not add any after `>` or before `<`. In other words, if there's no whitespace, the text content should hug the tags.\n\nExample of text hugging the tags: ```html content ```", "type": "string", "enum": ["strict"] },