Skip to content

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.

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();

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.

This rule is in the recommended preset, so it is on with preset: recommended or preset: opinionated.

To turn it off:

many_lints.yaml
rules:
no_equal_then_else: false

To keep the rule on but skip certain paths, use per-rule exclude.