Skip to content

RCS1208 False-positive on flat if statement with multiple conditions #1454

@wiciok

Description

@wiciok

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions