Skip to content

Commit 29514d2

Browse files
committed
Added changes to allow the <para> tag in <summary>. Added Unit test for SA1642
1 parent 51c772e commit 29514d2

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1642UnitTests.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,57 @@ public ClassName()
10611061
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
10621062
}
10631063

1064+
[Fact]
1065+
[WorkItem(3575, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3575")]
1066+
public async Task TestConstructorSummaryWithParaTagsAsync()
1067+
{
1068+
var testCode = @"
1069+
using System;
1070+
/// <summary>
1071+
/// Does a thing.
1072+
/// </summary>
1073+
public class B
1074+
{
1075+
/// <summary>
1076+
/// <para>
1077+
/// Initializes a new instance of the <see cref=""B""/> class.
1078+
/// </para>
1079+
/// <para>
1080+
/// Some more info about B.
1081+
/// </para>
1082+
/// </summary>
1083+
public B()
1084+
{
1085+
}
1086+
}
1087+
";
1088+
1089+
var fixedCode = @"
1090+
using System;
1091+
/// <summary>
1092+
/// Does a thing.
1093+
/// </summary>
1094+
public class B
1095+
{
1096+
/// <summary>
1097+
/// <para>
1098+
/// Initializes a new instance of the <see cref=""B""/> class.
1099+
/// </para>
1100+
/// <para>
1101+
/// Some more info about B.
1102+
/// </para>
1103+
/// </summary>
1104+
public B()
1105+
{
1106+
}
1107+
}
1108+
";
1109+
1110+
var expectedDiagnostics = DiagnosticResult.EmptyDiagnosticResults;
1111+
1112+
await VerifyCSharpFixAsync(testCode, expectedDiagnostics, fixedCode, CancellationToken.None).ConfigureAwait(false);
1113+
}
1114+
10641115
private static async Task TestEmptyConstructorAsync(string typeKind, string modifiers)
10651116
{
10661117
var testCode = @"namespace FooNamespace

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/StandardTextDiagnosticBase.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@ protected static MatchResult HandleDeclaration(SyntaxNodeAnalysisContext context
122122
diagnosticLocation = summaryElement.GetLocation();
123123
diagnosticProperties = ImmutableDictionary.Create<string, string>();
124124

125+
// Handle empty or whitespace-only summary content
126+
var firstElementWithContent = XmlCommentHelper.TryGetFirstTextElementWithContent(summaryElement);
127+
if (firstElementWithContent == null)
128+
{
129+
// Report the diagnostic for empty or whitespace-only summaries
130+
if (diagnosticDescriptor != null)
131+
{
132+
context.ReportDiagnostic(Diagnostic.Create(diagnosticDescriptor, diagnosticLocation, diagnosticProperties));
133+
}
134+
135+
return MatchResult.None;
136+
}
137+
138+
// Check if the summary content starts with a <para> tag
139+
if (firstElementWithContent != null && firstElementWithContent.Parent is XmlElementSyntax firstElement && firstElement.StartTag.Name.ToString() == "para")
140+
{
141+
// We found a correct standard text
142+
return MatchResult.FoundMatch;
143+
}
144+
125145
// Check if the summary content could be a correct standard text
126146
if (summaryElement.Content.Count >= 3)
127147
{

0 commit comments

Comments
 (0)