Skip to content

Extra newline in switch case statement with curly braces #1192

@emberTrev

Description

@emberTrev

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions