Skip to content

Commit 0d7a541

Browse files
Updated SA1118 to allow multi-line constructor invocations.
1 parent 0298ccf commit 0d7a541

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,32 @@ public void Bar()
115115
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
116116
}
117117

118+
[Fact]
119+
public async Task TestMethodCallWithTwoParametersSecondSpansMultipleLinesButIsObjectCreationExpressionAsync()
120+
{
121+
var testCode = @"
122+
class Foo
123+
{
124+
Foo(int a, int b)
125+
{
126+
}
127+
128+
public void FunA(int i, Foo j)
129+
{
130+
}
131+
132+
public void FunB()
133+
{
134+
FunA(1,
135+
new Foo(
136+
2,
137+
3));
138+
}
139+
}";
140+
141+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
142+
}
143+
118144
[Fact]
119145
public async Task TestMethodCallWithTwoParametersFirstIsMultilineSecondIsOneLineAsync()
120146
{

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ internal class SA1118ParameterMustNotSpanMultipleLines : DiagnosticAnalyzer
7777
SyntaxKind.AnonymousMethodExpression,
7878
SyntaxKind.ParenthesizedLambdaExpression,
7979
SyntaxKind.SimpleLambdaExpression,
80-
SyntaxKind.InvocationExpression
80+
SyntaxKind.InvocationExpression,
81+
SyntaxKind.ObjectCreationExpression
8182
};
8283

8384
/// <inheritdoc/>

documentation/SA1118.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ cases:
3030
* The first parameter may span multiple lines
3131
* Anonymous methods (including lambda expressions) may span multiple lines
3232
* Invocation expressions may span multiple lines
33+
* Object creation expressions may span multiple lines
3334

3435
For example, the following code would violate this rule, since the second parameter spans across multiple lines:
3536

0 commit comments

Comments
 (0)