From 7fd43a7abbd0146f6e28dc63f3b9121d435a111e Mon Sep 17 00:00:00 2001 From: Bram Hoendervangers Date: Wed, 30 Aug 2023 13:07:31 +0200 Subject: [PATCH 1/2] fix: softbreak when elem has single raw text child node --- formatter/src/formatter/element.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/formatter/src/formatter/element.rs b/formatter/src/formatter/element.rs index 17d066e..b83c83a 100644 --- a/formatter/src/formatter/element.rs +++ b/formatter/src/formatter/element.rs @@ -69,7 +69,7 @@ impl Formatter<'_> { let is_textual = children .first() - .map(|n| matches!(n, Node::Text(_) | Node::Block(_))) + .map(|n| matches!(n, Node::Text(_) | Node::RawText(_) | Node::Block(_))) .unwrap_or_default(); let soft_break = is_textual && attribute_count <= 1; @@ -230,6 +230,12 @@ mod tests { insta::assert_snapshot!(formatted, @r###"
"hello"
"###); } + #[test] + fn child_element_single_textual_unquoted() { + let formatted = format_element_from_string!("
hello
"); + insta::assert_snapshot!(formatted, @r###"
hello
"###); + } + #[test] fn child_element_single_textual_single_attr() { let formatted = format_element! {
"hello"
}; From 5d3eca0af8b485a461e1a52d3183a77e4d913e67 Mon Sep 17 00:00:00 2001 From: Bram Hoendervangers Date: Wed, 30 Aug 2023 13:14:19 +0200 Subject: [PATCH 2/2] update tests --- formatter/src/formatter/element.rs | 10 ++-------- formatter/src/source_file.rs | 10 ++-------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/formatter/src/formatter/element.rs b/formatter/src/formatter/element.rs index b83c83a..51be2b9 100644 --- a/formatter/src/formatter/element.rs +++ b/formatter/src/formatter/element.rs @@ -272,19 +272,13 @@ mod tests { #[test] fn html_unquoted_text() { let formatted = format_element_from_string!(r##"
Unquoted text
"##); - insta::assert_snapshot!(formatted, @r#" -
- Unquoted text -
"#); + insta::assert_snapshot!(formatted, @"
Unquoted text
"); } #[test] fn html_unquoted_text_with_surrounding_spaces() { let formatted = format_element_from_string!(r##"
Unquoted text with spaces
"##); - insta::assert_snapshot!(formatted, @r#" -
- Unquoted text with spaces -
"#); + insta::assert_snapshot!(formatted, @"
Unquoted text with spaces
"); } #[test] diff --git a/formatter/src/source_file.rs b/formatter/src/source_file.rs index f311f4b..92ba5b4 100644 --- a/formatter/src/source_file.rs +++ b/formatter/src/source_file.rs @@ -104,11 +104,7 @@ mod tests { // Valid Rust formatted code #[component] pub(crate) fn Error(cx: Scope, message: Option) -> impl IntoView { - view! { cx, -
- Example -
- } + view! { cx,
Example
} } "###); } @@ -349,9 +345,7 @@ mod tests { fn test2(cx: Scope) -> impl IntoView { let x = view! { cx,
- - Hello - + Hello
}; }