From 4f72d3a996b6bdf5b8dc7641a5719b1c672acbda Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Sun, 9 Aug 2026 17:15:44 +0200 Subject: [PATCH 1/4] fix: RCS1263 and RCS1139 for C# 14 extension block XmlDoc Fixes #1752 Handle ExtensionBlockDeclaration in CSharpUtility parameter and type-parameter resolution, and skip RCS1139 summary requirement on extension block documentation comments. Co-authored-by: Cursor --- CHANGELOG.md | 4 ++++ ...ngleLineDocumentationCommentTriviaAnalyzer.cs | 10 +++++++--- src/CSharp/CSharp/CSharpUtility.cs | 8 ++++++++ ...dSummaryElementToDocumentationCommentTests.cs | 16 ++++++++++++++++ ...nvalidReferenceInDocumentationCommentTests.cs | 16 ++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bde6f995fa..213fb3c022 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [CLI] Fix GitLab output format to use relative paths, forward slashes, and 1-based line numbers ([PR](https://github.com/dotnet/roslynator/pull/1792)) - [CLI] Fix `generate-doc` to omit internal interfaces from type declarations and the Implements section ([PR](https://github.com/dotnet/roslynator/pull/1801)) +### Fixed + +- Fix analyzers [RCS1263](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1263) and [RCS1139](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1139) for C# 14 extension block documentation + ## [4.16.0] - 2026-08-08 ### Added diff --git a/src/Analyzers/CSharp/Analysis/SingleLineDocumentationCommentTriviaAnalyzer.cs b/src/Analyzers/CSharp/Analysis/SingleLineDocumentationCommentTriviaAnalyzer.cs index f2272c54f5..c8aff5f8b3 100644 --- a/src/Analyzers/CSharp/Analysis/SingleLineDocumentationCommentTriviaAnalyzer.cs +++ b/src/Analyzers/CSharp/Analysis/SingleLineDocumentationCommentTriviaAnalyzer.cs @@ -185,14 +185,18 @@ private static void AnalyzeSingleLineDocumentationCommentTrivia(SyntaxNodeAnalys return; } + SyntaxNode parent = documentationComment.ParentTrivia.Token.Parent; + if (!containsSummaryElement - && !containsContentElement) + && !containsContentElement +#if ROSLYN_5_0 + && parent?.IsKind(SyntaxKind.ExtensionBlockDeclaration) != true +#endif + ) { ReportDiagnosticIfEffective(context, DiagnosticRules.AddSummaryElementToDocumentationComment, documentationComment); } - SyntaxNode parent = documentationComment.ParentTrivia.Token.Parent; - bool invalidReference = DiagnosticRules.InvalidReferenceInDocumentationComment.IsEffective(context); bool orderParams = DiagnosticRules.OrderElementsInDocumentationComment.IsEffective(context); bool addParam = DiagnosticRules.AddParamElementToDocumentationComment.IsEffective(context); diff --git a/src/CSharp/CSharp/CSharpUtility.cs b/src/CSharp/CSharp/CSharpUtility.cs index d6627c6381..64e3b265a2 100644 --- a/src/CSharp/CSharp/CSharpUtility.cs +++ b/src/CSharp/CSharp/CSharpUtility.cs @@ -688,6 +688,10 @@ public static SeparatedSyntaxList GetParameters(SyntaxNode decl case SyntaxKind.StructDeclaration: case SyntaxKind.InterfaceDeclaration: return ((TypeDeclarationSyntax)declaration).ParameterList; +#endif +#if ROSLYN_5_0 + case SyntaxKind.ExtensionBlockDeclaration: + return ((ExtensionBlockDeclarationSyntax)declaration).ParameterList; #endif default: return null; @@ -720,6 +724,10 @@ public static SeparatedSyntaxList GetTypeParameters(SyntaxN case SyntaxKind.RecordStructDeclaration: #endif return ((RecordDeclarationSyntax)declaration).TypeParameterList; +#if ROSLYN_5_0 + case SyntaxKind.ExtensionBlockDeclaration: + return ((ExtensionBlockDeclarationSyntax)declaration).TypeParameterList; +#endif default: return null; } diff --git a/src/Tests/Analyzers.Tests/RCS1139AddSummaryElementToDocumentationCommentTests.cs b/src/Tests/Analyzers.Tests/RCS1139AddSummaryElementToDocumentationCommentTests.cs index 4440d63aa0..c24c76bee2 100644 --- a/src/Tests/Analyzers.Tests/RCS1139AddSummaryElementToDocumentationCommentTests.cs +++ b/src/Tests/Analyzers.Tests/RCS1139AddSummaryElementToDocumentationCommentTests.cs @@ -50,4 +50,20 @@ partial class C } "); } + + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddSummaryElementToDocumentationComment)] + public async Task TestNoDiagnostic_ExtensionBlock_WithoutSummary() + { + await VerifyNoDiagnosticAsync(""" +static class C +{ + /// x + /// T + extension(T x) where T : struct + { + public int M() => 0; + } +} +"""); + } } diff --git a/src/Tests/Analyzers.Tests/RCS1263InvalidReferenceInDocumentationCommentTests.cs b/src/Tests/Analyzers.Tests/RCS1263InvalidReferenceInDocumentationCommentTests.cs index 8d980db15c..b7d8e24e61 100644 --- a/src/Tests/Analyzers.Tests/RCS1263InvalidReferenceInDocumentationCommentTests.cs +++ b/src/Tests/Analyzers.Tests/RCS1263InvalidReferenceInDocumentationCommentTests.cs @@ -205,6 +205,22 @@ public struct Foo(string value) { public string Value { get; } = value; } +"""); + } + + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.InvalidReferenceInDocumentationComment)] + public async Task TestNoDiagnostic_ExtensionBlock_ParamAndTypeParam() + { + await VerifyNoDiagnosticAsync(""" +static class C +{ + /// x + /// T + extension(T x) where T : struct + { + public int M() => 0; + } +} """); } } From 50e0989e2428afb42aec65ed4374fa65b79b2664 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Sun, 9 Aug 2026 17:15:57 +0200 Subject: [PATCH 2/4] chore: add PR link to changelog for #1752 fix Co-authored-by: Cursor --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 213fb3c022..6355ae21c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,7 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Fix analyzers [RCS1263](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1263) and [RCS1139](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1139) for C# 14 extension block documentation +- Fix analyzers [RCS1263](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1263) and [RCS1139](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1139) for C# 14 extension block documentation ([PR](https://github.com/dotnet/roslynator/pull/1799)) ## [4.16.0] - 2026-08-08 From 60453e7ac7c91a56187fe568719363c7b02cd5b4 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Fri, 14 Aug 2026 19:32:39 +0200 Subject: [PATCH 3/4] test(analyzers): report RCS1263 for invalid extension-block param refs Co-authored-by: Cursor --- ...lidReferenceInDocumentationCommentTests.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Tests/Analyzers.Tests/RCS1263InvalidReferenceInDocumentationCommentTests.cs b/src/Tests/Analyzers.Tests/RCS1263InvalidReferenceInDocumentationCommentTests.cs index b7d8e24e61..08046384f2 100644 --- a/src/Tests/Analyzers.Tests/RCS1263InvalidReferenceInDocumentationCommentTests.cs +++ b/src/Tests/Analyzers.Tests/RCS1263InvalidReferenceInDocumentationCommentTests.cs @@ -221,6 +221,31 @@ static class C public int M() => 0; } } +"""); + } + + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.InvalidReferenceInDocumentationComment)] + public async Task Test_ExtensionBlock_InvalidParamName() + { + await VerifyDiagnosticAndFixAsync(""" +static class C +{ + /// + /// T + extension(T x) where T : struct + { + public int M() => 0; + } +} +""", """ +static class C +{ + /// T + extension(T x) where T : struct + { + public int M() => 0; + } +} """); } } From 30c9b52c093af320af0861ed1a045e97784abce2 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Sun, 16 Aug 2026 15:54:25 +0200 Subject: [PATCH 4/4] chore: move #1799 changelog entry under Unreleased Co-authored-by: Cursor --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6355ae21c9..95e4c7f81c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Drop support for Visual Studio 2022 VSIX ([PR](https://github.com/dotnet/roslynator/pull/1787)) - Pin last 4.x release ([Roslynator 2022](https://marketplace.visualstudio.com/items?itemName=josefpihrt.Roslynator2022)) or use NuGet packages on Visual Studio 2022 +### Fixed + +- Fix analyzers [RCS1263](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1263) and [RCS1139](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1139) for C# 14 extension block documentation ([PR](https://github.com/dotnet/roslynator/pull/1799)) + ## [4.16.1] - 2026-08-16 ### Fixed @@ -48,10 +52,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [CLI] Fix GitLab output format to use relative paths, forward slashes, and 1-based line numbers ([PR](https://github.com/dotnet/roslynator/pull/1792)) - [CLI] Fix `generate-doc` to omit internal interfaces from type declarations and the Implements section ([PR](https://github.com/dotnet/roslynator/pull/1801)) -### Fixed - -- Fix analyzers [RCS1263](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1263) and [RCS1139](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1139) for C# 14 extension block documentation ([PR](https://github.com/dotnet/roslynator/pull/1799)) - ## [4.16.0] - 2026-08-08 ### Added