Skip to content

Commit 00e97ad

Browse files
authored
fix(lint): noUselessFragments should ignore fragments with untrimmed whitespaces (#6425)
1 parent 4c90d55 commit 00e97ad

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#6391](https://github.com/biomejs/biome/issues/6391): the rule [`noUselessFragments`](https://biomejs.dev/linter/rules/no-useless-fragments/) no longer reports a fragment that contains whitespaces which aren't trimmed by the runtime.

crates/biome_js_analyze/src/lint/complexity/no_useless_fragments.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,21 @@ impl Rule for NoUselessFragments {
218218
// We need to whitespaces and newlines from the original string.
219219
// Since in the JSX newlines aren't trivia, we require to allocate a string to trim from those characters.
220220
let original_text = child.to_trimmed_text();
221-
let child_text = original_text.text().trim();
221+
let trimmed_text = original_text.text().trim();
222222

223223
if (in_jsx_expr || in_js_logical_expr)
224-
&& contains_html_character_references(child_text)
224+
&& contains_html_character_references(trimmed_text)
225225
{
226226
children_where_fragments_must_preserved = true;
227227
break;
228228
}
229229

230-
if !child_text.is_empty() {
230+
// Test whether a node is a padding spaces trimmed by the React runtime.
231+
let is_only_whitespace = trimmed_text.is_empty();
232+
let is_padding_spaces =
233+
is_only_whitespace && original_text.contains('\n');
234+
235+
if !is_padding_spaces {
231236
significant_children += 1;
232237
if first_significant_child.is_none() {
233238
first_significant_child = Some(child);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
appendToLastRow(rows, <> {character.leftBracket}</>);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
source: crates/biome_js_analyze/tests/spec_tests.rs
3+
expression: issue_6391.jsx
4+
---
5+
# Input
6+
```jsx
7+
appendToLastRow(rows, <> {character.leftBracket}</>);
8+
9+
```

0 commit comments

Comments
 (0)