Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SA1623 and SA1624 to not trigger if the summary contains an inheritdoc element #3880

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,26 @@ public class TestClass
/// <summary/>
public int TestProperty { get; set; }
}
";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Theory]
[InlineData("<inheritdoc/>")]
[InlineData("XYZ <inheritdoc/>")]
[InlineData("<inheritdoc/> XYZ")]
[WorkItem(3465, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3465")]
public async Task VerifyInheritdocInSummaryTagIsAllowedAsync(string summary)
{
var testCode = $@"
public class TestClass
{{
/// <summary>
/// {summary}
/// </summary>
public int TestProperty {{ get; set; }}
}}
";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@ public class TestClass
/// <summary/>
public int TestProperty { get; set; }
}
";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Theory]
[InlineData("<inheritdoc/>")]
[InlineData("XYZ <inheritdoc/>")]
[InlineData("<inheritdoc/> XYZ")]
[WorkItem(3465, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3465")]
public async Task VerifyInheritdocInSummaryTagIsAllowedAsync(string summary)
{
var testCode = $@"
public class TestClass
{{
/// <summary>
/// {summary}
/// </summary>
public int TestProperty {{ get; private set; }}
}}
";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ internal class PropertySummaryDocumentationAnalyzer : PropertyDocumentationBase
/// <inheritdoc/>
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
{
if (!(syntax is XmlElementSyntax summaryElement))
{
// This is reported by SA1604 or SA1606.
return;
}

if (summaryElement.Content.GetFirstXmlElement(XmlCommentHelper.InheritdocXmlTag) != null)
{
// Ignore nodes with an <inheritdoc/> tag.
return;
}

var propertyDeclaration = (PropertyDeclarationSyntax)context.Node;
var propertyType = context.SemanticModel.GetTypeInfo(propertyDeclaration.Type.StripRefFromType());
var culture = settings.DocumentationRules.DocumentationCultureInfo;
Expand All @@ -70,7 +82,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
{
AnalyzeSummaryElement(
context,
syntax,
summaryElement,
diagnosticLocation,
propertyDeclaration,
resourceManager.GetString(nameof(DocumentationResources.StartingTextGetsWhether), culture),
Expand All @@ -82,7 +94,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
{
AnalyzeSummaryElement(
context,
syntax,
summaryElement,
diagnosticLocation,
propertyDeclaration,
resourceManager.GetString(nameof(DocumentationResources.StartingTextGets), culture),
Expand All @@ -92,7 +104,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}
}

private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, XmlNodeSyntax syntax, Location diagnosticLocation, PropertyDeclarationSyntax propertyDeclaration, string startingTextGets, string startingTextSets, string startingTextGetsOrSets, string startingTextReturns)
private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, XmlElementSyntax summaryElement, Location diagnosticLocation, PropertyDeclarationSyntax propertyDeclaration, string startingTextGets, string startingTextSets, string startingTextGetsOrSets, string startingTextReturns)
{
var diagnosticProperties = ImmutableDictionary.CreateBuilder<string, string>();
ArrowExpressionClauseSyntax expressionBody = propertyDeclaration.ExpressionBody;
Expand All @@ -116,12 +128,6 @@ private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, Xml
}
}

if (!(syntax is XmlElementSyntax summaryElement))
{
// This is reported by SA1604 or SA1606.
return;
}

// Add a no code fix tag when the summary element is empty.
// This will only impact SA1623, because SA1624 cannot trigger with an empty summary.
if (summaryElement.Content.Count == 0)
Expand Down