From c8e200c4adbd71e415cba2716ddba7cfef5951bd Mon Sep 17 00:00:00 2001
From: Sysix <3897725+Sysix@users.noreply.github.com>
Date: Fri, 8 Aug 2025 10:38:39 +0000
Subject: [PATCH] fix(linter): `react/jsx-curly-brace-presence` report for
JSXAttributeItem with quote char inside (#12888)
---
.../rules/react/jsx_curly_brace_presence.rs | 34 ++++++++-----------
.../react_jsx_curly_brace_presence.snap | 14 ++++++++
2 files changed, 28 insertions(+), 20 deletions(-)
diff --git a/crates/oxc_linter/src/rules/react/jsx_curly_brace_presence.rs b/crates/oxc_linter/src/rules/react/jsx_curly_brace_presence.rs
index 52655f99f0082..27ef42c460ea7 100644
--- a/crates/oxc_linter/src/rules/react/jsx_curly_brace_presence.rs
+++ b/crates/oxc_linter/src/rules/react/jsx_curly_brace_presence.rs
@@ -465,15 +465,10 @@ impl JsxCurlyBracePresence {
if allowed.is_never()
&& let Some(string) = template.single_quasi()
{
- if contains_quote_characters(string.as_str())
- || is_allowed_string_like(
- ctx,
- string.as_str(),
- container,
- node.id(),
- is_prop,
- )
- {
+ if !is_prop && contains_quote_characters(&string) {
+ return;
+ }
+ if is_allowed_string_like(ctx, string.as_str(), container, node.id(), is_prop) {
return;
}
report_unnecessary_curly(ctx, container, template.span);
@@ -499,7 +494,6 @@ fn is_allowed_string_like<'a>(
|| contains_multiline_comment(s)
|| contains_line_break_literal(s)
|| contains_utf8_escape(s)
- || is_prop && contains_quote_characters(s)
|| has_adjacent_jsx_expression_containers(ctx, container, node_id)
}
@@ -974,16 +968,16 @@ fn test() {
"} />",
Some(json!([{ "props": "never", "children": "never", "propElementValues": "never" }])),
),
- // (
- // r#""#,
- // Some(json!([{ "props": "never", "children": "never", "propElementValues": "never" }])),
- // ),
- //(
- // r#"
- //
- // "#,
- // Some(json!(["never"])),
- //),
+ (
+ r#""#,
+ Some(json!([{ "props": "never", "children": "never", "propElementValues": "never" }])),
+ ),
+ (
+ r#"
+
+ "#,
+ Some(json!(["never"])),
+ ),
];
// TODO: implement fixer
diff --git a/crates/oxc_linter/src/snapshots/react_jsx_curly_brace_presence.snap b/crates/oxc_linter/src/snapshots/react_jsx_curly_brace_presence.snap
index 0b341a7b6ab5b..5ef78e487a23d 100644
--- a/crates/oxc_linter/src/snapshots/react_jsx_curly_brace_presence.snap
+++ b/crates/oxc_linter/src/snapshots/react_jsx_curly_brace_presence.snap
@@ -411,3 +411,17 @@ source: crates/oxc_linter/src/tester.rs
1 │ } />
· ───────
╰────
+
+ ⚠ eslint-plugin-react(jsx-curly-brace-presence): Curly braces are unnecessary here.
+ ╭─[jsx_curly_brace_presence.tsx:1:11]
+ 1 │
+ · ───
+ ╰────
+
+ ⚠ eslint-plugin-react(jsx-curly-brace-presence): Curly braces are unnecessary here.
+ ╭─[jsx_curly_brace_presence.tsx:2:29]
+ 1 │
+ 2 │
+ · ──────────────────────────────────────────────────────────────────────────────────────
+ 3 │
+ ╰────