Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wiciok opened this issue Apr 26, 2024 · 1 comment · May be fixed by #1462
Open

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

wiciok opened this issue Apr 26, 2024 · 1 comment · May be fixed by #1462

Comments

@wiciok
Copy link

wiciok commented Apr 26, 2024

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.

@AdrianoAE
Copy link

Also facing false positive, this triggers the analyzer:

if (last.End > time)
{
    return last;
}

return null;

but if the if is inverted:

if (last.End <= time)
{
    return null;
}

return last;

then it's fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants