Skip to content

Commit bce6fc3

Browse files
authored
Show warning when ConfigureAwait should be used (#522)
1 parent 174a957 commit bce6fc3

File tree

10 files changed

+142
-112
lines changed

10 files changed

+142
-112
lines changed

Diff for: Softeq.XToolkit.Common/Commands/AsyncCommandBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected async Task DoExecuteAsync(Func<Task> executionProvider)
4747

4848
try
4949
{
50-
await executionProvider.Invoke();
50+
await executionProvider.Invoke().ConfigureAwait(false);
5151
}
5252
finally
5353
{

Diff for: Softeq.XToolkit.Common/Files/BaseFileProvider.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public Task ClearFolderAsync(string path)
3232
{
3333
var tasks = _fileSystem.Directory.GetFiles(path).
3434
Select(async x => await RemoveFileAsync(x).ConfigureAwait(false));
35-
await Task.WhenAll(tasks);
35+
await Task.WhenAll(tasks).ConfigureAwait(false);
3636
});
3737
}
3838

@@ -69,10 +69,10 @@ public Task CopyFileAsync(string sourcePath, string destinationPath, bool overwr
6969
public async Task WriteFileAsync(string path, Stream stream)
7070
{
7171
path = GetAbsolutePath(path);
72-
using (var outputStream = await OpenFileForWriteAsync(path))
72+
using (var outputStream = await OpenFileForWriteAsync(path).ConfigureAwait(false))
7373
{
7474
stream.Position = 0;
75-
await stream.CopyToAsync(outputStream);
75+
await stream.CopyToAsync(outputStream).ConfigureAwait(false);
7676

7777
stream.Dispose();
7878
}

Diff for: Softeq.XToolkit.Common/Threading/TaskDeferral.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public async Task<T> DoWorkAsync(Func<Task<T>> taskFactory)
4141
if (_queue.IsEmpty)
4242
{
4343
_semaphoreSlim.Release();
44-
return await tcs.Task;
44+
return await tcs.Task.ConfigureAwait(false);
4545
}
4646

4747
var result = await ExecuteAsync(taskFactory).ConfigureAwait(false);
@@ -54,7 +54,7 @@ public async Task<T> DoWorkAsync(Func<Task<T>> taskFactory)
5454

5555
_semaphoreSlim.Release();
5656

57-
return await tcs.Task;
57+
return await tcs.Task.ConfigureAwait(false);
5858
}
5959

6060
private static async Task<T> ExecuteAsync(Func<Task<T>> taskFactory)

Diff for: Softeq.XToolkit.Common/Timers/Timer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private async Task DoWork()
7979
{
8080
do
8181
{
82-
await Task.Delay(_interval);
82+
await Task.Delay(_interval).ConfigureAwait(false);
8383
if (IsActive && _taskFactory != null)
8484
{
8585
await _taskFactory().ConfigureAwait(false);

Diff for: Softeq.XToolkit.Permissions/PermissionsService.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ namespace Softeq.XToolkit.Permissions
1212
public class PermissionsService : IPermissionsService
1313
{
1414
/// <inheritdoc />
15-
public async Task<PermissionStatus> RequestPermissionsAsync<T>()
15+
public Task<PermissionStatus> RequestPermissionsAsync<T>()
1616
where T : BasePermission, new()
1717
{
18-
return await MainThread.InvokeOnMainThreadAsync(async () =>
18+
return MainThread.InvokeOnMainThreadAsync(async () =>
1919
{
2020
var result = await EssentialsPermissions.RequestAsync<T>().ConfigureAwait(false);
2121
return result.ToPermissionStatus();
@@ -41,4 +41,4 @@ public void OpenSettings()
4141
return EssentialsPermissions.ShouldShowRationale<T>();
4242
}
4343
}
44-
}
44+
}

Diff for: Softeq.XToolkit.WhiteLabel.Tests/GlobalSuppressions.cs

+5
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@
1212
"StyleCop.CSharp.DocumentationRules",
1313
"SA1649:File name should match first type name",
1414
Justification = "Mixed types allowed for tests")]
15+
16+
[assembly: SuppressMessage(
17+
"Reliability",
18+
"CA2007:Consider calling ConfigureAwait on the awaited task",
19+
Justification = "Allowed for tests")]

Diff for: XToolkit.ruleset

+100-102
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RuleSet Name="Rules for Softeq.XToolkit" Description="Code analysis rules for Softeq.XToolkit." ToolsVersion="15.0">
33
<IncludeAll Action="Warning" />
4+
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
5+
<Rule Id="CA2007" Action="Warning" /> <!-- Decorate all async calls with a `.ConfigureAwait(false);` suffix -->
6+
</Rules>
47
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
5-
<Rule Id="SA0001" Action="None" />
6-
<!-- <Rule Id="SA0002" Action="Error" />
7-
<Rule Id="SA1000" Action="Error" />
8-
<Rule Id="SA1001" Action="Error" />
9-
<Rule Id="SA1002" Action="Error" /> -->
10-
<Rule Id="SA1003" Action="None" /> <!-- @ Error -->
11-
<!-- <Rule Id="SA1004" Action="Error" />
12-
<Rule Id="SA1005" Action="Error" />
13-
<Rule Id="SA1006" Action="Error" />
14-
<Rule Id="SA1007" Action="Error" />
15-
<Rule Id="SA1008" Action="Error" /> -->
16-
<Rule Id="SA1009" Action="None" /> <!-- @ Error -->
8+
<Rule Id="SA0001" Action="None" />
9+
<!-- <Rule Id="SA0002" Action="Error" /> -->
10+
<!-- <Rule Id="SA1000" Action="Error" /> -->
11+
<!-- <Rule Id="SA1001" Action="Error" /> -->
12+
<!-- <Rule Id="SA1002" Action="Error" /> -->
13+
<Rule Id="SA1003" Action="None" /> <!-- @ Error -->
14+
<!-- <Rule Id="SA1004" Action="Error" /> -->
15+
<!-- <Rule Id="SA1005" Action="Error" /> -->
16+
<!-- <Rule Id="SA1006" Action="Error" /> -->
17+
<!-- <Rule Id="SA1007" Action="Error" /> -->
18+
<!-- <Rule Id="SA1008" Action="Error" /> -->
19+
<Rule Id="SA1009" Action="None" /> <!-- @ Error -->
1720
<!-- <Rule Id="SA1010" Action="Error" /> -->
1821
<Rule Id="SA1011" Action="None" />
1922
<!-- <Rule Id="SA1012" Action="Error" />
@@ -32,74 +35,69 @@
3235
<Rule Id="SA1025" Action="Error" />
3336
<Rule Id="SA1026" Action="Error" />
3437
<Rule Id="SA1027" Action="Error" /> -->
35-
<Rule Id="SA1028" Action="Warning" /> <!-- @ Error -->
38+
<Rule Id="SA1028" Action="Warning" /> <!-- @ Error -->
3639
<!-- <Rule Id="SA1100" Action="Error" /> -->
3740
<Rule Id="SA1101" Action="None" /> <!-- Prefix local calls with this -->
3841
<!-- <Rule Id="SA1102" Action="Error" /> -->
3942
<Rule Id="SA1103" Action="None" /> <!-- !!! -->
40-
<!-- <Rule Id="SA1104" Action="Error" />
41-
<Rule Id="SA1105" Action="Error" />
42-
<Rule Id="SA1106" Action="Error" />
43-
<Rule Id="SA1107" Action="Error" /> -->
43+
<!-- <Rule Id="SA1104" Action="Error" /> -->
44+
<!-- <Rule Id="SA1105" Action="Error" /> -->
45+
<!-- <Rule Id="SA1106" Action="Error" /> -->
46+
<!-- <Rule Id="SA1107" Action="Error" /> -->
4447
<Rule Id="SA1108" Action="None" /> <!-- !!! -->
4548
<Rule Id="SA1109" Action="None" /> <!-- !!! -->
46-
<!-- <Rule Id="SA1110" Action="Error" />
47-
<Rule Id="SA1111" Action="Error" />
48-
<Rule Id="SA1112" Action="Error" />
49-
<Rule Id="SA1113" Action="Error" />
50-
<Rule Id="SA1114" Action="Error" />
51-
<Rule Id="SA1115" Action="Error" /> -->
52-
<Rule Id="SA1116" Action="Warning" /> <!-- @ Error -->
53-
<!-- <Rule Id="SA1117" Action="Error" />
54-
<Rule Id="SA1118" Action="Error" />
55-
<Rule Id="SA1119" Action="Error" />
56-
<Rule Id="SA1120" Action="Error" />
57-
<Rule Id="SA1121" Action="Error" />
58-
<Rule Id="SA1122" Action="Error" />
59-
<Rule Id="SA1123" Action="Error" /> -->
49+
<!-- <Rule Id="SA1110" Action="Error" /> -->
50+
<!-- <Rule Id="SA1111" Action="Error" /> -->
51+
<!-- <Rule Id="SA1112" Action="Error" /> -->
52+
<!-- <Rule Id="SA1113" Action="Error" /> -->
53+
<!-- <Rule Id="SA1114" Action="Error" /> -->
54+
<!-- <Rule Id="SA1115" Action="Error" /> -->
55+
<Rule Id="SA1116" Action="Warning" /> <!-- @ Error -->
56+
<!-- <Rule Id="SA1117" Action="Error" /> -->
57+
<!-- <Rule Id="SA1118" Action="Error" /> -->
58+
<!-- <Rule Id="SA1119" Action="Error" /> -->
59+
<!-- <Rule Id="SA1120" Action="Error" /> -->
60+
<!-- <Rule Id="SA1121" Action="Error" /> -->
61+
<!-- <Rule Id="SA1122" Action="Error" /> -->
62+
<!-- <Rule Id="SA1123" Action="Error" /> -->
6063
<Rule Id="SA1124" Action="None" /> <!-- DoNotUseRegions -->
61-
<!--
62-
<Rule Id="SA1125" Action="Error" /> -->
64+
<!-- <Rule Id="SA1125" Action="Error" /> -->
6365
<Rule Id="SA1126" Action="None" />
64-
<Rule Id="SA1127" Action="None" /> <!-- @ Error -->
65-
<Rule Id="SA1128" Action="None" /> <!-- Constructor initializers should be on their own line -->
66-
<!--
67-
<Rule Id="SA1129" Action="Error" />
68-
<Rule Id="SA1130" Action="Error" />
69-
<Rule Id="SA1131" Action="Error" />
70-
<Rule Id="SA1132" Action="Error" />
71-
<Rule Id="SA1133" Action="Error" />
72-
<Rule Id="SA1134" Action="Error" />
73-
<Rule Id="SA1135" Action="Error" />
74-
<Rule Id="SA1136" Action="Error" />
75-
<Rule Id="SA1137" Action="Error" />
76-
<Rule Id="SA1139" Action="Error" /> -->
66+
<Rule Id="SA1127" Action="None" /> <!-- @ Error -->
67+
<Rule Id="SA1128" Action="None" /> <!-- Constructor initializers should be on their own line -->
68+
<!-- <Rule Id="SA1129" Action="Error" /> -->
69+
<!-- <Rule Id="SA1130" Action="Error" /> -->
70+
<!-- <Rule Id="SA1131" Action="Error" /> -->
71+
<!-- <Rule Id="SA1132" Action="Error" /> -->
72+
<!-- <Rule Id="SA1133" Action="Error" /> -->
73+
<!-- <Rule Id="SA1134" Action="Error" /> -->
74+
<!-- <Rule Id="SA1135" Action="Error" /> -->
75+
<!-- <Rule Id="SA1136" Action="Error" /> -->
76+
<!-- <Rule Id="SA1137" Action="Error" /> -->
77+
<!-- <Rule Id="SA1139" Action="Error" /> -->
7778
<Rule Id="SA1200" Action="None" />
78-
<Rule Id="SA1201" Action="Warning" /> <!-- @ Error - ordering -->
79+
<Rule Id="SA1201" Action="Warning" /> <!-- @ Error - ordering -->
7980
<Rule Id="SA1202" Action="None" />
8081
<!-- <Rule Id="SA1203" Action="Error" /> -->
81-
<Rule Id="SA1204" Action="Warning" /> <!-- @ Error - ordering -->
82-
<!-- <Rule Id="SA1205" Action="Error" />
83-
<Rule Id="SA1206" Action="Error" />
84-
<Rule Id="SA1207" Action="Error" />
85-
<Rule Id="SA1208" Action="Error" />
86-
<Rule Id="SA1209" Action="Error" />
87-
<Rule Id="SA1210" Action="Error" />
88-
<Rule Id="SA1211" Action="Error" />
89-
<Rule Id="SA1212" Action="Error" />
90-
<Rule Id="SA1213" Action="Error" />
91-
<Rule Id="SA1214" Action="Error" />
92-
<Rule Id="SA1215" Action="Error" />
93-
<Rule Id="SA1216" Action="Error" />
94-
<Rule Id="SA1217" Action="Error" />
95-
<Rule Id="SA1300" Action="Error" />
96-
<Rule Id="SA1301" Action="Error" />
97-
<Rule Id="SA1302" Action="Error" />
98-
<Rule Id="SA1303" Action="Error" />
99-
<Rule Id="SA1304" Action="Error" /> -->
100-
101-
102-
82+
<Rule Id="SA1204" Action="Warning" /> <!-- @ Error - ordering -->
83+
<!-- <Rule Id="SA1205" Action="Error" /> -->
84+
<!-- <Rule Id="SA1206" Action="Error" /> -->
85+
<!-- <Rule Id="SA1207" Action="Error" /> -->
86+
<!-- <Rule Id="SA1208" Action="Error" /> -->
87+
<!-- <Rule Id="SA1209" Action="Error" /> -->
88+
<!-- <Rule Id="SA1210" Action="Error" /> -->
89+
<!-- <Rule Id="SA1211" Action="Error" /> -->
90+
<!-- <Rule Id="SA1212" Action="Error" /> -->
91+
<!-- <Rule Id="SA1213" Action="Error" /> -->
92+
<!-- <Rule Id="SA1214" Action="Error" /> -->
93+
<!-- <Rule Id="SA1215" Action="Error" /> -->
94+
<!-- <Rule Id="SA1216" Action="Error" /> -->
95+
<!-- <Rule Id="SA1217" Action="Error" /> -->
96+
<!-- <Rule Id="SA1300" Action="Error" /> -->
97+
<!-- <Rule Id="SA1301" Action="Error" /> -->
98+
<!-- <Rule Id="SA1302" Action="Error" /> -->
99+
<!-- <Rule Id="SA1303" Action="Error" /> -->
100+
<!-- <Rule Id="SA1304" Action="Error" /> -->
103101
<Rule Id="SA1306" Action="None" />
104102
<!-- <Rule Id="SA1307" Action="Error" /> -->
105103
<!-- <Rule Id="SA1308" Action="Error" /> -->
@@ -109,49 +107,49 @@
109107
<!-- <Rule Id="SA1313" Action="Error" /> -->
110108
<!-- <Rule Id="SA1314" Action="Error" /> -->
111109
<!-- <Rule Id="SA1400" Action="Error" /> -->
112-
<Rule Id="SA1401" Action="None" /> <!-- @ Warning -->
110+
<Rule Id="SA1401" Action="None" /> <!-- @ Warning -->
113111
<Rule Id="SA1402" Action="None" />
114112
<!-- <Rule Id="SA1403" Action="Error" /> -->
115-
<Rule Id="SA1407" Action="Warning" /> <!-- @ Warning -->
116-
<!-- <Rule Id="SA1408" Action="Error" /> --> <!-- @ Warning -->
113+
<Rule Id="SA1407" Action="Warning" /> <!-- @ Warning -->
114+
<!-- <Rule Id="SA1408" Action="Error" /> --> <!-- @ Warning -->
117115
<!-- <Rule Id="SA1411" Action="Error" /> -->
118-
<Rule Id="SA1412" Action="None" /> <!-- @ Error -->
116+
<Rule Id="SA1412" Action="None" /> <!-- @ Error -->
119117
<Rule Id="SA1413" Action="None" />
120118
<!-- <Rule Id="SA1500" Action="Error" /> -->
121119
<!-- <Rule Id="SA1501" Action="Error" /> -->
122120
<Rule Id="SA1502" Action="Warning" /> <!-- !!! -->
123-
<!-- <Rule Id="SA1504" Action="Error" />
124-
<Rule Id="SA1505" Action="Error" />
125-
<Rule Id="SA1506" Action="Error" />
126-
<Rule Id="SA1507" Action="Error" />
127-
<Rule Id="SA1508" Action="Error" />
128-
<Rule Id="SA1509" Action="Error" />
129-
<Rule Id="SA1510" Action="Error" />
130-
<Rule Id="SA1511" Action="Error" /> -->
131-
<Rule Id="SA1512" Action="None" />
132-
<Rule Id="SA1516" Action="None" /> <!-- @ Warning -->
133-
<!-- <Rule Id="SA1517" Action="Error" />
134-
<Rule Id="SA1519" Action="Error" />
135-
<Rule Id="SA1520" Action="Error" /> -->
136-
<Rule Id="SA1600" Action="None" /> <!-- @ Warning -->
121+
<!-- <Rule Id="SA1504" Action="Error" /> -->
122+
<!-- <Rule Id="SA1505" Action="Error" /> -->
123+
<!-- <Rule Id="SA1506" Action="Error" /> -->
124+
<!-- <Rule Id="SA1507" Action="Error" /> -->
125+
<!-- <Rule Id="SA1508" Action="Error" /> -->
126+
<!-- <Rule Id="SA1509" Action="Error" /> -->
127+
<!-- <Rule Id="SA1510" Action="Error" /> -->
128+
<!-- <Rule Id="SA1511" Action="Error" /> -->
129+
<Rule Id="SA1512" Action="None" />
130+
<Rule Id="SA1516" Action="None" /> <!-- @ Warning -->
131+
<!-- <Rule Id="SA1517" Action="Error" /> -->
132+
<!-- <Rule Id="SA1519" Action="Error" /> -->
133+
<!-- <Rule Id="SA1520" Action="Error" /> -->
134+
<Rule Id="SA1600" Action="None" /> <!-- @ Warning -->
137135
<Rule Id="SA1601" Action="None" />
138136
<Rule Id="SA1602" Action="None" />
139-
<!-- <Rule Id="SA1603" Action="Error" /> -->
137+
<!-- <Rule Id="SA1603" Action="Error" /> -->
140138
<Rule Id="SA1609" Action="None" />
141-
<!-- <Rule Id="SA1630" Action="Error" />
142-
<Rule Id="SA1641" Action="Error" /> -->
139+
<!-- <Rule Id="SA1630" Action="Error" /> -->
140+
<!-- <Rule Id="SA1641" Action="Error" /> -->
143141
<Rule Id="SA1642" Action="Warning" />
144-
<!-- <Rule Id="SA1643" Action="Error" />
145-
<Rule Id="SA1644" Action="Error" />
146-
<Rule Id="SA1645" Action="Error" />
147-
<Rule Id="SA1646" Action="Error" />
148-
<Rule Id="SA1647" Action="Error" />
149-
<Rule Id="SA1648" Action="Error" /> -->
150-
<Rule Id="SA1649" Action="Warning" /> <!-- @ Error -->
151-
<!-- <Rule Id="SA1650" Action="Error" />
152-
<Rule Id="SA1651" Action="Error" />
153-
<Rule Id="SX1101" Action="Error" /> -->
154-
<Rule Id="SX1309" Action="Warning" /> <!-- @ Error -->
155-
<!-- <Rule Id="SX1309S" Action="Error" /> -->
142+
<!-- <Rule Id="SA1643" Action="Error" /> -->
143+
<!-- <Rule Id="SA1644" Action="Error" /> -->
144+
<!-- <Rule Id="SA1645" Action="Error" /> -->
145+
<!-- <Rule Id="SA1646" Action="Error" /> -->
146+
<!-- <Rule Id="SA1647" Action="Error" /> -->
147+
<!-- <Rule Id="SA1648" Action="Error" /> -->
148+
<Rule Id="SA1649" Action="Warning" /> <!-- @ Error -->
149+
<!-- <Rule Id="SA1650" Action="Error" /> -->
150+
<!-- <Rule Id="SA1651" Action="Error" /> -->
151+
<!-- <Rule Id="SX1101" Action="Error" /> -->
152+
<Rule Id="SX1309" Action="Warning" /> <!-- @ Error -->
153+
<!-- <Rule Id="SX1309S" Action="Error" /> -->
156154
</Rules>
157155
</RuleSet>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Developed by Softeq Development Corporation
2+
// http://www.softeq.com
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
[assembly: SuppressMessage(
7+
"Reliability",
8+
"CA2007:Consider calling ConfigureAwait on the awaited task",
9+
Justification = "Allowed for playground project")]
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Developed by Softeq Development Corporation
2+
// http://www.softeq.com
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
[assembly: SuppressMessage(
7+
"Reliability",
8+
"CA2007:Consider calling ConfigureAwait on the awaited task",
9+
Justification = "Allowed for playground project")]

Diff for: samples/Playground/Playground/GlobalSuppressions.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Developed by Softeq Development Corporation
2+
// http://www.softeq.com
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
[assembly: SuppressMessage(
7+
"Reliability",
8+
"CA2007:Consider calling ConfigureAwait on the awaited task",
9+
Justification = "Allowed for playground project")]

0 commit comments

Comments
 (0)