Skip to content

Commit ff19b90

Browse files
committed
Update SA1118 to support multiline array creation (fix #2916)
1 parent 7820a76 commit ff19b90

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1118UnitTests.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace StyleCop.Analyzers.Test.ReadabilityRules
55
{
6+
using System.Collections.Generic;
67
using System.Threading;
78
using System.Threading.Tasks;
89
using Microsoft.CodeAnalysis.Testing;
@@ -12,6 +13,26 @@ namespace StyleCop.Analyzers.Test.ReadabilityRules
1213

1314
public class SA1118UnitTests
1415
{
16+
public static IEnumerable<object[]> ArrayCreationExpressions { get; } = new List<object[]>
17+
{
18+
new object[]
19+
{
20+
@"new[]
21+
{
22+
0,
23+
1
24+
}",
25+
},
26+
new object[]
27+
{
28+
@"new int[]
29+
{
30+
0,
31+
1
32+
}",
33+
},
34+
};
35+
1536
[Fact]
1637
public async Task TestMethodCallWithTwoParametersSecondSpansMoreThanOneLineAsync()
1738
{
@@ -363,5 +384,27 @@ public class Foo
363384

364385
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
365386
}
387+
388+
[Theory]
389+
[MemberData(nameof(ArrayCreationExpressions))]
390+
public async Task TestArrayCreationSpansMultipleLinesAsync(string arrayCreationExpression)
391+
{
392+
var testCode = $@"
393+
class Foo
394+
{{
395+
public void Fun(int i, int[] j)
396+
{{
397+
}}
398+
399+
public void Bar()
400+
{{
401+
Fun(
402+
1,
403+
{arrayCreationExpression});
404+
}}
405+
}}";
406+
407+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
408+
}
366409
}
367410
}

StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1118ParameterMustNotSpanMultipleLines.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ internal class SA1118ParameterMustNotSpanMultipleLines : DiagnosticAnalyzer
8080
SyntaxKind.InvocationExpression,
8181
SyntaxKind.ObjectCreationExpression,
8282
SyntaxKind.AnonymousObjectCreationExpression,
83+
SyntaxKind.ArrayCreationExpression,
84+
SyntaxKind.ImplicitArrayCreationExpression,
8385
};
8486

8587
/// <inheritdoc/>

0 commit comments

Comments
 (0)