Skip to content

Commit ecee2c7

Browse files
committed
Fix handling of consecutive empty elements
1 parent 65bdc27 commit ecee2c7

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,47 @@ public interface ITest
336336
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
337337
}
338338

339+
[Fact]
340+
[WorkItem(2680, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2680")]
341+
public async Task TestReportingAfterTwoEmptyElementsAsync()
342+
{
343+
var testCode = @"
344+
/// <summary>
345+
/// Test interface <see cref=""ITest""/> <see cref=""ITest""/>
346+
/// </summary>
347+
public interface ITest
348+
{
349+
/// <summary>
350+
/// Test method <see cref=""Method""/><see cref=""Method""/>
351+
/// </summary>
352+
void Method();
353+
}
354+
";
355+
356+
var fixedTestCode = @"
357+
/// <summary>
358+
/// Test interface <see cref=""ITest""/> <see cref=""ITest""/>.
359+
/// </summary>
360+
public interface ITest
361+
{
362+
/// <summary>
363+
/// Test method <see cref=""Method""/><see cref=""Method""/>.
364+
/// </summary>
365+
void Method();
366+
}
367+
";
368+
369+
DiagnosticResult[] expected =
370+
{
371+
this.CSharpDiagnostic().WithLocation(3, 59),
372+
this.CSharpDiagnostic().WithLocation(8, 61),
373+
};
374+
375+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
376+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
377+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
378+
}
379+
339380
[Fact]
340381
[WorkItem(2679, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2679")]
341382
public async Task TestElementsThatDoNotRequirePeriodsAsync()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool
110110
{
111111
// If a diagnostic gets reported for the element, place the diagnostic after the last inline
112112
// element.
113-
reportingLocation = xmlElement.Content[i].Span.End;
113+
reportingLocation = reportingLocation ?? xmlElement.Content[i].Span.End;
114114
}
115115
}
116116
}

0 commit comments

Comments
 (0)