You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The body text of this would render as x="y"> Body Text, which is probably not
what was intended. This rule requires that these special characters are
escaped if they appear in the body of a tag.
Another example is when one accidentally includes an extra closing brace.
<MyComponent>{'Text'}}</MyComponent>
The extra brace will be rendered, and the body text will be Text}.
This rule will also check for " and ', which might be accidentally included
when the closing > is in the wrong place.
<MyComponenta="b">{/* oops! */}
c="d"
Intended body text
</MyComponent>
The preferred way to include one of these characters is to use the HTML escape code.
> can be replaced with >
" can be replaced with ", “, " or ”
' can be replaced with ', ‘, ' or ’
} can be replaced with }
Alternatively, you can include the literal character inside a subexpression
(such as <div>{'>'}</div>.
The characters < and { should also be escaped, but they are not checked by this
rule because it is a syntax error to include those tokens inside of a tag.
https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unescaped-entities.md
From my testing, the configuration with no false positives is:
This rule prevents characters that you may have meant as JSX escape characters
from being accidentally injected as a text node in JSX statements.
For example, if one were to misplace their closing
>
in a tag:The body text of this would render as
x="y"> Body Text
, which is probably notwhat was intended. This rule requires that these special characters are
escaped if they appear in the body of a tag.
Another example is when one accidentally includes an extra closing brace.
The extra brace will be rendered, and the body text will be
Text}
.This rule will also check for
"
and'
, which might be accidentally includedwhen the closing
>
is in the wrong place.The preferred way to include one of these characters is to use the HTML escape code.
>
can be replaced with>
"
can be replaced with"
,“
,"
or”
'
can be replaced with'
,‘
,'
or’
}
can be replaced with}
Alternatively, you can include the literal character inside a subexpression
(such as
<div>{'>'}</div>
.The characters
<
and{
should also be escaped, but they are not checked by thisrule because it is a syntax error to include those tokens inside of a tag.
Rule Details
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Rule Options
forbid
Overwrite the default forbidden entities array
['>', '"', '\'', '}']
with your own:Where
char
is a special character andalternatives
is the correct escapes.The text was updated successfully, but these errors were encountered: