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/fix-curly-braces-opening-brace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [#8011](https://github.com/biomejs/biome/issues/8011): [`useConsistentCurlyBraces`](https://biomejs.dev/linter/rules/use-consistent-curly-braces/) no longer suggests removing curly braces from JSX expression children containing characters that would cause parsing issues or semantic changes when converted to plain JSX text (`{`, `}`, `<`, `>`, `&`).
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,17 @@ fn contains_only_spaces(literal: &JsStringLiteralExpression) -> bool {
.is_ok_and(|text| text.bytes().all(|b| b == b' '))
}

const FORBIDDEN_CHARS: [char; 4] = ['>', '"', '\'', '}'];
/// Characters that would cause parsing issues or semantic changes if a JSX expression
/// child is converted to plain JSX text. When a string literal contains any of these,
/// we must NOT suggest removing the curly braces.
///
/// - `{` `}` - would be parsed as expression delimiters
/// - `<` `>` - would be parsed as tag delimiters
/// - `&` - would be parsed as HTML entity start
/// - `"` `'` - included for consistency, though mainly relevant in attribute contexts
///
/// See: https://github.com/biomejs/biome/issues/8011
const FORBIDDEN_CHARS: [char; 7] = ['{', '}', '<', '>', '&', '"', '\''];

fn contains_forbidden_chars(str_literal: &JsStringLiteralExpression) -> bool {
str_literal.inner_string_text().is_ok_and(|text| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ let baz = 4;

<Foo>{'Invalid closing tag }'}</Foo>

<Foo>Invalid opening tag {'{'}</Foo>

<Foo>{'Invalid opening tag {'}</Foo>

<Foo>{'start {{'}</Foo>

<Foo>{'}} end'}</Foo>

<Foo>{'<script>'}</Foo>

<Foo>{'a < b'}</Foo>

<Foo>{'&amp;'}</Foo>

<Foo>{'Tom & Jerry'}</Foo>

<Foo>Jupiter {">"} Venus</Foo>

<Foo>Jupiter {'>'} Venus</Foo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ let baz = 4;

<Foo>{'Invalid closing tag }'}</Foo>

<Foo>Invalid opening tag {'{'}</Foo>

<Foo>{'Invalid opening tag {'}</Foo>

<Foo>{'start {{'}</Foo>

<Foo>{'}} end'}</Foo>

<Foo>{'<script>'}</Foo>

<Foo>{'a < b'}</Foo>

<Foo>{'&amp;'}</Foo>

<Foo>{'Tom & Jerry'}</Foo>

<Foo>Jupiter {">"} Venus</Foo>

<Foo>Jupiter {'>'} Venus</Foo>
Expand Down
Loading