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

typescript-eslint-jsx-conditionals

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-eslint-jsx-conditionals

TypeScript ESlint rule to remove unsafe conditionals in JSX.

1.0.0
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

TypeScript ESLint JSX Conditionals

TypeScript ESLint rule to remove unsafe conditionals in JSX.

npm install --save-dev typescript-eslint-jsx-conditionals yarn add -D typescript-eslint-jsx-conditionals

.eslintrc.js example:

module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint', 'typescript-eslint-jsx-conditionals'],
  ignorePatterns: ['.eslintrc.js'],
  rules: {
    'typescript-eslint-jsx-conditionals/strict-jsx-conditionals': 'error',
  },
}

Valid:

const Component = ({ check }: { check: boolean }) => {
  return <div>{check && <p>Check</p>}</div>
}
const HelloWorld = () => {
  const someCondition = true
  return <div>{someCondition && <p>Check</p>}</div>
}

Invalid:

Check might be undefined.

const Component = ({ check }: { check?: boolean }) => {
  return <div>{check && <p>Check</p>}</div>
}

message.length is a number

const HelloWorld = () => {
  const message = 'hello world'

  return <div>{message.length && <p>Check</p>}</div>
}

Check might not be a boolean

const Component = ({ check }: { check: boolean | string | null }) => {
  return <div>{check && <p>Check</p>}</div>
}

Options

NameTypeDefault ValueDescription
preferBooleanbooleanfalseWhen using auto-fix, use Boolean() cast instead of !!
normalizebooleanfalseensure that your whole codebase uses the same type of casting - HIGHLY EXPERIMENTAL and NOT recommended

FAQs

Package last updated on 22 May 2021

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