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
34 changes: 14 additions & 20 deletions crates/oxc_linter/src/rules/react/jsx_curly_brace_presence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
}

Expand Down Expand Up @@ -974,16 +968,16 @@ fn test() {
"<App horror={<div />} />",
Some(json!([{ "props": "never", "children": "never", "propElementValues": "never" }])),
),
// (
// r#"<Foo bar={"'"} />"#,
// Some(json!([{ "props": "never", "children": "never", "propElementValues": "never" }])),
// ),
//(
// r#"
// <Foo help={'The maximum time range for searches. (i.e. "P30D" for 30 days, "PT24H" for 24 hours)'} />
// "#,
// Some(json!(["never"])),
//),
(
r#"<Foo bar={"'"} />"#,
Some(json!([{ "props": "never", "children": "never", "propElementValues": "never" }])),
),
(
r#"
<Foo help={'The maximum time range for searches. (i.e. "P30D" for 30 days, "PT24H" for 24 hours)'} />
"#,
Some(json!(["never"])),
),
];

// TODO: implement fixer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,17 @@ source: crates/oxc_linter/src/tester.rs
1 │ <App horror={<div />} />
· ───────
╰────

⚠ eslint-plugin-react(jsx-curly-brace-presence): Curly braces are unnecessary here.
╭─[jsx_curly_brace_presence.tsx:1:11]
1 │ <Foo bar={"'"} />
· ───
╰────

⚠ eslint-plugin-react(jsx-curly-brace-presence): Curly braces are unnecessary here.
╭─[jsx_curly_brace_presence.tsx:2:29]
1 │
2 │ <Foo help={'The maximum time range for searches. (i.e. "P30D" for 30 days, "PT24H" for 24 hours)'} />
· ──────────────────────────────────────────────────────────────────────────────────────
3 │
╰────
Expand Down
Loading