From 16f768e7b2b3912ced6f59607fb8c83458d3a9b2 Mon Sep 17 00:00:00 2001 From: Bela VanderVoort Date: Tue, 21 Dec 2021 11:23:46 -0600 Subject: [PATCH] Cleaning up formatting of fors with empty statements (#528) closes #523 --- .../FormattingTests/TestFiles/ForStatements.cst | 17 ++++++++++++++++- .../SyntaxNodePrinters/ForStatement.cs | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/ForStatements.cst b/Src/CSharpier.Tests/FormattingTests/TestFiles/ForStatements.cst index 709d5715d..ca1319ec8 100644 --- a/Src/CSharpier.Tests/FormattingTests/TestFiles/ForStatements.cst +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/ForStatements.cst @@ -13,7 +13,22 @@ class ClassName break; } - for (;;) + for (; ; ) + { + break; + } + + for (var x = 1; ; ) + { + break; + } + + for (var x = 1; x < 0; ) + { + break; + } + + for (var x = 1; ; x++) { break; } diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ForStatement.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ForStatement.cs index 4377f16f5..4242d6820 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ForStatement.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ForStatement.cs @@ -23,9 +23,9 @@ public static Doc Print(ForStatementSyntax node) ), node.Condition != null ? Doc.Concat(Doc.Line, Node.Print(node.Condition)) - : Doc.SoftLine, + : Doc.Line, Token.Print(node.SecondSemicolonToken), - node.Incrementors.Any() ? Doc.Line : Doc.SoftLine, + Doc.Line, Doc.Group( Doc.Indent( SeparatedSyntaxList.Print(node.Incrementors, Node.Print, Doc.Line)