Rules
jsx-dollar
Prevents unintentional '$' sign before expression.
Full Name in eslint-plugin-react-x
react-x/jsx-dollarFull Name in @eslint-react/eslint-plugin
@eslint-react/jsx-dollarFeatures
🔧
Presets
Rule Details
This can happen when refactoring from a template literal to JSX and forgetting to remove the dollar sign. This results in an unintentional $ being rendered in the output.
function MyComponent({ user }) {
return `Hello ${user.name}`;
}When refactored to JSX, it might look like this:
function MyComponent({ user }) {
return <>Hello ${user.name}</>;
}In this example, the $ before {user.name} is unnecessary and will be rendered as part of the output.
Common Violations
Invalid
function MyComponent({ user }) {
return <div>Hello ${user.name}</div>;
// ^ Possible unintentional '$' sign before expression.
}function MyComponent({ user }) {
return <div>${user.name} is your name</div>;
// ^ Possible unintentional '$' sign before expression.
}function MyComponent({ count, total }) {
return <div>Progress: ${count} / ${total}</div>;
// ^ ^ Possible unintentional '$' sign before expression.
}Valid
function MyComponent({ user }) {
return `Hello ${user.name}`;
}function MyComponent({ user }) {
return <div>Hello {user.name}</div>;
}function MyComponent({ price }) {
return <div>${price}</div>;
}Resources
Further Reading
See Also
react-x/jsx-no-comment-textnodes
Prevents comment strings (ex: beginning with//or/*) from being accidentally inserted into a JSX element's text nodes.