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 855731e8b5cec..2fbb97a8b22c6 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 @@ -534,7 +534,7 @@ fn is_allowed_string_like_in_container<'a>( is_prop: bool, ) -> bool { is_whitespace(s) - || contains_line_break_or_is_empty(s) + || contains_line_break(s) || contains_html_entity(s) || is_prop && contains_both_quote_characters(s) || !is_prop && contains_disallowed_jsx_text_chars(s) @@ -546,11 +546,11 @@ fn is_allowed_string_like_in_container<'a>( } fn is_whitespace(s: &str) -> bool { - s.chars().all(char::is_whitespace) + !s.is_empty() && s.chars().all(char::is_whitespace) } -fn contains_line_break_or_is_empty(s: &str) -> bool { - s.chars().any(|c| matches!(c, '\n' | '\r')) || s.trim().is_empty() +fn contains_line_break(s: &str) -> bool { + s.chars().any(|c| matches!(c, '\n' | '\r')) } fn contains_line_break_literal(s: &str) -> bool { @@ -1225,6 +1225,8 @@ fn test() { "#, Some(json!(["never"])), ), + (r#"{""}"#, Some(json!([{ "props": "never", "children": "never" }]))), + (r#"{""}"#, Some(json!([{ "props": "never", "children": "never" }]))), ]; let fix = vec![ @@ -1544,6 +1546,16 @@ fn test() { "#, Some(json!(["never"])), ), + ( + r#"{""}"#, + r#""#, + Some(json!([{ "props": "never", "children": "never" }])), + ), + ( + r#"{""}"#, + r"", + Some(json!([{ "props": "never", "children": "never" }])), + ), ( " 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 9b8fbbd9a7830..1a1bb44bc8a68 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 @@ -497,3 +497,17 @@ source: crates/oxc_linter/src/tester.rs 3 │ ╰──── help: Replace `{'The maximum time range for searches. (i.e. "P30D" for 30 days, "PT24H" for 24 hours)'}` with `'The maximum time range for searches. (i.e. "P30D" for 30 days, "PT24H" for 24 hours)'`. + + ⚠ eslint-plugin-react(jsx-curly-brace-presence): Curly braces are unnecessary here. + ╭─[jsx_curly_brace_presence.tsx:1:13] + 1 │ {""} + · ── + ╰──── + help: Replace `{""}` with `""`. + + ⚠ eslint-plugin-react(jsx-curly-brace-presence): Curly braces are unnecessary here. + ╭─[jsx_curly_brace_presence.tsx:1:7] + 1 │ {""} + · ── + ╰──── + help: Replace `{""}` with ``.