From 19b5422d586b5cd44bdc3968d34ddec746be935c Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Mon, 27 Jan 2025 15:48:03 +0100 Subject: [PATCH] fix(jsx_no_unescaped_entities): only warn about > and } (#1405) --- src/rules/jsx_no_unescaped_entities.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/rules/jsx_no_unescaped_entities.rs b/src/rules/jsx_no_unescaped_entities.rs index 611079627..c8dceee9c 100644 --- a/src/rules/jsx_no_unescaped_entities.rs +++ b/src/rules/jsx_no_unescaped_entities.rs @@ -32,7 +32,7 @@ impl LintRule for JSXNoUnescapedEntities { } const MESSAGE: &str = "Found one or more unescaped entities in JSX text"; -const HINT: &str = "Escape the '\">} characters respectively"; +const HINT: &str = "Escape the >} characters respectively"; struct JSXNoUnescapedEntitiesHandler; @@ -41,15 +41,11 @@ impl Handler for JSXNoUnescapedEntitiesHandler { for child in node.children { if let JSXElementChild::JSXText(jsx_text) = child { let text = jsx_text.raw().as_str(); - let new_text = text - .replace('>', ">") - .replace('"', """) - .replace('\'', "'") - .replace('}', "}"); + let new_text = text.replace('>', ">").replace('}', "}"); if text != new_text { ctx.add_diagnostic_with_fixes( - node.range(), + jsx_text.range(), CODE, MESSAGE, Some(HINT.to_string()), @@ -78,6 +74,7 @@ mod tests { filename: "file:///foo.jsx", r#"
>
"#, r#"
{">"}
"#, + r#"
{"}"}
"#, }; } @@ -86,14 +83,14 @@ mod tests { assert_lint_err! { JSXNoUnescapedEntities, filename: "file:///foo.jsx", - r#"
'">}
"#: [ + r#"
>}
"#: [ { - col: 0, + col: 5, message: MESSAGE, hint: HINT, fix: ( "Escape entities in the text node", - "
'">}
" + "
>}
" ) } ]