Skip to content

Commit b1101fb

Browse files
authored
Keep discard with when on long arms (#1624)
closes #1620
1 parent 6b10381 commit b1101fb

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Src/CSharpier.Core/CSharp/SyntaxPrinter/SyntaxNodePrinters/WhenClause.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ public static Doc Print(WhenClauseSyntax node, PrintingContext context)
99
{
1010
return Doc.Group(
1111
Doc.Indent(
12-
Doc.Line,
12+
node.Parent is SwitchExpressionArmSyntax { Pattern: DiscardPatternSyntax }
13+
? " "
14+
: Doc.Line,
1315
Token.PrintWithSuffix(node.WhenKeyword, " ", context),
1416
Node.Print(node.Condition, context)
1517
)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ class ClassName
4141
),
4242
VeryLongObject_______________________________________________________________
4343
when count > 0 => CallSomeMethod(someValue),
44+
_ when KeepWhenWithDiscard() => "",
45+
_ when KeepWhenWithDiscard_________________(
46+
SomeObject_______________________________________________
47+
) => "",
48+
_ when KeepWhenWithDiscard_________________(
49+
SomeObject_______________________________________________
50+
) =>
51+
"LongString_____________________________________________________________________",
4452
OneMore => "someStrings"
4553
+ "moreStrings"
4654
+ "andMoreStrings_________________________________________",

0 commit comments

Comments
 (0)