prefer_returning_condition
v1.0.0 Warning Control Flow
This rule flags an if that returns true with a following return false (or the reverse).
Why use this rule
Section titled “Why use this rule”if (x > 0) return true; return false; is the condition itself, spelled out in three lines. return x > 0; says it once, and the reader does not have to check that the two branches really are opposites — which is exactly the check that gets skipped when one of them is later edited.
Both branches returning the same literal is a different mistake, reported by function_always_returns_same_value. A pattern case (if (x case ...)) is skipped, since it binds variables the returned expression may use.
bool isEligible(Player player) { if (player.rating > 1200) { return true; } return false;}bool isEligible(Player player) => player.rating > 1200;Turning this rule off
Section titled “Turning this rule off”This rule is in the opinionated preset.
To disable this rule:
rules: prefer_returning_condition: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”avoid_inverted_boolean_checks— Use the opposite operator instead of negating a comparison.avoid_negated_conditions— State the positive case first in an if/else.avoid_unnecessary_negations— Collapse double negations.avoid_unmodified_loop_condition— A while loop whose condition the body can never change.