Skip to content

Commit

Permalink
Merge pull request #68 from belav/gh-61-trailing-bug
Browse files Browse the repository at this point in the history
closes #61 - fixes issue with trailing separators adding extra line
  • Loading branch information
shocklateboy92 committed Apr 4, 2021
2 parents 0e8885e + 9a3100b commit 81ebaba
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 51 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class ClassName
{
public ClassName Basic = new ClassName();

public ClassName WithInitializer = new ClassName { Property = true };

public ClassName WithBigInitializer = new ClassName
{
Property1 = true,
Property2 = false,
Property3 = false,
Property4 = false,
Property5 = false
};

public ClassName TrailingComma = new ClassName
{
Property1 = true,
Property2 = true,
};
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,7 @@ public void BasicObjectCreationExpression()
{
this.RunTest(
"ObjectCreationExpression",
"BasicObjectCreationExpression"
);
}
[Test]
public void ObjectCreationWithBiggerInitializer()
{
this.RunTest(
"ObjectCreationExpression",
"ObjectCreationWithBiggerInitializer"
);
}
[Test]
public void ObjectCreationWithInitializer()
{
this.RunTest(
"ObjectCreationExpression",
"ObjectCreationWithInitializer"
"ObjectCreationExpressions"
);
}
}
Expand Down
20 changes: 12 additions & 8 deletions Src/CSharpier/Printer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,20 @@ public static Doc Indent(params Doc[] contents)
for (var x = 0; x < list.Count; x++)
{
parts.Push(printFunc(list[x]));
// TODO 1 this keeps trailing commas, that should probably be an option, for let's keep what appears to make finding "bad" code formats easier
if (x < list.SeparatorCount)

if (x >= list.SeparatorCount)
{
parts.Push(
this.PrintSyntaxToken(
list.GetSeparator(x),
afterSeparator
)
);
continue;
}

var isTrailingSeparator = x == list.Count - 1;

parts.Push(
this.PrintSyntaxToken(
list.GetSeparator(x),
!isTrailingSeparator ? afterSeparator : null
)
);
}

return parts.Count == 0 ? Doc.Null : Concat(parts);
Expand Down
12 changes: 5 additions & 7 deletions Src/CSharpier/Printer/InitializerExpressionSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ public partial class Printer
: Line,
this.PrintSyntaxToken(node.OpenBraceToken),
Indent(
Concat(
Line,
this.PrintSeparatedSyntaxList(
node.Expressions,
this.Print,
Line
)
Line,
this.PrintSeparatedSyntaxList(
node.Expressions,
this.Print,
Line
)
),
Line,
Expand Down

0 comments on commit 81ebaba

Please sign in to comment.