Reports ternary expressions that can be simplified to boolean expressions or logical operators
✅ This rule is included in the ts stylistic and stylisticStrict presets.
Ternary expressions can sometimes be simplified to more concise and readable forms.
In particular:
- Boolean ternaries: ternary expressions that return
true or false based on a condition can be simplified to the condition itself or its negation.
- Redundant ternaries: ternary expressions where the consequent duplicates the condition can be replaced with a logical OR operator (
||).
This rule detects and reports ternary expressions that can be replaced with boolean expressions or logical operators.
AEconsB0isActiAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53stat= sp>AE ==<= sp ansty="le--0:#D9F5DD;--1:#1111">1= sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dacti1"sp>1<1"sp ansty="le--0:#C792EA;--1:#8844">AE 1"sp> sp ansty="le--0:#FF6A83;--1:#A248">48tr? sp>AE <: sp ansty="le--0:#FF6A83;--1:#A248">48fal5<3;d ivclassNa="meco">3;d>AEconsB0isInactiAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53stat= sp>AE ==<= sp ansty="le--0:#D9F5DD;--1:#1111">1= sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dacti1"sp>1<1"sp ansty="le--0:#C792EA;--1:#8844">AE 1"sp> sp ansty="le--0:#FF6A83;--1:#A248">48fal? sp>AE <: sp ansty="le--0:#FF6A83;--1:#A248">48tr5<3;d ivclassNa="meco">3;d>AEconsB0resuAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53val= sp>AE sp ansty="le--0:#D6DEEB;--1:#403F">53val? sp>AE <: sp ansty="le--0:#D6DEEB;--1:#403F">53defaultValuAEconsB0resuAE =< !sp ansty="le--0:#D6DEEB;--1:#403F">53val !sp>AE sp ansty="le--0:#D6DEEB;--1:#403F">53alternati? sp>AE <: sp ansty="le--0:#D6DEEB;--1:#403F">53valu 44AEco61B0isAc44A3F53st44AE <=== spans="tyle--0:#D9F5DD;--1:#11">1=== ><111" spans="tyle--0:#ECC48D;--1:#98">4E4Dac111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3111"><;di vdivclass="Nameexpressive-">44AEco61B0isInac44AE< = ! spans="tyle--0:#D6DEEB;--1:#40">3F53(st = !>44AE <=== spans="tyle--0:#D9F5DD;--1:#11">1=== ><111" spans="tyle--0:#ECC48D;--1:#98">4E4Dac111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53) ;divclass="Name">53)>;di><;di vdivclass="Nameexpressive-">44AEco61B0re44A3F53v44AE< || spans="tyle--0:#D6DEEB;--1:#40">3F53defaultVa || >;di><;di vdivclass="Nameexpressive-">44AEco61B0re44A3F53v44AE< || spans="tyle--0:#D6DEEB;--1:#40">3F53alternat || >;di>
This rule is not configurable.
If you have a large codebase with established patterns using ternary expressions for clarity, or if your team prefers explicit ternary expressions over logical operators, this rule might not be for you.