
Security News
US Government Forces Anthropic to Pull Claude Fable Days After Launch
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.
eslint-plugin-jsx-conditional
Advanced tools
Enforces a consistent use of conditional expressions in jsx
Enforce or forbid the use of conditionals expressions using a ternary or a logical expression using an AND && operator in JSX.
In other words, it allows to keep a consistent use of the way jsx elements are showned based on a condition
Fixable: This rule is automatically fixable by using the --fix option on the command line.
This rule checks that conditionals expressions or logical expression match a certain shape.
This rule accepts as a first argument one of these two possible values:
prefer-ternaryprefer-and-operatorThe default value is prefer-ternary.
It also accepts a second argument defining the options of the rule. Options are:
exceptNotNullishAlternates: this option is taken into account only on prefer-and-operator modeprefer-ternaryThis option will check for logical expressions inside JSX code and if it finds a logical expression that follows the following shape:
<>{identifier && JSXElement | JSXFragment}</>
And this would be auto fixable outputing the following code
<>{identifier ? JSXElement | JSXFragment : null}</>
✅ Examples of valid code:
function Component({ propA }) {
return <>{propA ? <span>Hello</span> : null}</>;
}
function Component({ propA }) {
return <>{propA ? <span>Hello</span> : <span>Hello</span>}</>;
}
function Component({ propA }) {
return (
<>
{propA ? (
<>
<span>Hello</span>
<span>Hello 2</span>
</>
) : null}
</>
);
}
❌ Examples of invalid code:
function Component({ propA }) {
return <>{propA && <span>Hello</span>}</>;
}
function Component({ propA }) {
return (
<>
{propA && <span>Hello</span>}
{!propA && <span>Hello</span>}
</>
);
}
function Component({ propA }) {
return (
<>
{propA && (
<>
<span>Hello</span>
<span>Hello 2</span>
</>
)}
</>
);
}
prefer-and-operatorThis option will check for conditional expressions inside JSX code and if it finds a conditional expression that follows the following shape:
<>{identifier ? JSXElement | JSXFragment : JSXElement | JSXFragment}</>
And this would be auto fixable outputing the following code
<>
{identifier && JSXElement | JSXFragment}
{!identifier && JSXElement | JSXFragment}
</>
Being two logical expressions where the first tests the condition and renders the consequent of the conditional expression and the second negates the test and renders the alternate.
If a conditional expression is preferred over a logical expression when the alternate is not null or undefined you can tell the rule your
preferences by using the option exceptNotNullishAlternates as a second argument in the rule declaration on .eslintrc
Example:
// .eslintrc.js
module.exports = {
extends: [...],
plugins: [..., 'jsx-conditional'],
rules: {
...
'jsx-conditional/jsx-conditional': ['error', 'prefer-and-operator', { exceptNotNullishAlternates: true }]
...
}
}
✅ Examples of valid code:
function Component({ propA }) {
return <>{propA && <span>Hello</span>}</>;
}
function Component({ propA }) {
return (
<>
{propA && <span>Hello</span>}
{!propA && <span>Hello</span>}
</>
);
}
function Component({ propA }) {
return (
<>
{propA && (
<>
<span>Hello</span>
<span>Hello 2</span>
</>
)}
</>
);
}
❌ Examples of invalid code:
function Component({ propA }) {
return <>{propA ? <span>Hello</span> : null}</>;
}
This can be valid if you prefer by indicating it in the options argument { exceptNotNullishAlternates: true }, but without it the following code would be invalid.
function Component({ propA }) {
return <>{propA ? <span>Hello</span> : <span>Hello</span>}</>;
}
function Component({ propA }) {
return (
<>
{propA ? (
<>
<span>Hello</span>
<span>Hello 2</span>
</>
) : null}
</>
);
}
You can decide to not use it or turn it off if you are not concerned about the consistency of rendering elements based on a condition, either by using a ternary operator or using a logical expression
FAQs
Enforces a consistent use of conditional expressions in jsx
The npm package eslint-plugin-jsx-conditional receives a total of 839 weekly downloads. As such, eslint-plugin-jsx-conditional popularity was classified as not popular.
We found that eslint-plugin-jsx-conditional demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.

Security News
A network of 152 Chrome live wallpaper extensions hid ad tracking and made extension-driven traffic look like Google search clicks.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.