From 1cbc9bd1ac27a626ee14a56d6aa06f03e440645f Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Fri, 24 Jun 2022 21:27:41 +0200 Subject: [PATCH 1/3] Add nested diagnostics test --- .../SA1413CSharp9UnitTests.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/MaintainabilityRules/SA1413CSharp9UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/MaintainabilityRules/SA1413CSharp9UnitTests.cs index d85368205..1dbee3155 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/MaintainabilityRules/SA1413CSharp9UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/MaintainabilityRules/SA1413CSharp9UnitTests.cs @@ -61,6 +61,50 @@ void M() } } } +"; + + await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false); + } + + [Fact] + [WorkItem(3240, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3240")] + public async Task VerifyWithInitializerNestedDiagnosticsAsync() + { + var testCode = @"public record R1(int X, R2 r2); +public record R2(int Y); + +public class C +{ + public void M(R1 r1, R2 r2) + { + _ = r1 with + { + X = 0, + r2 = [|r2 with + { + [|Y = 0|] + }|] + }; + } +} +"; + var fixedCode = @"public record R1(int X, R2 r2); +public record R2(int Y); + +public class C +{ + public void M(R1 r1, R2 r2) + { + _ = r1 with + { + X = 0, + r2 = r2 with + { + Y = 0, + }, + }; + } +} "; await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false); From 8b4355c1fe64db5fc46c2f07df6aeb63f3bbc188 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Fri, 24 Jun 2022 22:10:22 +0200 Subject: [PATCH 2/3] Update SA1413CSharp9UnitTests.cs --- .../MaintainabilityRules/SA1413CSharp9UnitTests.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/MaintainabilityRules/SA1413CSharp9UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/MaintainabilityRules/SA1413CSharp9UnitTests.cs index 1dbee3155..4ba94df6c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/MaintainabilityRules/SA1413CSharp9UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/MaintainabilityRules/SA1413CSharp9UnitTests.cs @@ -107,7 +107,12 @@ public void M(R1 r1, R2 r2) } "; - await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false); + await new CSharpTest() + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = testCode, + FixedCode = fixedCode, + }.RunAsync(CancellationToken.None).ConfigureAwait(false); } } } From 6041f7d32defd24062f5cceefa176210082f435d Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Fri, 24 Jun 2022 22:54:34 +0200 Subject: [PATCH 3/3] Update SA1413CSharp9UnitTests.cs --- .../MaintainabilityRules/SA1413CSharp9UnitTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/MaintainabilityRules/SA1413CSharp9UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/MaintainabilityRules/SA1413CSharp9UnitTests.cs index 4ba94df6c..b2fc77f4c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/MaintainabilityRules/SA1413CSharp9UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/MaintainabilityRules/SA1413CSharp9UnitTests.cs @@ -80,7 +80,7 @@ public void M(R1 r1, R2 r2) _ = r1 with { X = 0, - r2 = [|r2 with + [|r2 = r2 with { [|Y = 0|] }|]