forked from DotNetAnalyzers/AsyncUsageAnalyzers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
169 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
## AvoidAsyncSuffix | ||
|
||
<table> | ||
<tr> | ||
<td>TypeName</td> | ||
<td>AvoidAsyncSuffix</td> | ||
</tr> | ||
<tr> | ||
<td>CheckId</td> | ||
<td>AvoidAsyncSuffix</td> | ||
</tr> | ||
<tr> | ||
<td>Category</td> | ||
<td>Naming Rules</td> | ||
</tr> | ||
</table> | ||
|
||
## Cause | ||
|
||
A non-Task-returning method is named with the suffix `Async`. | ||
|
||
## Rule description | ||
|
||
This diagnostic identifies methods which are not asynchronous according to the Task-based Asynchronous Pattern (TAP) by | ||
their signature, and reports a warning if the method name includes the suffix `Async`. | ||
|
||
## How to fix violations | ||
|
||
To fix a violation of this rule, remove the `Async` suffix from the method name or change the signature to return a | ||
`Task`. | ||
|
||
## How to suppress violations | ||
|
||
```csharp | ||
#pragma warning disable AvoidAsyncSuffix // Avoid Async suffix | ||
public int ThisIsNotAsync() | ||
#pragma warning restore AvoidAsyncSuffix // Avoid Async suffix | ||
{ | ||
return 0; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
## AvoidAsyncVoid | ||
|
||
<table> | ||
<tr> | ||
<td>TypeName</td> | ||
<td>AvoidAsyncVoid</td> | ||
</tr> | ||
<tr> | ||
<td>CheckId</td> | ||
<td>AvoidAsyncVoid</td> | ||
</tr> | ||
<tr> | ||
<td>Category</td> | ||
<td>Reliability Rules</td> | ||
</tr> | ||
</table> | ||
|
||
## Cause | ||
|
||
An asynchronous method has the return type `void`. | ||
|
||
## Rule description | ||
|
||
This diagnostic identifies code using `void`-returning `async` methods, and reports a warning. | ||
|
||
## How to fix violations | ||
|
||
To fix a violation of this rule, change the signature of the method to return a `Task` instead of `void`. | ||
|
||
## How to suppress violations | ||
|
||
```csharp | ||
#pragma warning disable AvoidAsyncVoid // Avoid async void | ||
private async void HandleSomeEvent(object sender, EventArgs e) | ||
#pragma warning restore AvoidAsyncVoid // Avoid async void | ||
{ | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
## UseAsyncSuffix | ||
|
||
<table> | ||
<tr> | ||
<td>TypeName</td> | ||
<td>UseAsyncSuffix</td> | ||
</tr> | ||
<tr> | ||
<td>CheckId</td> | ||
<td>UseAsyncSuffix</td> | ||
</tr> | ||
<tr> | ||
<td>Category</td> | ||
<td>Naming Rules</td> | ||
</tr> | ||
</table> | ||
|
||
## Cause | ||
|
||
A Task-returning method is named without the suffix `Async`. | ||
|
||
## Rule description | ||
|
||
This diagnostic identifies methods which are asynchronous according to the Task-based Asynchronous Pattern (TAP) by | ||
their signature, and reports a warning if the method name does not include the suffix `Async`. | ||
|
||
## How to fix violations | ||
|
||
To fix a violation of this rule, rename the method to include the `Async` suffix. | ||
|
||
## How to suppress violations | ||
|
||
```csharp | ||
#pragma warning disable UseAsyncSuffix // Use Async suffix | ||
public async Task<int> GetValue() | ||
#pragma warning restore UseAsyncSuffix // Use Async suffix | ||
{ | ||
return 0; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
## UseConfigureAwait | ||
|
||
<table> | ||
<tr> | ||
<td>TypeName</td> | ||
<td>UseConfigureAwait</td> | ||
</tr> | ||
<tr> | ||
<td>CheckId</td> | ||
<td>UseConfigureAwait</td> | ||
</tr> | ||
<tr> | ||
<td>Category</td> | ||
<td>Usage Rules</td> | ||
</tr> | ||
</table> | ||
|
||
## Cause | ||
|
||
A `Task` whose continuation behavior has not been configured is awaited. | ||
|
||
## Rule description | ||
|
||
The continuation behavior for a `Task` should be configured by calling `ConfigureAwait` prior to awaiting the task. This | ||
diagnostic is reported if an `await` expression is used on a `Task` that has not been configured. | ||
|
||
## How to fix violations | ||
|
||
To fix a violation of this rule, use `ConfigureAwait(false)` or `ConfigureAwait(true)` as appropriate for the context of | ||
the asynchronous operation. | ||
|
||
## How to suppress violations | ||
|
||
```csharp | ||
#pragma warning disable UseConfigureAwait // Use ConfigureAwait | ||
await Task.Delay(1000); | ||
#pragma warning restore UseConfigureAwait // Use ConfigureAwait | ||
``` |