no-unneeded-ternary
Configuration
rslint.config.ts
Rule Details
Disallows ternary expressions when a simpler alternative exists. Two patterns are flagged:
- Boolean-literal selection —
cond ? true : false(or any combination of boolean literals on both arms) collapses tocond,!cond,!!cond, or the boolean literal itself. Always reported. - Default assignment —
a ? a : bis equivalent toa || b. Reported only when thedefaultAssignmentoption is set tofalse.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Examples of incorrect code for this rule with { "defaultAssignment": false }: