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

RCS1111 should trigger when case returns directly or throws an exception #1440

Open
daze99 opened this issue Apr 12, 2024 · 2 comments
Open

Comments

@daze99
Copy link

daze99 commented Apr 12, 2024

Product and Version Used: Roslynator 4.12

Steps to Reproduce:

private string Test(int i)
{
    var result = string.Empty;

    switch (i)
    {
        case 0:
            result = i.ToString();
            break;

        case 1:
            var s = i.ToString();
            return s;

        case 2:
            return i.ToString();

        default:
            throw new Exception();
    }

    return result;
}

Actual Behavior:

private string Test(int i)
{
    var result = string.Empty;

    switch (i)
    {
        case 0:
        {
            result = i.ToString();
            break;
        }

        case 1:
        {
            var s = i.ToString();
            return s;
        }

        case 2:
            return i.ToString();

        default:
            throw new Exception();
    }

    return result;
}

Expected Behavior:

private string Test(int i)
{
    var result = string.Empty;

    switch (i)
    {
        case 0:
        {
            result = i.ToString();
            break;
        }

        case 1:
        {
            var s = i.ToString();
            return s;
        }

        case 2:
        {
            return i.ToString();
        }

        default:
        {
            throw new Exception();
        }
    }

    return result;
}
@josefpihrt
Copy link
Collaborator

RCS1111 is called "Add braces to switch section with multiple statements". Why do you think is should trigger when there is a single statement?

@daze99
Copy link
Author

daze99 commented Apr 24, 2024

Yes, you are right. The title says is all.

Anyway it would be nice to have another analyzer "Add braces to switch section" like it exists for if statements (IDE0011).

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

No branches or pull requests

2 participants