Skip to content

Commit 6642040

Browse files
committed
Improved behavior with invalid included documentation
1 parent 06ec337 commit 6642040

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1629UnitTests.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,18 @@ public int TestMethod<T>(T arg1)
284284
Assert.Empty(offeredFixes);
285285
}
286286

287-
//// TODO: Verify <inheritdoc/> together with additional elements
287+
[Fact]
288+
public async Task TestInvalidIncludedDocumentationAsync()
289+
{
290+
var testCode = @"
291+
/// <include file='InvalidClassInheritDoc.xml' path='/TestClass/*'/>
292+
public class TestClass
293+
{
294+
}
295+
";
296+
297+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
298+
}
288299

289300
protected override Project ApplyCompilationOptions(Project project)
290301
{
@@ -297,6 +308,13 @@ protected override Project ApplyCompilationOptions(Project project)
297308
";
298309
resolver.XmlReferences.Add("ClassInheritDoc.xml", contentClassInheritDoc);
299310

311+
string contentInvalidClassInheritDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
312+
<TestClass>
313+
<summary>Test class<summary>
314+
</TestClass>
315+
";
316+
resolver.XmlReferences.Add("InvalidClassInheritDoc.xml", contentInvalidClassInheritDoc);
317+
300318
string contentPropertyInheritDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
301319
<TestClass>
302320
<TestProperty>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1629DocumentationTextMustEndWithAPeriod.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,26 +107,20 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool
107107
/// <inheritdoc/>
108108
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
109109
{
110-
try
110+
foreach (var node in completeDocumentation.Nodes().OfType<XElement>())
111111
{
112-
foreach (var node in completeDocumentation.Nodes().Cast<XElement>())
112+
var textWithoutTrailingWhitespace = node.Value.TrimEnd(' ', '\r', '\n');
113+
if (!string.IsNullOrEmpty(textWithoutTrailingWhitespace))
113114
{
114-
var textWithoutTrailingWhitespace = node.Value.TrimEnd(' ', '\r', '\n');
115-
if (!string.IsNullOrEmpty(textWithoutTrailingWhitespace))
115+
if (!textWithoutTrailingWhitespace.EndsWith(".", StringComparison.Ordinal))
116116
{
117-
if (!textWithoutTrailingWhitespace.EndsWith(".", StringComparison.Ordinal))
118-
{
119-
context.ReportDiagnostic(Diagnostic.Create(Descriptor, diagnosticLocations[0], NoCodeFixProperties));
117+
context.ReportDiagnostic(Diagnostic.Create(Descriptor, diagnosticLocations[0], NoCodeFixProperties));
120118

121-
// only report a single instance of the diagnostic, as they will all be reported on the same location anyway.
122-
break;
123-
}
119+
// only report a single instance of the diagnostic, as they will all be reported on the same location anyway.
120+
break;
124121
}
125122
}
126123
}
127-
catch (InvalidCastException)
128-
{
129-
}
130124
}
131125
}
132126
}

0 commit comments

Comments
 (0)