Skip to content

Commit 56c677b

Browse files
authored
Merge pull request #3340 from BlythMeister/SA1118-new
Handle new() syntax on SA1118
2 parents 4d9b3e3 + 27e6bf8 commit 56c677b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/ReadabilityRules/SA1118CSharp9UnitTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,37 @@ r with
7575
TestCode = testCode,
7676
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
7777
}
78+
79+
[Fact]
80+
[WorkItem(3339, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3339")]
81+
public async Task TestNewExpressionAsync()
82+
{
83+
var testCode = @"
84+
public class MyClass
85+
{
86+
public class MyObject
87+
{
88+
public string MyValue { get; init; }
89+
}
90+
91+
public void MyTestFunction()
92+
{
93+
MyCallingFunction(0, new()
94+
{
95+
MyValue = ""Test""
96+
});
97+
}
98+
99+
public void MyCallingFunction(int index, MyObject myObject)
100+
{
101+
}
102+
}";
103+
104+
await new CSharpTest(LanguageVersion.CSharp9)
105+
{
106+
ReferenceAssemblies = ReferenceAssemblies.Net.Net50,
107+
TestCode = testCode,
108+
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
109+
}
78110
}
79111
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ internal class SA1118ParameterMustNotSpanMultipleLines : DiagnosticAnalyzer
8484
SyntaxKind.ArrayCreationExpression,
8585
SyntaxKind.ImplicitArrayCreationExpression,
8686
SyntaxKindEx.WithExpression,
87+
SyntaxKindEx.ImplicitObjectCreationExpression,
8788
};
8889

8990
/// <inheritdoc/>

0 commit comments

Comments
 (0)