Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,49 @@ await Task.Delay(1000)
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

[Theory]
[InlineData("if (true)")]
[InlineData("while (true)")]
[InlineData("for (var i = 0; i < 10; i++)")]
[InlineData("foreach (var i in a)")]
[WorkItem(3731, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3731")]
public async Task TestControlStatementWithBodyOnSameLineAsync(string stmt)
{
var testCode = $@"
public class TestClass
{{
public async void TestMethod(int x, int[] a)
{{
{stmt}++x;
{stmt}--x;
{stmt}x++;
{stmt}{{ x++; }}
}}
}}";

var fixedCode = $@"
public class TestClass
{{
public async void TestMethod(int x, int[] a)
{{
{stmt} ++x;
{stmt} --x;
{stmt} x++;
{stmt} {{ x++; }}
}}
}}";

var expected = new[]
{
Diagnostic(DescriptorFollowed).WithLocation(6, 8 + stmt.Length),
Diagnostic(DescriptorFollowed).WithLocation(7, 8 + stmt.Length),
Diagnostic(DescriptorFollowed).WithLocation(8, 8 + stmt.Length),
Diagnostic(DescriptorFollowed).WithLocation(9, 8 + stmt.Length),
};

await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestWhitespaceInStatementOrDeclAsync(string originalStatement, string fixedStatement, params DiagnosticResult[] expected)
{
string template = @"namespace Foo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ private static void HandleCloseParenToken(SyntaxTreeAnalysisContext context, Syn

case SyntaxKind.PlusPlusToken:
case SyntaxKind.MinusMinusToken:
precedesStickyCharacter = true;
precedesStickyCharacter =
!nextToken.Parent.IsKind(SyntaxKind.PreIncrementExpression)
&& !nextToken.Parent.IsKind(SyntaxKind.PreDecrementExpression);
suppressFollowingSpaceError = false;
break;

Expand Down