-
-
Notifications
You must be signed in to change notification settings - Fork 442
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(analyze): check if a fragment has only one child element using tokens. #3582
fix(analyze): check if a fragment has only one child element using tokens. #3582
Conversation
CodSpeed Performance ReportMerging #3582 will degrade performances by 6.98%Comparing Summary
Benchmarks breakdown
|
A test i s failing. <>
foo
</> |
2 │ - <> | ||
3 │ - → <Component·/> | ||
4 │ - </>; | ||
2 │ + ""; | ||
5 3 │ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a regression here
@Conaclos @ematipico |
@satojin219 Can you update the changelog to describe your fix? https://github.com/biomejs/biome/blob/main/CONTRIBUTING.md#writing-a-changelog-line |
chore: updaste CHANGELOG.md |
Summary
This bug occurs when a warning is supposed to be issued if a fragment has only one child element, but if line breaks or tabs are included, the warning does not appear. To check the number of child elements, child_list.len() is used, but this includes line breaks and tabs, causing the count of child elements to be more than one.
https://github.com/biomejs/biome/blob/main/crates/biome_js_analyze/src/lint/complexity/no_useless_fragments.rs#L165
Therefore, I modified the code to scan the tokens of the fragment's children and check if there is only one
JsSyntaxKind::JSX_SELF_CLOSING_ELEMENT
orJsSyntaxKind::JSX_ELEMENT
.Test Plan
Change the path on line 17 of
crates/biome_js_analyze/tests/quick_test.rs
totests/specs/complexity/noUselessFragments/issue_3545.jsx
andtests/specs/complexity/noUselessFragments/withJsxElementInvalid.jsx.
Run the tests and confirm that both tests pass successfully.closed #3545