Skip to content

Commit

Permalink
Fixing extra new line inside case (#1202)
Browse files Browse the repository at this point in the history
closes #1192

Co-authored-by: Lasath Fernando <[email protected]>
  • Loading branch information
belav and shocklateboy92 authored Mar 11, 2024
1 parent 5e12370 commit 8949282
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,20 @@ public class ClassName
case (_, SomeValue) when !isEquality:
return;
}

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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ public static Doc Print(SwitchSectionSyntax node, FormattingContext context)
{
Doc.Join(Doc.HardLine, node.Labels.Select(o => Node.Print(o, context)))
};
if (node.Statements.Count == 1 && node.Statements[0] is BlockSyntax blockSyntax)
if (node.Statements is [BlockSyntax blockSyntax])
{
docs.Add(Block.Print(blockSyntax, context));
}
else
{
docs.Add(
Doc.Indent(
Doc.HardLine,
node.Statements.First() is BlockSyntax ? Doc.Null : Doc.HardLine,
Doc.Join(
Doc.HardLine,
node.Statements.Select(o => Node.Print(o, context)).ToArray()
Expand Down

0 comments on commit 8949282

Please sign in to comment.