Skip to content

Commit c1d0884

Browse files
committed
Merge pull request #2007 from sharwell/port-1977
Port #1977 to stabilization
2 parents 1c701f5 + cac27cd commit c1d0884

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1609UnitTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,43 @@ public class ClassName
244244
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
245245
}
246246

247+
/// <summary>
248+
/// Regression test for DotNetAnalyzers/StyleCopAnalyzers#1942.
249+
/// </summary>
250+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
251+
[Fact]
252+
public async Task TestPropertyWithEmptySummaryAsync()
253+
{
254+
var testCode = @"
255+
public class ClassName
256+
{
257+
/// <summary>
258+
/// </summary>
259+
public int Property
260+
{
261+
get;
262+
}
263+
}";
264+
265+
var fixedCode = @"
266+
public class ClassName
267+
{
268+
/// <summary>
269+
/// </summary>
270+
/// <value>
271+
///
272+
/// </value>
273+
public int Property
274+
{
275+
get;
276+
}
277+
}";
278+
279+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 16);
280+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
281+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
282+
}
283+
247284
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
248285
{
249286
yield return new SA1609PropertyDocumentationMustHaveValue();

StyleCop.Analyzers/StyleCop.Analyzers/Helpers/DocumentationCommentExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ public static SyntaxList<XmlNodeSyntax> WithoutFirstAndLastNewlines(this SyntaxL
152152

153153
for (int i = 0; i < removeFromEnd; i++)
154154
{
155+
if (!lastSyntaxTokens.Any())
156+
{
157+
break;
158+
}
159+
155160
lastSyntaxTokens = lastSyntaxTokens.RemoveAt(lastSyntaxTokens.Count - 1);
156161
}
157162

0 commit comments

Comments
 (0)