Skip to content

Commit 8949282

Browse files
Fixing extra new line inside case (#1202)
closes #1192 Co-authored-by: Lasath Fernando <[email protected]>
1 parent 5e12370 commit 8949282

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Src/CSharpier.Tests/FormattingTests/TestFiles/cs/SwitchStatements.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,20 @@ public class ClassName
112112
case (_, SomeValue) when !isEquality:
113113
return;
114114
}
115+
116+
switch (someValue)
117+
{
118+
case 0:
119+
{
120+
// dedented because the only statement is a block
121+
break;
122+
}
123+
124+
case 1:
125+
{
126+
// indented because there are two statements, a block then a break
127+
}
128+
break;
129+
}
115130
}
116131
}

Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/SwitchSection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ public static Doc Print(SwitchSectionSyntax node, FormattingContext context)
88
{
99
Doc.Join(Doc.HardLine, node.Labels.Select(o => Node.Print(o, context)))
1010
};
11-
if (node.Statements.Count == 1 && node.Statements[0] is BlockSyntax blockSyntax)
11+
if (node.Statements is [BlockSyntax blockSyntax])
1212
{
1313
docs.Add(Block.Print(blockSyntax, context));
1414
}
1515
else
1616
{
1717
docs.Add(
1818
Doc.Indent(
19-
Doc.HardLine,
19+
node.Statements.First() is BlockSyntax ? Doc.Null : Doc.HardLine,
2020
Doc.Join(
2121
Doc.HardLine,
2222
node.Statements.Select(o => Node.Print(o, context)).ToArray()

0 commit comments

Comments
 (0)