From 3b2ad3fb43e0c91a87ec982e9936f845c99ece7a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 19:01:25 +0000 Subject: [PATCH 1/3] Initial plan From 699fa96dff0ed7f27be73a6edddb42649543a3b7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 19:07:59 +0000 Subject: [PATCH 2/3] Add support for multiline pattern-matching expressions in MA0007 Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com> --- src/Meziantou.Analyzer/Rules/CommaAnalyzer.cs | 10 +++ .../Rules/CommaAnalyzerTests.cs | 82 +++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/src/Meziantou.Analyzer/Rules/CommaAnalyzer.cs b/src/Meziantou.Analyzer/Rules/CommaAnalyzer.cs index ab43cfe8..bee14b60 100644 --- a/src/Meziantou.Analyzer/Rules/CommaAnalyzer.cs +++ b/src/Meziantou.Analyzer/Rules/CommaAnalyzer.cs @@ -36,6 +36,7 @@ public override void Initialize(AnalysisContext context) context.RegisterSyntaxNodeAction(HandleEnumDeclaration, SyntaxKind.EnumDeclaration); context.RegisterSyntaxNodeAction(HandleWithExpression, SyntaxKind.WithExpression); context.RegisterSyntaxNodeAction(HandleSwitchExpression, SyntaxKind.SwitchExpression); + context.RegisterSyntaxNodeAction(HandleRecursivePattern, SyntaxKind.RecursivePattern); #if CSHARP12_OR_GREATER context.RegisterSyntaxNodeAction(HandleCollectionExpression, SyntaxKind.CollectionExpression); #endif @@ -101,4 +102,13 @@ private static void HandleAnonymousObjectInitializer(SyntaxNodeAnalysisContext c var node = (AnonymousObjectCreationExpressionSyntax)context.Node; HandleSeparatedList(context, node, node.Initializers); } + + private static void HandleRecursivePattern(SyntaxNodeAnalysisContext context) + { + var node = (RecursivePatternSyntax)context.Node; + if (node.PropertyPatternClause is null) + return; + + HandleSeparatedList(context, node, node.PropertyPatternClause.Subpatterns); + } } diff --git a/tests/Meziantou.Analyzer.Test/Rules/CommaAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/CommaAnalyzerTests.cs index 72d6227e..ab8956bd 100644 --- a/tests/Meziantou.Analyzer.Test/Rules/CommaAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/CommaAnalyzerTests.cs @@ -421,4 +421,86 @@ public Task WithExpressionWithoutLeadingCommaSingleLine() record Sample(int A, int B); """) .ValidateAsync(); + + [Fact] + public Task PropertyPatternWithoutLeadingComma() + => CreateProjectBuilder() + .WithLanguageVersion(Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp8) + .WithSourceCode(""" + class TypeName + { + public int A { get; set; } + public int B { get; set; } + + public void Test() + { + var obj = new TypeName(); + _ = obj is + { + A: 1, + [||]B: 2 + }; + } + } + """) + .ShouldFixCodeWith(""" + class TypeName + { + public int A { get; set; } + public int B { get; set; } + + public void Test() + { + var obj = new TypeName(); + _ = obj is + { + A: 1, + B: 2, + }; + } + } + """) + .ValidateAsync(); + + [Fact] + public Task PropertyPatternWithLeadingComma() + => CreateProjectBuilder() + .WithLanguageVersion(Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp8) + .WithSourceCode(""" + class TypeName + { + public int A { get; set; } + public int B { get; set; } + + public void Test() + { + var obj = new TypeName(); + _ = obj is + { + A: 1, + B: 2, + }; + } + } + """) + .ValidateAsync(); + + [Fact] + public Task PropertyPatternSingleLine() + => CreateProjectBuilder() + .WithLanguageVersion(Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp8) + .WithSourceCode(""" + class TypeName + { + public int A { get; set; } + public int B { get; set; } + + public void Test() + { + var obj = new TypeName(); + _ = obj is { A: 1, B: 2 }; + } + } + """) + .ValidateAsync(); } From d719c213b6b4f88329ce255a3e66b96561edf4a3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 19:09:21 +0000 Subject: [PATCH 3/3] Fix test naming: use TrailingComma instead of LeadingComma Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com> --- tests/Meziantou.Analyzer.Test/Rules/CommaAnalyzerTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Meziantou.Analyzer.Test/Rules/CommaAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/CommaAnalyzerTests.cs index ab8956bd..35686446 100644 --- a/tests/Meziantou.Analyzer.Test/Rules/CommaAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/CommaAnalyzerTests.cs @@ -423,7 +423,7 @@ record Sample(int A, int B); .ValidateAsync(); [Fact] - public Task PropertyPatternWithoutLeadingComma() + public Task PropertyPatternWithoutTrailingComma() => CreateProjectBuilder() .WithLanguageVersion(Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp8) .WithSourceCode(""" @@ -463,7 +463,7 @@ public void Test() .ValidateAsync(); [Fact] - public Task PropertyPatternWithLeadingComma() + public Task PropertyPatternWithTrailingComma() => CreateProjectBuilder() .WithLanguageVersion(Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp8) .WithSourceCode("""