Skip to content

Commit

Permalink
Added changes to allow the <para> tag in <summary>. Added Unit test f…
Browse files Browse the repository at this point in the history
…or SA1642
  • Loading branch information
MattFromRVA committed Jun 18, 2024
1 parent 51c772e commit 29514d2
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,57 @@ public ClassName()
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(3575, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3575")]
public async Task TestConstructorSummaryWithParaTagsAsync()
{
var testCode = @"
using System;
/// <summary>
/// Does a thing.
/// </summary>
public class B
{
/// <summary>
/// <para>
/// Initializes a new instance of the <see cref=""B""/> class.
/// </para>
/// <para>
/// Some more info about B.
/// </para>
/// </summary>
public B()
{
}
}
";

var fixedCode = @"
using System;
/// <summary>
/// Does a thing.
/// </summary>
public class B
{
/// <summary>
/// <para>
/// Initializes a new instance of the <see cref=""B""/> class.
/// </para>
/// <para>
/// Some more info about B.
/// </para>
/// </summary>
public B()
{
}
}
";

var expectedDiagnostics = DiagnosticResult.EmptyDiagnosticResults;

await VerifyCSharpFixAsync(testCode, expectedDiagnostics, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

private static async Task TestEmptyConstructorAsync(string typeKind, string modifiers)
{
var testCode = @"namespace FooNamespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ protected static MatchResult HandleDeclaration(SyntaxNodeAnalysisContext context
diagnosticLocation = summaryElement.GetLocation();
diagnosticProperties = ImmutableDictionary.Create<string, string>();

// Handle empty or whitespace-only summary content
var firstElementWithContent = XmlCommentHelper.TryGetFirstTextElementWithContent(summaryElement);
if (firstElementWithContent == null)
{
// Report the diagnostic for empty or whitespace-only summaries
if (diagnosticDescriptor != null)
{
context.ReportDiagnostic(Diagnostic.Create(diagnosticDescriptor, diagnosticLocation, diagnosticProperties));
}

return MatchResult.None;
}

// Check if the summary content starts with a <para> tag
if (firstElementWithContent != null && firstElementWithContent.Parent is XmlElementSyntax firstElement && firstElement.StartTag.Name.ToString() == "para")
{
// We found a correct standard text
return MatchResult.FoundMatch;
}

// Check if the summary content could be a correct standard text
if (summaryElement.Content.Count >= 3)
{
Expand Down

0 comments on commit 29514d2

Please sign in to comment.