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.
It means 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. The shape appears through copy-paste, and nothing about it is a type error, so it survives review easily.
See also: Dart: branches
void showDashboard() {}
void render({required bool isAdmin}) { if (isAdmin) { showDashboard(); } else { showDashboard(); }}A conditional expression is checked the same way:
String label({required bool isActive}) => isActive ? 'on' : 'on';Make the branches differ:
void showDashboard() {}void showHome() {}
void render({required bool isAdmin}) { if (isAdmin) { showDashboard(); } else { showHome(); }}Or drop the condition, if it really decided nothing:
void showDashboard() {}
void render() { 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.
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.