Rules
no-comment-textnodes
Prevents comment strings from being accidentally inserted into a JSX element's text nodes.
Full Name in eslint-plugin-react-jsx
react-jsx/no-comment-textnodesFull Name in @eslint-react/eslint-plugin
@eslint-react/jsx-no-comment-textnodesPresets
recommended
recommended-typescript
recommended-type-checked
strict
strict-typescript
strict-type-checked
Rule Details
This rule prevents comment strings (ex: beginning with // or /*) from being accidentally inserted into a JSX element's text nodes.
Comments inside JSX elements should be placed inside braces ({/* comment */}) to prevent them from being rendered as text.
Common Violations
Invalid
function MyComponent() {
return (
<div>
// This will be rendered as text
/* This will also be rendered as text */
</div>
);
}Valid
function MyComponent() {
return (
<div>
{/* This is a valid comment inside JSX */}
<span>Hello</span>
</div>
);
}