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 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} 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} + │ -- -- ```