sonar-dotnet icon indicating copy to clipboard operation
sonar-dotnet copied to clipboard

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

Open sebastien-marichal opened this issue 8 months ago • 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();
}

sebastien-marichal avatar Jun 14 '24 12:06 sebastien-marichal