Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preserve other children in useConsistentCurlyBraces #3925

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
│ -- --

```
Loading