-
-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lint): prevent crash when applying
noUselessFragments
unsafe fi…
…xes (#3338)
- Loading branch information
Showing
4 changed files
with
91 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
crates/biome_js_analyze/tests/specs/complexity/noUselessFragments/issue_3149.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function fn(member) { | ||
fn(<>{member.expression}</>); | ||
fn(<>{member.expression()}</>); | ||
(<>{1}</>).toString(); | ||
} |
76 changes: 76 additions & 0 deletions
76
crates/biome_js_analyze/tests/specs/complexity/noUselessFragments/issue_3149.jsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
source: crates/biome_js_analyze/tests/spec_tests.rs | ||
expression: issue_3149.jsx | ||
--- | ||
# Input | ||
```jsx | ||
function fn(member) { | ||
fn(<>{member.expression}</>); | ||
fn(<>{member.expression()}</>); | ||
(<>{1}</>).toString(); | ||
} | ||
|
||
``` | ||
|
||
# Diagnostics | ||
``` | ||
issue_3149.jsx:2:6 lint/complexity/noUselessFragments FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! Avoid using unnecessary Fragment. | ||
1 │ function fn(member) { | ||
> 2 │ fn(<>{member.expression}</>); | ||
│ ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
3 │ fn(<>{member.expression()}</>); | ||
4 │ (<>{1}</>).toString(); | ||
i A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment. | ||
i Unsafe fix: Remove the Fragment | ||
2 │ ··fn(<>{member.expression}</>); | ||
│ --- ---- | ||
``` | ||
|
||
``` | ||
issue_3149.jsx:3:6 lint/complexity/noUselessFragments FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! Avoid using unnecessary Fragment. | ||
1 │ function fn(member) { | ||
2 │ fn(<>{member.expression}</>); | ||
> 3 │ fn(<>{member.expression()}</>); | ||
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
4 │ (<>{1}</>).toString(); | ||
5 │ } | ||
i A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment. | ||
i Unsafe fix: Remove the Fragment | ||
3 │ ··fn(<>{member.expression()}</>); | ||
│ --- ---- | ||
``` | ||
|
||
``` | ||
issue_3149.jsx:4:4 lint/complexity/noUselessFragments FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! Avoid using unnecessary Fragment. | ||
2 │ fn(<>{member.expression}</>); | ||
3 │ fn(<>{member.expression()}</>); | ||
> 4 │ (<>{1}</>).toString(); | ||
│ ^^^^^^^^ | ||
5 │ } | ||
6 │ | ||
i A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment. | ||
i Unsafe fix: Remove the Fragment | ||
4 │ ··(<>{1}</>).toString(); | ||
│ --- ---- | ||
``` |