SonarSource/sonar-dotnet

Fix S1871 FN: Nested `if .. else if` chain

Opened this issue · 0 comments

if (s == 0)
{
    DoSomething1();
}
else
{
    if (s > 0 && s < 11)
    { // FN
        DoSomething1();
    }
    else
    {
        if (s > 11 && s < 20)
        { // FN
            DoSomething1();
        }
        else
        {
            DoSomething2();
        }
    }
}

Is semantically the same as:

if (s == 0)
{
    DoSomething1();
}
else if (s > 0 && s < 11)
{ // Noncompliant
    DoSomething1();
}
else if (s > 11 && s < 20)
{ // Noncompliant
    DoSomething1();
}
else
{
    DoSomething2();
}