Skip to content

Commit 90708ec

Browse files
committed
Merge pull request #1890 from pdelvo/fix-1876
Fix that SA1625 ignores empty xml elements
2 parents 73afee8 + 84bd535 commit 90708ec

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1625UnitTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,27 @@ public class TestClass
4747
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
4848
}
4949

50+
[Theory]
51+
[MemberData(nameof(Members))]
52+
public async Task VerifyThatCorrectDocumentationWithEmptyElementsDoesNotReportADiagnosticAsync(string member)
53+
{
54+
var testCode = $@"
55+
public class TestClass
56+
{{
57+
/// <summary>
58+
/// Some documentation <see cref=""TestClass""/>.
59+
/// </summary>
60+
/// <summary>
61+
/// Some documentation <see cref=""TestClass2""/>.
62+
/// </summary>
63+
/// <remark>Some remark.</remark>
64+
{member}
65+
}}
66+
public class TestClass2 {{ }}
67+
";
68+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
69+
}
70+
5071
[Theory]
5172
[MemberData(nameof(Members))]
5273
public async Task VerifyThatTheAnalyzerDoesNotCrashOnInheritDocAsync(string member)
@@ -61,6 +82,27 @@ public class TestClass
6182
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
6283
}
6384

85+
[Theory]
86+
[MemberData(nameof(Members))]
87+
public async Task VerifyThatWhitespacesAreNormalizedForEmptyXmlElementsAsync(string member)
88+
{
89+
var testCode = $@"
90+
public class TestClass
91+
{{
92+
/// <summary>
93+
/// Some documentation <see cref=""TestClass""/>.
94+
/// </summary>
95+
/// <summary>
96+
/// Some documentation <see cref = ""TestClass"" />.
97+
/// </summary>
98+
/// <remark>Some remark.</remark>
99+
{member}
100+
}}
101+
";
102+
var expected = this.CSharpDiagnostic().WithLocation(7, 9);
103+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
104+
}
105+
64106
[Theory]
65107
[MemberData(nameof(Members))]
66108
public async Task VerifyThatDublicatedDocumentationDoesReportADiagnosticAsync(string member)

StyleCop.Analyzers/StyleCop.Analyzers/Helpers/XmlCommentHelper.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ internal static string GetText(XmlNodeSyntax nodeSyntax, bool normalizeWhitespac
184184
return StringBuilderPool.ReturnAndFree(stringBuilder);
185185
}
186186

187+
var emptyXmlElement = nodeSyntax as XmlEmptyElementSyntax;
188+
189+
if (emptyXmlElement != null)
190+
{
191+
return emptyXmlElement.NormalizeWhitespace(string.Empty).ToString();
192+
}
193+
187194
return null;
188195
}
189196

0 commit comments

Comments
 (0)