Skip to content

Commit

Permalink
Remove empty lines at beginning of statements without braces
Browse files Browse the repository at this point in the history
closes #979
  • Loading branch information
belav committed Oct 30, 2023
1 parent 9182752 commit cf32265
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if (true)
CallMethod();
else if (false)
CallMethod();
else
CallMethod();

for (; ; )
CallMethod();

while (true)
CallMethod();
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if (true)

CallMethod();
else if (false)

CallMethod();
else

CallMethod();

for (; ; )

CallMethod();

while (true)

CallMethod();
6 changes: 3 additions & 3 deletions Src/CSharpier/DocTypes/DocUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ private static void RemoveInitialDoubleHardLine(IList<Doc> docs, ref bool remove

x++;
}

return;
}

public static void RemoveInitialDoubleHardLine(Doc doc)
public static Doc RemoveInitialDoubleHardLine(Doc doc)
{
var removeNextHardLine = false;
RemoveInitialDoubleHardLine(doc, ref removeNextHardLine);

return doc;
}

private static void RemoveInitialDoubleHardLine(Doc doc, ref bool removeNextHardLine)
Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier/SyntaxPrinter/OptionalBraces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public static Doc Print(StatementSyntax node, FormattingContext context)
{
return node is BlockSyntax blockSyntax
? Block.Print(blockSyntax, context)
: Doc.Indent(Doc.HardLine, Node.Print(node, context));
: DocUtilities.RemoveInitialDoubleHardLine(Doc.Indent(Doc.HardLine, Node.Print(node, context)));
}
}

0 comments on commit cf32265

Please sign in to comment.