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.

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

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.

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.