no-unnecessary-boolean-literal-compare
Configuration
rslint.config.ts
Rule Details
Disallow unnecessary equality comparisons against boolean literals.
Comparing a boolean value to true or false is redundant. The value can be used directly or negated instead. This rule flags such comparisons and provides auto-fixes.
Options
allowComparingNullableBooleansToTrue(default:true): When set totrue, allowsnullableVar === trueornullableVar !== truecomparisons for nullable boolean types (boolean | null | undefined). Set tofalseto flag these comparisons.allowComparingNullableBooleansToFalse(default:true): When set totrue, allowsnullableVar === falseornullableVar !== falsecomparisons for nullable boolean types. Set tofalseto flag these comparisons and suggest using the??operator instead.allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing(default:false): When set totrue, allows the rule to run even whenstrictNullChecksis not enabled. By default, the rule reports an error ifstrictNullChecksis off.
Examples of incorrect code for this rule:
Examples of incorrect code with { allowComparingNullableBooleansToTrue: false }:
Examples of incorrect code with { allowComparingNullableBooleansToFalse: false }:
Examples of correct code for this rule: