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

Extra newline in switch case statement with curly braces #1192

Closed
emberTrev opened this issue Mar 5, 2024 · 1 comment · Fixed by #1202
Closed

Extra newline in switch case statement with curly braces #1192

emberTrev opened this issue Mar 5, 2024 · 1 comment · Fixed by #1202
Labels
area:formatting type:bug Something isn't working
Milestone

Comments

@emberTrev
Copy link

Input:

switch (foo)
{
	case 0:
		{
			// do stuff here
		}
		break;
	case 1:
		{
			// do stuff here
		}
		break;
}

Output:

switch (foo)
{
	case 0:

		{
			// do stuff here
		}
		break;
	case 1:

		{
			// do stuff here
		}
		break;
}

Expected behavior:

There shouldn't be an empty line added between the case statement and the opening curly brace.

For the record, I am not a fan of these curly braces, but you need to create a new scope if you want to declare the same variable name in multiple cases of the switch (CS0128). My coworkers always put the break outside the ending curly brace, which causes CSharpier to add a newline before the opening curly brace. There is a workaround by moving the break inside the closing curly brace, which I have been doing when I can. Doesn't change that the extra newline shouldn't be there in this case.

@belav belav added this to the 0.28.0 milestone Mar 8, 2024
@belav belav added type:bug Something isn't working area:formatting labels Mar 8, 2024
belav added a commit that referenced this issue Mar 9, 2024
closes #1192
@belav
Copy link
Owner

belav commented Mar 9, 2024

This is what I ended up doing

switch (someValue)
{
    case 0:
    {
        // dedented because the only statement is a block
        break;
    }

    case 1:
        {
            // indented because there are two statements, a block then a break
        }
        break;
}

It looks a bit weird with the break; dedented

switch (someValue)
{
    case 0:
    {
        // some comment
    }
    break;
    case 1:
    {
        // some comment
    }
    break;
}

And also with the block and break; at different indents.

switch (someValue)
{
    case 0:
    {
        // some comment
    }
        break;
    case 1:
    {
        // some comment
    }
        break;
}

shocklateboy92 added a commit that referenced this issue Mar 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
closes #1192

Co-authored-by: Lasath Fernando <devel@lasath.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:formatting type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants