Skip to content

Commit 96b2835

Browse files
committed
Allow single-line ArrayCreationExpression syntax
Fixes #2607
1 parent 5156b7e commit 96b2835

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1500/SA1500UnitTests.ArrayInitializers.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public partial class SA1500UnitTests
2525
public async Task TestArrayInitializersValidAsync()
2626
{
2727
var testCode = @"
28+
using System;
29+
2830
public class TestClass
2931
{
3032
private int[] array1 = { };
@@ -33,6 +35,8 @@ public class TestClass
3335
3436
private int[] array3 = new[] { 0, 1 };
3537
38+
private int[] array3b = new int[] { 0, 1 };
39+
3640
private int[] array4 =
3741
{
3842
};
@@ -70,6 +74,10 @@ public void TestMethod()
7074
{
7175
0,
7276
};
77+
78+
Console.WriteLine(new[] { 0, 1 });
79+
Console.WriteLine(new int[] { 0, 1 });
80+
Console.WriteLine(new int[] { });
7381
}
7482
}";
7583

StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1500BracesForMultiLineStatementsMustNotShareLine.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ private static void CheckBraces(SyntaxNodeAnalysisContext context, SyntaxToken o
155155

156156
break;
157157

158+
case SyntaxKind.ArrayCreationExpression:
159+
if (GetStartLine(((ArrayCreationExpressionSyntax)context.Node.Parent).NewKeyword) == GetStartLine(openBraceToken))
160+
{
161+
return;
162+
}
163+
164+
break;
165+
158166
case SyntaxKind.ImplicitArrayCreationExpression:
159167
if (GetStartLine(((ImplicitArrayCreationExpressionSyntax)context.Node.Parent).NewKeyword) == GetStartLine(openBraceToken))
160168
{

0 commit comments

Comments
 (0)