From 79c69595f670416320a7255df8e0797eefa0aeaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Hellander?= Date: Fri, 18 Nov 2022 05:28:13 +0100 Subject: [PATCH] Update SA1008 to handle positional patterns inside property patterns #3556 --- .../SpacingRules/SA1008CSharp8UnitTests.cs | 45 +++++++++++++++++++ ...OpeningParenthesisMustBeSpacedCorrectly.cs | 3 +- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1008CSharp8UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1008CSharp8UnitTests.cs index 0b86d258b..aaa149590 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1008CSharp8UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1008CSharp8UnitTests.cs @@ -149,5 +149,50 @@ await VerifyCSharpFixAsync( fixedCode, CancellationToken.None).ConfigureAwait(false); } + + [Fact] + [WorkItem(3556, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3556")] + public async Task TestInPositionalPatternAfterTagAsync() + { + var testCode = @" +internal class TestClass + { + private void TestMethod(object obj) + { + _ = obj is ClassWithTuple { Tag:{|#0:(|} true, false) }; + } + + public class ClassWithTuple + { + public (bool Item1, bool Item2) Tag { get; set; } + } + } +"; + var fixedCode = @" +internal class TestClass + { + private void TestMethod(object obj) + { + _ = obj is ClassWithTuple { Tag: (true, false) }; + } + + public class ClassWithTuple + { + public (bool Item1, bool Item2) Tag { get; set; } + } + } +"; + DiagnosticResult[] expectedResults = + { + Diagnostic(DescriptorPreceded).WithLocation(0), + Diagnostic(DescriptorNotFollowed).WithLocation(0), + }; + + await VerifyCSharpFixAsync( + testCode, + expectedResults, + fixedCode, + CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1008OpeningParenthesisMustBeSpacedCorrectly.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1008OpeningParenthesisMustBeSpacedCorrectly.cs index d83d7a847..7db4a4fdf 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1008OpeningParenthesisMustBeSpacedCorrectly.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1008OpeningParenthesisMustBeSpacedCorrectly.cs @@ -191,7 +191,8 @@ private static void HandleOpenParenToken(SyntaxTreeAnalysisContext context, Synt || prevToken.IsKind(SyntaxKindEx.OrKeyword) || prevToken.IsKind(SyntaxKindEx.AndKeyword) || prevToken.IsKind(SyntaxKindEx.NotKeyword) - || prevToken.IsKind(SyntaxKind.CommaToken); + || prevToken.IsKind(SyntaxKind.CommaToken) + || prevToken.IsKind(SyntaxKind.ColonToken); break; case SyntaxKindEx.ParenthesizedPattern: