New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
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
  • Socket score

Version published
Weekly downloads
32
increased by52.38%
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc