Skip to content

Commit 03e0562

Browse files
authored
Merge pull request #3292 from angelobreuer/fix/3291
SA1648 throws an exception on delegates that use the <include> tag
2 parents 046752f + e26b2f1 commit 03e0562

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1648UnitTests.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,57 @@ public void TestMethod() { }
305305
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
306306
}
307307

308+
/// <summary>
309+
/// Verifies that a delegate declaration that includes the inheritdoc will produce diagnostics.
310+
/// </summary>
311+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
312+
[Fact]
313+
[WorkItem(3291, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3291")]
314+
[WorkItem(3291, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3291")]
315+
public async Task TestIncorrectDocumentedDelegateInheritDocAsync()
316+
{
317+
var testCode = @"
318+
/// <summary>Foo</summary>
319+
/// <param name=""value"">some param</param>
320+
/// <returns>something</returns>
321+
public delegate bool TestDelegate(int value);
322+
323+
/// <summary>Test class</summary>
324+
public class TestClass
325+
{
326+
/// {|#0:<include file='DelegateInheritDoc.xml' path='/TestDelegate/*'/>|}
327+
public delegate bool TestDelegate(int value);
328+
}
329+
";
330+
331+
var expected = Diagnostic().WithLocation(0);
332+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
333+
}
334+
335+
/// <summary>
336+
/// Verifies that a delegate declaration that includes the inheritdoc will produce diagnostics.
337+
/// </summary>
338+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
339+
[Fact]
340+
[WorkItem(3291, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3291")]
341+
[WorkItem(3291, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3291")]
342+
public async Task TestIncorrectDelegateInheritDocAsync()
343+
{
344+
var testCode = @"
345+
public delegate bool TestDelegate(int value);
346+
347+
/// <summary>Test class</summary>
348+
public class TestClass
349+
{
350+
/// {|#0:<include file='DelegateInheritDoc.xml' path='/TestDelegate/*'/>|}
351+
public delegate bool TestDelegate(int value);
352+
}
353+
";
354+
355+
var expected = Diagnostic().WithLocation(0);
356+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
357+
}
358+
308359
private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken)
309360
=> VerifyCSharpDiagnosticAsync(source, new[] { expected }, cancellationToken);
310361

@@ -329,6 +380,11 @@ private static StyleCopDiagnosticVerifier<SA1648InheritDocMustBeUsedWithInheriti
329380
<inheritdoc/>
330381
</TestMethod>
331382
</TestClass>
383+
";
384+
string contentDelegateInheritDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
385+
<TestDelegate>
386+
<inheritdoc/>
387+
</TestDelegate>
332388
";
333389

334390
var test = new StyleCopDiagnosticVerifier<SA1648InheritDocMustBeUsedWithInheritingClass>.CSharpTest
@@ -337,6 +393,7 @@ private static StyleCopDiagnosticVerifier<SA1648InheritDocMustBeUsedWithInheriti
337393
{
338394
{ "ClassInheritDoc.xml", contentClassInheritDoc },
339395
{ "MethodInheritDoc.xml", contentMethodInheritDoc },
396+
{ "DelegateInheritDoc.xml", contentDelegateInheritDoc },
340397
},
341398
};
342399

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1648InheritDocMustBeUsedWithInheritingClass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private static void HandleBaseTypeLikeDeclaration(SyntaxNodeAnalysisContext cont
8686

8787
if (documentation.Content.GetFirstXmlElement(XmlCommentHelper.IncludeXmlTag) is XmlEmptyElementSyntax includeElement)
8888
{
89-
var declaration = context.SemanticModel.GetDeclaredSymbol(baseType, context.CancellationToken);
89+
var declaration = context.SemanticModel.GetDeclaredSymbol(context.Node, context.CancellationToken);
9090
if (declaration == null)
9191
{
9292
return;

0 commit comments

Comments
 (0)