Skip to content

Latest commit

Β 

History

History
45 lines (31 loc) Β· 1.26 KB

File metadata and controls

45 lines (31 loc) Β· 1.26 KB

no-unnecessary-boolean-comparison

πŸ“ Disallow unnecessary comparisons against boolean literals.

πŸ’ΌπŸš« This rule is enabled in the βœ… recommended config. This rule is disabled in the β˜‘οΈ unopinionated config.

πŸ”§ This rule is automatically fixable by the --fix CLI option.

Comparing a value that is already known to be boolean against true or false adds noise without changing the result.

This rule only reports comparisons where the non-literal side is known to be boolean. It intentionally does not report unknown values like value === true, because strict identity comparison against true is not equivalent to a truthiness check.

Examples

// ❌
if ((a > b) === true) {}

// βœ…
if (a > b) {}
// ❌
if ((a > b) === false) {}

// βœ…
if (!(a > b)) {}
// ❌
const active = Boolean(value) !== false;

// βœ…
const active = Boolean(value);
// βœ…
if (value === true) {}