Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/hot-adults-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [`#9296`](https://github.com/biomejs/biome/issues/9296), so comments are moved along with the attributes in the useSortedAttributes assist rule code fix.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl Rule for UseSortedAttributes {
for (PropElement { prop }, PropElement { prop: sorted_prop }) in
zip(state.props.iter(), state.get_sorted_props(comparator))
{
mutation.replace_node(prop.clone(), sorted_prop);
mutation.replace_node_discard_trivia(prop.clone(), sorted_prop);
}

Some(RuleAction::new(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Hello
// Simple comment
tel={5555555}
address="NY"
{...this.props}
// Another simple comment
lastName="Smith"
Comment on lines +2 to +7
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make these comments different so its more obvious to see if the comments stay with the attributes or not.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye true

firstName="John" // Inline comment
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
expression: with-comments.jsx
---
# Input
```jsx
<Hello
// Simple comment
tel={5555555}
address="NY"
{...this.props}
// Another simple comment
lastName="Smith"
firstName="John" // Inline comment
/>

```

# Diagnostics
```
with-comments.jsx:1:1 assist/source/useSortedAttributes FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

i The attributes are not sorted.

> 1 │ <Hello
│ ^^^^^^
> 2 │ // Simple comment
> 3 │ tel={5555555}
> 4 │ address="NY"
> 5 │ {...this.props}
> 6 │ // Another simple comment
> 7 │ lastName="Smith"
> 8 │ firstName="John" // Inline comment
> 9 │ />
│ ^^
10 │

i Safe fix: Sort the JSX props.

1 1 │ <Hello
2 │ - → //·Simple·comment
3 │ - → tel={5555555}
4 │ - → address="NY"
2 │ + → address="NY"
3 │ + → //·Simple·comment
4 │ + → tel={5555555}
5 5 │ {...this.props}
6 6 │ // Another simple comment


```

```
with-comments.jsx:1:1 assist/source/useSortedAttributes FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

i The attributes are not sorted.

> 1 │ <Hello
│ ^^^^^^
> 2 │ // Simple comment
> 3 │ tel={5555555}
> 4 │ address="NY"
> 5 │ {...this.props}
> 6 │ // Another simple comment
> 7 │ lastName="Smith"
> 8 │ firstName="John" // Inline comment
> 9 │ />
│ ^^
10 │

i Safe fix: Sort the JSX props.

4 4 │ address="NY"
5 5 │ {...this.props}
6 │ - → //·Another·simple·comment
7 │ - → lastName="Smith"
8 │ - → firstName="John"·//·Inline·comment
6 │ + → firstName="John"·//·Inline·comment
7 │ + → //·Another·simple·comment
8 │ + → lastName="Smith"
9 9 │ />
10 10 │


```