dotnet / roslynator

Roslynator is a set of code analysis tools for C#, powered by Roslyn.

Home Page:https://josefpihrt.github.io/docs/roslynator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RCS1208 False-positive on flat if statement with multiple conditions

wiciok opened this issue · comments

Product and Version Used:
Roslynator.Analyzers 4.12.2

Steps to Reproduce:
Following code or similar one containing if statement with multiple conditions, but without any nesting:

private void Foo(string bar, int baz)
{
    if (bar == "bar" && baz == 123)  // RCS1208: Reduce 'if' nesting
    {
        var foo = "baz";
    }
}

Please note, that the issue doesn't occur, when there is some other code present after if statement in question:

private void Foo(string bar, int baz)
{
    if (bar == "bar" && baz == 123)
    {
        var foo = "baz";
    }
    var thisDoes = "something preventing RCS1208 in if statement above";
}

Actual Behavior:

RCS1208 is raised, suggesting rather counterproductive change to:

private void Foo(string bar, int baz)
{
    if (bar != "bar" || baz != 123)
    {
        return;
    }
    var foo = "baz";
}

Expected Behavior:
Do not raise RCS1208 in case of flat if statements with multiple conditions.