OptimumCredo.Check.Readability.RedundantBooleanComparison (OptimumCredo v0.5.0)

View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of low and works with any version of Elixir.

Explanation

Comparing a boolean-valued expression with true or false is redundant: use the expression itself, or not / ! for the negation.

By default only provably boolean operands are reported (comparisons, not/!, Kernel guards and standard-library ? predicates). Set trust_question_mark: true to also accept project ?/is_* functions as boolean, or strict: true to report variables and arbitrary calls, which may be nil and therefore not equivalent. Opt-in, low priority.

Bad

if Enum.empty?(list) == true, do: :none

Good

if Enum.empty?(list), do: :none

Check-Specific Parameters

Use the following parameters to configure this check:

:trust_question_mark

Treat project ?-suffixed and is_* functions as boolean.

This parameter defaults to false.

:strict

Report comparisons for every operand, not only certainly-boolean ones.

This parameter defaults to false.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.