Skip to content

Commit bfc1935

Browse files
committed
Remove inheritdoc analysis from SA1606
Fixes #1944
1 parent e60c596 commit bfc1935

4 files changed

Lines changed: 38 additions & 15 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1606UnitTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,27 @@ public void MethodName()
745745
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
746746
}
747747

748+
[Fact(DisplayName = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1944")]
749+
public async Task TestOverriddenInheritDocAsync()
750+
{
751+
var testCode = @"
752+
/// <summary>
753+
/// Foo
754+
/// </summary>
755+
public class ClassName
756+
{
757+
/// <summary>
758+
///
759+
/// </summary>
760+
/// <inheritdoc/>
761+
public string Property => ""P"";
762+
}";
763+
764+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(11, 19);
765+
766+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
767+
}
768+
748769
/// <inheritdoc/>
749770
protected override Project CreateProject(string[] sources, string language = "C#", string[] filenames = null)
750771
{

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/ElementDocumentationSummaryBase.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ public override void Initialize(AnalysisContext context)
5959
/// Analyzes the top-level <c>&lt;summary&gt;</c> element of a documentation comment.
6060
/// </summary>
6161
/// <param name="context">The current analysis context.</param>
62+
/// <param name="documentation">The documentation syntax associated with the element.</param>
6263
/// <param name="syntax">The <see cref="XmlElementSyntax"/> or <see cref="XmlEmptyElementSyntax"/> of the node
6364
/// to examine.</param>
6465
/// <param name="completeDocumentation">The complete documentation for the declared symbol, with any
6566
/// <c>&lt;include&gt;</c> elements expanded. If the XML documentation comment included a <c>&lt;summary&gt;</c>
6667
/// element, this value will be <see langword="null"/>, even if the XML documentation comment also included an
6768
/// <c>&lt;include&gt;</c> element.</param>
6869
/// <param name="diagnosticLocations">The location(s) where diagnostics, if any, should be reported.</param>
69-
protected abstract void HandleXmlElement(SyntaxNodeAnalysisContext context, XmlNodeSyntax syntax, XElement completeDocumentation, params Location[] diagnosticLocations);
70+
protected abstract void HandleXmlElement(SyntaxNodeAnalysisContext context, DocumentationCommentTriviaSyntax documentation, XmlNodeSyntax syntax, XElement completeDocumentation, params Location[] diagnosticLocations);
7071

7172
private void HandleCompilationStart(CompilationStartAnalysisContext context)
7273
{
@@ -219,12 +220,6 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, SyntaxNode nod
219220
return;
220221
}
221222

222-
if (documentation.Content.GetFirstXmlElement(XmlCommentHelper.InheritdocXmlTag) != null)
223-
{
224-
// Ignore nodes with an <inheritdoc/> tag.
225-
return;
226-
}
227-
228223
XElement completeDocumentation = null;
229224
var relevantXmlElement = documentation.Content.GetFirstXmlElement(XmlCommentHelper.SummaryXmlTag);
230225
if (relevantXmlElement == null)
@@ -235,15 +230,10 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, SyntaxNode nod
235230
var declaration = context.SemanticModel.GetDeclaredSymbol(node, context.CancellationToken);
236231
var rawDocumentation = declaration?.GetDocumentationCommentXml(expandIncludes: true, cancellationToken: context.CancellationToken);
237232
completeDocumentation = XElement.Parse(rawDocumentation, LoadOptions.None);
238-
if (completeDocumentation.Nodes().OfType<XElement>().Any(element => element.Name == XmlCommentHelper.InheritdocXmlTag))
239-
{
240-
// Ignore nodes with an <inheritdoc/> tag in the included XML.
241-
return;
242-
}
243233
}
244234
}
245235

246-
this.HandleXmlElement(context, relevantXmlElement, completeDocumentation, locations);
236+
this.HandleXmlElement(context, documentation, relevantXmlElement, completeDocumentation, locations);
247237
}
248238
}
249239
}

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1604ElementDocumentationMustHaveSummary.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ internal class SA1604ElementDocumentationMustHaveSummary : ElementDocumentationS
4343
ImmutableArray.Create(Descriptor);
4444

4545
/// <inheritdoc/>
46-
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, XmlNodeSyntax syntax, XElement completeDocumentation, Location[] diagnosticLocations)
46+
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, DocumentationCommentTriviaSyntax documentation, XmlNodeSyntax syntax, XElement completeDocumentation, Location[] diagnosticLocations)
4747
{
4848
if (completeDocumentation != null)
4949
{
@@ -52,13 +52,25 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, XmlN
5252
{
5353
return;
5454
}
55+
56+
if (completeDocumentation.Nodes().OfType<XElement>().Any(element => element.Name == XmlCommentHelper.InheritdocXmlTag))
57+
{
58+
// Ignore nodes with an <inheritdoc/> tag in the included XML.
59+
return;
60+
}
5561
}
5662
else
5763
{
5864
if (syntax != null)
5965
{
6066
return;
6167
}
68+
69+
if (documentation?.Content.GetFirstXmlElement(XmlCommentHelper.InheritdocXmlTag) != null)
70+
{
71+
// Ignore nodes with an <inheritdoc/> tag.
72+
return;
73+
}
6274
}
6375

6476
foreach (var location in diagnosticLocations)

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1606ElementDocumentationMustHaveSummaryText.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ internal class SA1606ElementDocumentationMustHaveSummaryText : ElementDocumentat
4545
ImmutableArray.Create(Descriptor);
4646

4747
/// <inheritdoc/>
48-
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, XmlNodeSyntax syntax, XElement completeDocumentation, Location[] diagnosticLocations)
48+
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, DocumentationCommentTriviaSyntax documentation, XmlNodeSyntax syntax, XElement completeDocumentation, Location[] diagnosticLocations)
4949
{
5050
if (syntax == null)
5151
{

0 commit comments

Comments
 (0)