Skip to content

Commit

Permalink
fix: preserve other children in useConsistentCurlyBraces (#3925)
Browse files Browse the repository at this point in the history
  • Loading branch information
suzak committed Sep 16, 2024
1 parent 2a775c7 commit 2eb6faa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,16 @@ impl Rule for UseConsistentCurlyBraces {

let child_list = node.parent::<JsxChildList>()?;
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);
}
children.push(jsx_text.clone());
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
}</Foo>

<Foo>{/*comment*/'Hello world'/*comment*/}</Foo>

<Foo>{x}{'y'}{z}</Foo>
</>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 86
expression: invalid.jsx
---
# Input
Expand All @@ -16,6 +17,8 @@ expression: invalid.jsx
}</Foo>

<Foo>{/*comment*/'Hello world'/*comment*/}</Foo>

<Foo>{x}{'y'}{z}</Foo>
</>

```
Expand Down Expand Up @@ -123,8 +126,8 @@ invalid.jsx:12:6 lint/nursery/useConsistentCurlyBraces FIXABLE ━━━━━
11 │
> 12 │ <Foo>{/*comment*/'Hello world'/*comment*/}</Foo>
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13 │ </>
14 │
13 │
14 │ <Foo>{x}{'y'}{z}</Foo>
i JSX child does not need to be wrapped in curly braces.
Expand All @@ -134,8 +137,29 @@ invalid.jsx:12:6 lint/nursery/useConsistentCurlyBraces FIXABLE ━━━━━
11 11 │
12 │ - <Foo>{/*comment*/'Hello·world'/*comment*/}</Foo>
12 │ + <Foo>{/*comment*/}Hello·world{/*comment*/}</Foo>
13 13 │ </>
14 14 │
13 13 │
14 14 │ <Foo>{x}{'y'}{z}</Foo>
```

```
invalid.jsx:14:9 lint/nursery/useConsistentCurlyBraces FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Should not have curly braces around expression.
12 │ <Foo>{/*comment*/'Hello world'/*comment*/}</Foo>
13 │
> 14 │ <Foo>{x}{'y'}{z}</Foo>
│ ^^^^^
15 │ </>
16 │
i JSX child does not need to be wrapped in curly braces.
i Unsafe fix: Remove curly braces around the expression.
14 │ <Foo>{x}{'y'}{z}</Foo>
│ -- --
```

0 comments on commit 2eb6faa

Please sign in to comment.