Skip to content

Commit ef47559

Browse files
committed
Merge pull request #1842 from sharwell/fix-1777
Fix handling of semicolon followed by empty statement
2 parents 61fb631 + edabc7f commit ef47559

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1002UnitTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,26 @@ void MethodName()
221221
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
222222
}
223223

224+
/// <summary>
225+
/// This is a regression test for DotNetAnalyzers/StyleCopAnalyzers#1777.
226+
/// </summary>
227+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
228+
[Fact]
229+
public async Task TestEmptyStatementAfterCallAsync()
230+
{
231+
string testCode = @"using System;
232+
class ClassName
233+
{
234+
void MethodName()
235+
{
236+
Console.WriteLine();;
237+
}
238+
}
239+
";
240+
241+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
242+
}
243+
224244
[Fact]
225245
public async Task TestSingleLineAccessorsAsync()
226246
{

StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1002SemicolonsMustBeSpacedCorrectly.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,26 @@ private static void HandleSemicolonToken(SyntaxTreeAnalysisContext context, Synt
9292
else
9393
{
9494
SyntaxToken nextToken = token.GetNextToken();
95-
if (nextToken.IsKind(SyntaxKind.CloseParenToken))
95+
switch (nextToken.Kind())
9696
{
97+
case SyntaxKind.CloseParenToken:
9798
// Special handling for the following case:
9899
// for (; ;)
99100
missingFollowingSpace = false;
101+
break;
102+
103+
case SyntaxKind.SemicolonToken:
104+
// Special handling for the following case:
105+
// Statement();;
106+
if (nextToken.Parent.IsKind(SyntaxKind.EmptyStatement))
107+
{
108+
missingFollowingSpace = false;
109+
}
110+
111+
break;
112+
113+
default:
114+
break;
100115
}
101116
}
102117

0 commit comments

Comments
 (0)