🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

eslint-plugin-jsx-conditionals

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-jsx-conditionals

Ensuring variables are cast to booleans whenever using `&&` conditionals in JSX to avoid unwanted side effects

2.0.0
latest
Source
npm
Version published
Weekly downloads
202
20.24%
Maintainers
1
Weekly downloads
 
Created
Source

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.

// BAD
const Component = ({ check }) => (
  <div>
    {check && <p>Check passes!</p>}
  </div>
);

// GOOD
const Component = ({ check }) => (
  <div>
    {!!check && <p>Check passes!</p>}
    {Boolean(check) && <p>Check passes!</p>}
    {check ? <p>Check passes!</p> : null}
  </div>
);

Usage

yarn add eslint-plugin-jsx-conditionals --dev

In your .eslintrc config:

{
  "plugins": [ "jsx-conditionals" ],
  "rules": {
    "jsx-conditionals/ensure-booleans": "error"
  }
}

Development

git clone git@github.com:julianburr/eslint-plugin-jsx-conditionals.git
cd eslint-plugin-jsx-conditionals
yarn

# Run tests
yarn test

FAQs

Package last updated on 29 Dec 2018

Did you know?

Socket

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.

Install

Related posts