Skip to content

Commit

Permalink
Format Implicit Array Initializer consistently
Browse files Browse the repository at this point in the history
closes #297
  • Loading branch information
belav committed Jun 14, 2021
1 parent 7ed2638 commit 156736e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Src/CSharpier.Playground/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ ILoggerFactory loggerFactory
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
app.UseHttpsRedirection();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class ClassName

int[,] array = new[,] { { 1, 2 }, { 3, 4 } };

private string[] SomeArray = new[] {
private string[] SomeArray = new[]
{
"SomeValue_____________________",
"SomeValue_____________________",
};
Expand All @@ -16,6 +17,13 @@ class ClassName

void MethodName()
{
var implicitArrayShouldBreak = new[]
{
"someLongValue",
"anotherLongValue",
"yetAnotherLongValue"
};

return TheArrayInHereShouldAlsoNotBreak(
SomeLongThing__________,
new[] { one, two, three, found }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public static Doc Print(ImplicitArrayCreationExpressionSyntax node)
Token.Print(node.NewKeyword),
Token.Print(node.OpenBracketToken),
Doc.Concat(commas),
Token.PrintWithSuffix(node.CloseBracketToken, " "),
Node.Print(node.Initializer)
Token.Print(node.CloseBracketToken),
Doc.Line,
InitializerExpression.Print(node.Initializer)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ or SyntaxKind.ObjectInitializerExpression
);
return node.Parent
is not (ObjectCreationExpressionSyntax
or ArrayCreationExpressionSyntax)
or ArrayCreationExpressionSyntax
or ImplicitArrayCreationExpressionSyntax)
&& node.Kind()
is not SyntaxKind.WithInitializerExpression ? Doc.Group(result) : result;
}
Expand Down

0 comments on commit 156736e

Please sign in to comment.