diff --git a/.changeset/fix-curly-braces-opening-brace.md b/.changeset/fix-curly-braces-opening-brace.md new file mode 100644 index 000000000000..cfaf2049e5f1 --- /dev/null +++ b/.changeset/fix-curly-braces-opening-brace.md @@ -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 (`{`, `}`, `<`, `>`, `&`). diff --git a/crates/biome_js_analyze/src/lint/style/use_consistent_curly_braces.rs b/crates/biome_js_analyze/src/lint/style/use_consistent_curly_braces.rs index 3a1ecad3c5d1..a793be454e35 100644 --- a/crates/biome_js_analyze/src/lint/style/use_consistent_curly_braces.rs +++ b/crates/biome_js_analyze/src/lint/style/use_consistent_curly_braces.rs @@ -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| { diff --git a/crates/biome_js_analyze/tests/specs/style/useConsistentCurlyBraces/valid.jsx b/crates/biome_js_analyze/tests/specs/style/useConsistentCurlyBraces/valid.jsx index 4fe602bf27aa..79bdbd532d26 100644 --- a/crates/biome_js_analyze/tests/specs/style/useConsistentCurlyBraces/valid.jsx +++ b/crates/biome_js_analyze/tests/specs/style/useConsistentCurlyBraces/valid.jsx @@ -28,6 +28,22 @@ let baz = 4; {'Invalid closing tag }'} +Invalid opening tag {'{'} + +{'Invalid opening tag {'} + +{'start {{'} + +{'}} end'} + +{'