From 6b57cac2b15922e30c2d4233f6a35e237a313551 Mon Sep 17 00:00:00 2001 From: suzak Date: Mon, 16 Sep 2024 18:14:54 +0900 Subject: [PATCH 1/2] Add failing case --- .../tests/specs/nursery/useConsistentCurlyBraces/invalid.jsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/biome_js_analyze/tests/specs/nursery/useConsistentCurlyBraces/invalid.jsx b/crates/biome_js_analyze/tests/specs/nursery/useConsistentCurlyBraces/invalid.jsx index bf88f6b40c67..a6b69b1baf42 100644 --- a/crates/biome_js_analyze/tests/specs/nursery/useConsistentCurlyBraces/invalid.jsx +++ b/crates/biome_js_analyze/tests/specs/nursery/useConsistentCurlyBraces/invalid.jsx @@ -10,4 +10,6 @@ } {/*comment*/'Hello world'/*comment*/} + +{x}{'y'}{z} From 0cc4472b1a182ca726a4f922e4493508a5249f5d Mon Sep 17 00:00:00 2001 From: suzak Date: Mon, 16 Sep 2024 19:58:03 +0900 Subject: [PATCH 2/2] Preserve other children in useConsistentCurlyBraces --- .../nursery/use_consistent_curly_braces.rs | 3 ++ .../useConsistentCurlyBraces/invalid.jsx.snap | 32 ++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/crates/biome_js_analyze/src/lint/nursery/use_consistent_curly_braces.rs b/crates/biome_js_analyze/src/lint/nursery/use_consistent_curly_braces.rs index 764fdca6a576..2587ca2d4c6f 100644 --- a/crates/biome_js_analyze/src/lint/nursery/use_consistent_curly_braces.rs +++ b/crates/biome_js_analyze/src/lint/nursery/use_consistent_curly_braces.rs @@ -270,6 +270,8 @@ impl Rule for UseConsistentCurlyBraces { let child_list = node.parent::()?; let mut children = vec![]; + let mut iter = (&child_list).into_iter(); + children.extend(iter.by_ref().take_while(|c| c != node)); if let Some(leading_comments_expr) = leading_comments_expr { children.push(leading_comments_expr); } @@ -277,6 +279,7 @@ impl Rule for UseConsistentCurlyBraces { if let Some(trailing_comments_expr) = trailing_comments_expr { children.push(trailing_comments_expr); } + children.extend(iter); let new_child_list = make::jsx_child_list(children); mutation.replace_element_discard_trivia( diff --git a/crates/biome_js_analyze/tests/specs/nursery/useConsistentCurlyBraces/invalid.jsx.snap b/crates/biome_js_analyze/tests/specs/nursery/useConsistentCurlyBraces/invalid.jsx.snap index 4d12af674472..085ebad4b30d 100644 --- a/crates/biome_js_analyze/tests/specs/nursery/useConsistentCurlyBraces/invalid.jsx.snap +++ b/crates/biome_js_analyze/tests/specs/nursery/useConsistentCurlyBraces/invalid.jsx.snap @@ -1,5 +1,6 @@ --- source: crates/biome_js_analyze/tests/spec_tests.rs +assertion_line: 86 expression: invalid.jsx --- # Input @@ -16,6 +17,8 @@ expression: invalid.jsx } {/*comment*/'Hello world'/*comment*/} + +{x}{'y'}{z} ``` @@ -123,8 +126,8 @@ invalid.jsx:12:6 lint/nursery/useConsistentCurlyBraces FIXABLE ━━━━━ 11 │ > 12 │ {/*comment*/'Hello world'/*comment*/} │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 13 │ - 14 │ + 13 │ + 14 │ {x}{'y'}{z} i JSX child does not need to be wrapped in curly braces. @@ -134,8 +137,29 @@ invalid.jsx:12:6 lint/nursery/useConsistentCurlyBraces FIXABLE ━━━━━ 11 11 │ 12 │ - {/*comment*/'Hello·world'/*comment*/} 12 │ + {/*comment*/}Hello·world{/*comment*/} - 13 13 │ - 14 14 │ + 13 13 │ + 14 14 │ {x}{'y'}{z} + + +``` + +``` +invalid.jsx:14:9 lint/nursery/useConsistentCurlyBraces FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Should not have curly braces around expression. + + 12 │ {/*comment*/'Hello world'/*comment*/} + 13 │ + > 14 │ {x}{'y'}{z} + │ ^^^^^ + 15 │ + 16 │ + + i JSX child does not need to be wrapped in curly braces. + + i Unsafe fix: Remove curly braces around the expression. + 14 │ {x}{'y'}{z} + │ -- -- ```