csharp-analyzer-developer
Installation
SKILL.md
C# Analyzer and Code Fix Developer
This skill provides comprehensive guidance for developing Roslyn analyzers and code fix providers in the OpenRewrite C# project.
Project Structure and Placement
File Organization
- Analyzers: Place in
src/Rewrite.RoslynRecipe/project - Code Fix Providers: Place in
src/Rewrite.RoslynRecipe/project - Tests: Place in
tests/Rewrite.RoslynRecipe.Tests/ - Helper Utilities: Place in
src/Rewrite.RoslynRecipe/Helpers/
Naming Conventions
- Analyzers:
[Category][Action]Analyzer.cs(e.g.,NamingConventionAnalyzer.cs,ActionContextAccessorObsoleteAnalyzer.cs) - Code Fix Providers:
[Category][Action]CodeFixProvider.cs(e.g.,NamingConventionCodeFixProvider.cs) - Test Files:
[AnalyzerName]Tests.csand[CodeFixProviderName]Tests.cs - If analyzer targets an interface (such as
IActionContextAccessor), the analyzer name should drop theIfrom the prefix as that clashes with naming convention identying interfaces - an analyzer is not an interface. Instead, it should name it likeActionContextAccessorObsoleteAnalyzer. - Analyzers shall define
DiagnosticIdstarting with charactersOR(meaning OpenRewrite developed recipes). The next set of characters shall identify the target framework or package that the diagnostic is targeting. For example for recipes that help identify / fix issues when migration .NET framework versions, it would includeNETX. TheXis the roman numeral of the version 10 of .NET implying that the recipes targets migration to version 10. Roman numerals are used here as to not clash with the last digits of diagnostic id which are sequentially imported. The last number are 4 digits incrementing number for that specific issue for the target version. Full example for analyzer targeting issues in .NET 10:ORNETX0001.