Skip to content

Commit 8154da4

Browse files
committed
Update SA1503 for asynchronous streams
1 parent bc35406 commit 8154da4

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/LayoutRules/SA1503CSharp8UnitTests.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp8.LayoutRules
75
{
86
using System.Threading;
@@ -32,5 +30,41 @@ public void Method()
3230

3331
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3432
}
33+
34+
[Fact]
35+
[WorkItem(3007, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3007")]
36+
public async Task TestAwaitForEachMustUseBracesAsync()
37+
{
38+
var testCode = @"
39+
using System.Collections.Generic;
40+
using System.Threading.Tasks;
41+
42+
public class TestClass
43+
{
44+
public async Task TestAsync(IAsyncEnumerable<int> values)
45+
{
46+
await foreach (var value in values)
47+
{|#0:_ = value;|}
48+
}
49+
}
50+
";
51+
var fixedCode = @"
52+
using System.Collections.Generic;
53+
using System.Threading.Tasks;
54+
55+
public class TestClass
56+
{
57+
public async Task TestAsync(IAsyncEnumerable<int> values)
58+
{
59+
await foreach (var value in values)
60+
{
61+
_ = value;
62+
}
63+
}
64+
}
65+
";
66+
67+
await VerifyCSharpFixAsync(testCode, Diagnostic().WithLocation(0), fixedCode, CancellationToken.None).ConfigureAwait(false);
68+
}
3569
}
3670
}

0 commit comments

Comments
 (0)