/roslyn-analyzers:roslyn-analyzersfrom roslyn-analyzers
Writes, reviews and tests Roslyn diagnostic analyzers, code fix providers and incremental source generators, including Microsoft.CodeAnalysis version pinning and analyzer NuGet packaging. Use for a DiagnosticAnalyzer, CodeFixProvider or IIncrementalGenerator, an analyzer test harness, or a generator that recomputes on every keystroke.
Ships in roslyn-analyzers. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
For projects that build analyzers, code fixes or generators (Microsoft.CodeAnalysis.CSharp references, IsRoslynComponent, [DiagnosticAnalyzer], [Generator]).
Not for: fixing analyzer warnings or tuning .editorconfig severities in application code (csharp), general MSBuild failures (msbuild), package versions outside the analyzer boundary (nuget).
Directory.Packages.props (central package management), the test framework, how diagnostic IDs are allocated, localization (.resx), release tracking (AnalyzerReleases.Shipped.md/Unshipped.md), and packaging. Keep established conventions unless they break a rule below.search_graph for DiagnosticAnalyzer subclasses, trace_path for callers) when the repo is indexed, else the C# language server (csharp-ls) or Grep.--filter vs Microsoft.Testing.Platform options; see dotnet-testing).IOperation. Register the narrowest OperationKind and read typed operations (IInvocationOperation, IObjectCreationOperation, IConversionOperation). Order of preference: operation actions, operation-block actions, symbol actions, compilation-start actions that register those, and syntax actions last.Compilation.GetSemanticModel inside a syntax-node callback; that repeats expensive work and usually means an operation action fits better.Compilation.GetTypeByMetadataName, then select members from the containing type by name and full signature. If a required type is absent, register no inner action. Compare with SymbolEqualityComparer.Default.Equals. When generic substitution doesn't matter, normalize types, properties, fields and events with OriginalDefinition, and methods with (method.ReducedFrom ?? method).OriginalDefinition; check type arguments separately when they matter.ToDisplayString() against a literal. Display strings vary with aliases, qualification and nullability.context.EnableConcurrentExecution(), make an explicit ConfigureGeneratedCodeAnalysis(...) choice, keep callbacks stateless, pass cancellation tokens, and never store compilations, symbols, operations, trees or semantic models in static fields.Microsoft.CodeAnalysis.Common/CSharp (never Workspaces). Code fixes live in their own project with the Workspaces packages.DiagnosticAnalyzer/CodeFixProvider with the Roslyn test harness, not through InternalsVisibleTo.IIncrementalGenerator, never ISourceGenerator (AsSourceGenerator() is only the generator-driver adapter, not a way to wrap an ISourceGenerator). Render output through a small writer such as assets/SourceWriter.cs for deterministic newlines, indentation and encoding.DiagnosticDescriptor following the repo's category, severity, localization and release-tracking conventions. Give it a HelpLinkUri that points at a real published page for that ID.SyntaxGenerator or typed syntax APIs, add Formatter.Annotation/Simplifier.Annotation where useful, give each action a stable equivalence key, and return WellKnownFixAllProviders.BatchFixer only when fixes never conflict.// KnownApis is the shared name catalog; HelpLinks builds the published docs URL for an ID.
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class AvoidBlockingAnalyzer : DiagnosticAnalyzer
{
public const string DiagnosticId = "LIB0001";
private static readonly DiagnosticDescriptor Rule = new(
DiagnosticId, "Avoid blocking calls", "Do not call '{0}'", "Usage",
DiagnosticSeverity.Warning, isEnabledByDefault: true,
helpLinkUri: HelpLinks.For(DiagnosticId));
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => [Rule];
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.RegisterCompilationStartAction(static start =>
{
if (start.Compilation.GetTypeByMetadataName(KnownApis.Task.FullName) is not { } taskType)
return;
IMethodSymbol? wait = taskType.GetMembers(KnownApis.Task.Wait).OfType<IMethodSymbol>()
.FirstOrDefault(m => m.Parameters.IsEmpty);
if (wait is null)
return;
start.RegisterOperationAction(ctx =>
{
var invocation = (IInvocationOperation)ctx.Operation;
IMethodSymbol target = (invocation.TargetMethod.ReducedFrom ?? invocation.TargetMethod).OriginalDefinition;
if (SymbolEqualityComparer.Default.Equals(target, wait))
ctx.ReportDiagnostic(Diagnostic.Create(Rule, invocation.Syntax.GetLocation(), target.Name));
}, OperationKind.Invocation);
});
}
}
Declare [DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)] only when the analysis and locations are truly language-neutral and both languages are tested.
SyntaxProvider.ForAttributeWithMetadataName (Roslyn 4.3.1+); otherwise CreateSyntaxProvider with a cheap syntactic predicate and semantic work only in the transform.EquatableArray-style collections). Never carry SyntaxNode, ISymbol, SemanticModel or Compilation past the transform.RegisterSourceOutput with the writer; emit stable hint names; report invalid input as diagnostics, never exceptions.netstandard2.0 and run inside the compiler host (VS, the SDK's csc, Rider). A newer Microsoft.CodeAnalysis or transitive System.Collections.Immutable/System.Reflection.Metadata than the host ships makes the analyzer fail to load (CS8032), often silently in the IDE.Microsoft.CodeAnalysis.Analyzers is a development-time package: keep it on the latest version with PrivateAssets="all"; it is not part of the pinned host baseline.RS1035 and related Microsoft.CodeAnalysis.Analyzers rules flag banned APIs (file I/O, Environment) in analyzers and generators: read inputs through AdditionalTextsProvider and AnalyzerConfigOptionsProvider instead.*.Testing.XUnit, .NUnit, .MSTest) and XUnitVerifier are obsolete; use the generic packages with DefaultVerifier.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub adminhead/claude-plugins --plugin roslyn-analyzers