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
20 changes: 16 additions & 4 deletions crates/oxc_linter/src/rules/react/jsx_curly_brace_presence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -1225,6 +1225,8 @@ fn test() {
"#,
Some(json!(["never"])),
),
(r#"<Image alt={""} />"#, Some(json!([{ "props": "never", "children": "never" }]))),
(r#"<App>{""}</App>"#, Some(json!([{ "props": "never", "children": "never" }]))),
];

let fix = vec![
Expand Down Expand Up @@ -1544,6 +1546,16 @@ fn test() {
"#,
Some(json!(["never"])),
),
(
r#"<Image alt={""} />"#,
r#"<Image alt="" />"#,
Some(json!([{ "props": "never", "children": "never" }])),
),
(
r#"<App>{""}</App>"#,
r"<App></App>",
Some(json!([{ "props": "never", "children": "never" }])),
),
(
"
<App>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 │ <Image alt={""} />
· ──
╰────
help: Replace `{""}` with `""`.

⚠ eslint-plugin-react(jsx-curly-brace-presence): Curly braces are unnecessary here.
╭─[jsx_curly_brace_presence.tsx:1:7]
1 │ <App>{""}</App>
· ──
╰────
help: Replace `{""}` with ``.
Expand Down
Loading