Skip to main content
ai-slop/csharp-if-laddermanual fix

If/else-if ladder.

Four or more chained `if`/`else if` branches comparing the same value with `==` against a constant. A `switch` written longhand.

Flagged shape and clean shape.

Each example shows the exact code shape the rule is looking for, then the smallest version that keeps the intent without hiding risk or adding noise.

csharp-if-ladder.cs
✗ Flagged
if (status == "pending")
    return Color.Gray;
else if (status == "active")
    return Color.Green;
else if (status == "suspended")
    return Color.Orange;
else if (status == "closed")
    return Color.Red;
return Color.Black;
Why this trips

Deterministic line match: tracks an `if (x == ...)` followed by `else if (x == ...)` branches on the same variable and flags the chain at four or more branches.

csharp-if-ladder.cs
✓ Clean
return status switch
{
    "pending" => Color.Gray,
    "active" => Color.Green,
    "suspended" => Color.Orange,
    "closed" => Color.Red,
    _ => Color.Black,
};
What changed

Use a `switch` statement or expression, or a dictionary of handlers when each branch maps a value to an action.

Each new case becomes one more `else if`. Agents extend the chain rather than restructure it, so it grows with every feature.

How this rule is justified.

Rule id

ai-slop/csharp-if-ladder

Enforcing engine

ai-slop

Detector strategy

Deterministic line match: tracks an `if (x == ...)` followed by `else if (x == ...)` branches on the same variable and flags the chain at four or more branches.

Legitimate code that is NOT flagged

Chains of three or fewer, chains that switch variable or use other operators, and existing `switch` statements are not flagged.

Evidence

Part of aislop's C# rule set. First-class C# support, including C#-specific AI-slop rules, arrived in aislop v0.14.1.