eslint-plugin-jsx-conditionals
Ensuring 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.
// BADconst Component = check <div> check && <p>Check passes!</p> </div>; // GOODconst Component = check <div> !!check && <p>Check passes!</p> && <p>Check passes!</p> check ? <p>Check passes!</p> : null </div>;
Usage
yarn add eslint-plugin-jsx-conditionals --dev
In your .eslintrc
config:
Development
git clone git@github.com:julianburr/eslint-plugin-jsx-conditionals.gitcd eslint-plugin-jsx-conditionalsyarn # Run tests yarn test