Notes on the repository¶
There are two solutions in the roslyn-analyzers repository:
RoslynAnalyzers.sln¶
The main solution with the analyzers, unit tests and debug project:
- The code for the analyzers and code fix providers is at Source/RoslynAnalyzers/Analyzers.
- The code for the unit tests is at Tests/Analyzers.Tests.
- The debug project is at Debug/DebugAnalyzers.Vsix.
The analyzers and respective code fix providers are grouped under the same folder. Not all analyzers have a code fix provider.
All the tests use either the CSharpDiagnosticAnalyzerTest or the CSharpCodeFixProviderTest as the base class depending if it’s a test for an analyzer or for a code fix provider.
The classes inside Tests/Analyzers.Tests/_TestEnvironment/Roslyn are a refactored version of the classes provided by the default template for unit testing analyzers and code fix providers.
To debug the analyzers set the project DebugAnalyzers.Vsix as the startup project and follow the instructions here.
Note
Because I used the Tuple syntax from C# 7.0 on the analyzers project I had to do the following for the unit test project to work:
- Update the NuGet package System.ValueTuple to 4.3.1 on the unit test project.
- Install the Nuget package System.Composition 1.0.31 on the unit test project.
RoslynAnalyzersTestData.sln¶
Contains test cases to be used in the unit test project.
It is also used when debugging the analyzers because once you run the DebugAnalyzers.Vsix you can chose to open this solution with the experimental version of Visual Studio and then open the classes that should or should not trigger the analyzer. While doing this you can set breakpoints and debug the behavior of the analyzer/code fix provider.
Documentation¶
The documentation for the repository is at the Docs folder.
Read this to understand how the documentation was created and how you can build it.
Analyzers in the repository¶
Here is the list of the analyzers present in the RoslynAnalyzers.sln.
Note
The analyzers created in the roslyn-analyzers repository were tested on Visual Studio 2017 15.2 on different project types:
- .NET Framework 4.6.2
- .NET Core 1.1
- .NET Standard 1.4
Name | Identifier | Title | Default action |
---|---|---|---|
AsyncMethodNamesShouldBeSuffixedWithAsync | ASYNC0001 | Asynchronous method names should end with Async | Warning |
NonAsyncMethodNamesShouldNotBeSuffixedWithAsync | ASYNC0002 | Non asynchronous method names should end with Async | Warning |
AvoidAsyncVoidMethods | ASYNC0003 | Avoid void returning asynchronous method | Warning |
UseConfigureAwaitFalse | ASYNC0004 | Use ConfigureAwait(false) on await expression | Warning |
SetClassAsSealed | CLASS0001 | Seal class | Warning |
DefaultLabelShouldBeTheLast | ENUM0001 | Default switch label | Warning |
MergeSwitchSectionsWithEquivalentContent | ENUM0002 | Merge switch sections | Warning |
SwitchOnEnumMustHandleAllCases | ENUM0003 | Populate switch | Warning |
DoNotReturnNull | RETURN0001 | Do not return null | Warning |