no_equal_then_else
v1.0.0 Warning Control Flow
This rule flags an if/else or conditional expression whose branches are identical. If both branches do the same thing, the condition decides nothing.
Why use this rule
Section titled “Why use this rule”Two identical branches mean one of two things: a branch was meant to differ and does not — the usual case, and a real bug — or the branching is dead weight that should collapse to a single statement.
The shape appears through copy-paste: the second branch is duplicated from the first with the intent to edit it, and the edit never happens. Nothing about it is a type error, so it survives review easily.
See also: Dart: branches
if (isAdmin) { showDashboard();} else { showDashboard(); // the condition changes nothing}final label = isActive ? 'on' : 'on';Make the branches differ, or drop the condition:
showDashboard();Known limitations
Section titled “Known limitations”Branches are compared by source text, with a single-statement block reduced to that statement so { f(); } and f(); compare equal. Two branches that compute the same result by different code are not reported — that is beyond what a lint can judge.
An else if chain is skipped: comparing the first branch against a whole nested if says nothing useful. Two empty branches are skipped too, since that is usually code mid-way through being written.
Configuration
Section titled “Configuration”This rule is in the recommended preset, so it is on with
preset: recommended or preset: opinionated.
To turn it off:
rules: no_equal_then_else: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”no_equal_conditions— Flag an if/else-if chain that repeats a condition.no_equal_switch_case— Flag two switch branches with identical bodies.avoid_redundant_else— Drop the else when the if branch always exits.avoid_cascade_after_if_null— Detect cascades after if-null operators without parentheses.