Repeated If Conditions

ID

go.duplicate_else_if_conditions

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Go

Tags

dead-code, reliability, suspicious-comparison

Description

Reports if / else if / …​ chains in which two branches share the same condition. The second occurrence is unreachable — anything matching the duplicated condition fires the first branch — and is almost always a copy-paste error.

Rationale

A duplicate condition is dead code that masks a bug. The developer probably meant to change the operator or comparison value in one of the branches; tests rarely catch it because the data falls into the first branch as designed, so the defect stays latent until a refactor exposes it.

func classify(x int) string {
    if x == 1 {
        return "one"
    } else if x == 2 {
        return "two"
    } else if x == 1 { // FLAW — duplicate of the first condition, unreachable
        return "unreachable"
    }
    return "other"
}

Remediation

Fix the duplicated condition — the repeated branch was likely meant to test a different value — or remove it if it is genuinely redundant.