-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New analyzers: Dictionary keys & async void + NUnit (#278)
* Start of dictionary key analyzer * Tweaks and fixes * C# 12 * Enable nullable * Types test and ability to better customize compilation on tests * ISet is in a different assembly in net4x * Switch to NUnit to match every other repo * And then add NUnit analyzers and update to 4.0.1 * Change title to be more exact about what we're analyzing * Fix duplicated diagnostic id by moving StructuredLoggingWithRepeatedToken to 26 since Core already has a PR with pragmas for PS0025 * Add async void analyzer * Tweaks * Extended the message a bit * Update src/Particular.Analyzers/DiagnosticDescriptors.cs Co-authored-by: Brandon Ording <bording@gmail.com> --------- Co-authored-by: Brandon Ording <bording@gmail.com>
- Loading branch information
1 parent
7f80568
commit 9e46118
Showing
45 changed files
with
971 additions
and
494 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
namespace Particular.Analyzers.Tests | ||
{ | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Particular.Analyzers.Tests.Helpers; | ||
|
||
public class AsyncVoidAnalyzerTests : AnalyzerTestFixture<AsyncVoidAnalyzer> | ||
{ | ||
[Test] | ||
public Task NoAsyncVoid() | ||
{ | ||
var code = """ | ||
public class Foo | ||
{ | ||
async void [|Bad1|]() { await Task.Delay(1); } | ||
private async void [|Bad2|]() { await Task.Delay(1); } | ||
public async void [|Bad3|]() { await Task.Delay(1); } | ||
protected async void [|Bad4|]() { await Task.Delay(1); } | ||
static async void [|Bad5|]() { await Task.Delay(1); } | ||
static private async void [|Bad6|]() { await Task.Delay(1); } | ||
static public async void [|Bad7|]() { await Task.Delay(1); } | ||
static protected async void [|Bad8|]() { await Task.Delay(1); } | ||
async void [|Bad9|](string a, int b) { await Task.Delay(1); } | ||
|
||
async Task ReturnsTask1() { await Task.Delay(1); } | ||
private async Task ReturnsTask2() { await Task.Delay(1); } | ||
public async Task ReturnsTask3() { await Task.Delay(1); } | ||
protected async Task ReturnsTask4() { await Task.Delay(1); } | ||
static async Task ReturnsTask5() { await Task.Delay(1); } | ||
static private async Task ReturnsTask6() { await Task.Delay(1); } | ||
static public async Task ReturnsTask7() { await Task.Delay(1); } | ||
static protected async Task ReturnsTask8() { await Task.Delay(1); } | ||
async Task ReturnsTask9(string a, int b) { await Task.Delay(1); } | ||
|
||
async Task ReturnsValueTask1() { await Task.Delay(1); } | ||
private async Task ReturnsValueTask2() { await Task.Delay(1); } | ||
public async Task ReturnsValueTask3() { await Task.Delay(1); } | ||
protected async Task ReturnsValueTask4() { await Task.Delay(1); } | ||
static async Task ReturnsValueTask5() { await Task.Delay(1); } | ||
static private async Task ReturnsValueTask6() { await Task.Delay(1); } | ||
static public async Task ReturnsValueTask7() { await Task.Delay(1); } | ||
static protected async Task ReturnsValueTask8() { await Task.Delay(1); } | ||
async Task ReturnsValueTask9(string a, int b) { await Task.Delay(1); } | ||
|
||
public async Task RegularMethod() | ||
{ | ||
async void [|Local|]() => await Task.Delay(1); | ||
|
||
await Task.Delay(1); | ||
} | ||
} | ||
"""; | ||
|
||
return Assert(code, DiagnosticIds.AsyncVoid); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.