
Product
Introducing Repository Labels and Security Policies
Socket is introducing a new way to organize repositories and apply repository-specific security policies.
eslint-plugin-jsx-no-leaked-values
Advanced tools
Avoid accidentally rendering `0` or `NaN`. Requires `@typescript-eslint/parser`.
Avoid accidentally rendering 0
or NaN
. Requires @typescript-eslint/parser
.
function MyComponent() {
return (
<div>
{0 && <ComponentX /> /* error */}
{NaN && <ComponentX /> /* error */}
{undefined && <ComponentX /> /* no error */}
{null && <ComponentX /> /* no error */}
{'' && <ComponentX /> /* no error */}
{false && <ComponentX /> /* no error */}
</div>
);
}
npm i -D eslint-plugin-jsx-no-leaked-values
Install and enable typescript-eslint with type linting, see:
npm install -D @typescript-eslint/parser@latest @typescript-eslint/eslint-plugin@latest eslint@latest typescript@latest
"parser": "@typescript-eslint/parser",
"parserOptions": {
"tsconfigRootDir": ".",
"project": ["./tsconfig.json"]
},
"plugins": ["@typescript-eslint"],
Configure the plugin in your .eslintrc
:
{
"extends": ["plugin:jsx-no-leaked-values/recommended"]
}
This essentially expands to:
{
"plugins": ["jsx-no-leaked-values"],
"rules": {
"jsx-no-leaked-values/jsx-no-leaked-values": "error"
}
}
The jsx-no-leaked-render react plugin reports an error for all uses of &&
that do not start with Boolean(value)
or !!value
. This means that all values have to be coerced at the expression as it is not type aware, even booleans!
On my codebase it reported a lint error for almost all uses of &&
and meant those cases had to be made a ternary or converted via Boolean at the expression.
This plugin uses type information via typescript-eslint to only show an error for number
, 0
or NaN
.
Seeing as undefined
, null
and ''
do not render on screen, I deemed it unnecessary to report errors for those cases.
Inspired by:
FAQs
Avoid accidentally rendering `0` or `NaN`. Requires `@typescript-eslint/parser`.
The npm package eslint-plugin-jsx-no-leaked-values receives a total of 4,808 weekly downloads. As such, eslint-plugin-jsx-no-leaked-values popularity was classified as popular.
We found that eslint-plugin-jsx-no-leaked-values demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket is introducing a new way to organize repositories and apply repository-specific security policies.
Research
Security News
Socket researchers uncovered malicious npm and PyPI packages that steal crypto wallet credentials using Google Analytics and Telegram for exfiltration.
Product
Socket now supports .NET, bringing supply chain security and SBOM accuracy to NuGet and MSBuild-powered C# projects.