Skip to content

Commit

Permalink
fix(jsx_no_unescaped_entities): only warn about > and } (#1405)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister authored Jan 27, 2025
1 parent 0f1bc64 commit 19b5422
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/rules/jsx_no_unescaped_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()),
Expand Down Expand Up @@ -78,6 +74,7 @@ mod tests {
filename: "file:///foo.jsx",
r#"<div>&gt;</div>"#,
r#"<div>{">"}</div>"#,
r#"<div>{"}"}</div>"#,
};
}

Expand All @@ -86,14 +83,14 @@ mod tests {
assert_lint_err! {
JSXNoUnescapedEntities,
filename: "file:///foo.jsx",
r#"<div>'">}</div>"#: [
r#"<div>>}</div>"#: [
{
col: 0,
col: 5,
message: MESSAGE,
hint: HINT,
fix: (
"Escape entities in the text node",
"<div>&apos;&quot;&gt;&#125;</div>"
"<div>&gt;&#125;</div>"
)
}
]
Expand Down

0 comments on commit 19b5422

Please sign in to comment.