Ensuring variables are cast to booleans whenever using `&&` conditionals in JSX to avoid unwanted side effects
npm install eslint-plugin-jsx-conditionalsEnsuring variables used in JSX conditionals are cast to booleans whenever using && to avoid unwanted side effects, e.g. for other falsey values like empty strings etc.
`` Check passes!jsx
// BAD
const Component = ({ check }) => (
{check &&
);
// GOOD
const Component = ({ check }) => (
Check passes!
}Check passes!
}Check passes!
: null}Usage
`bash
yarn add eslint-plugin-jsx-conditionals --dev
`In your
.eslintrc config:
`json
{
"plugins": [ "jsx-conditionals" ],
"rules": {
"jsx-conditionals/ensure-booleans": "error"
}
}
`
Development
`bash
git clone git@github.com:julianburr/eslint-plugin-jsx-conditionals.git
cd eslint-plugin-jsx-conditionals
yarnRun tests
yarn test
``