
Static Analysis
- 8 installs
- 4 repo stars
- Updated June 18, 2026
- doubleslashse/claude-marketplace
Configure .NET analyzers, fix warnings, and enforce code standards using built-in and custom static analysis tools.
About
Covers configuring .NET analyzers, resolving warnings, and enforcing code standards. A developer uses it when setting up static analysis or improving code quality gates.
- Enables .NET SDK analyzers via project settings
- Fixes warnings and enforces standards
Static Analysis by the numbers
- 8 all-time installs (skills.sh)
- Ranked #839 of 1,352 Code Review & Quality skills by installs in the Skillselion catalog
- Data as of Jul 29, 2026 (Skillselion catalog sync)
npx skills add https://github.com/doubleslashse/claude-marketplace --skill static-analysisAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 8 |
|---|---|
| repo stars | ★ 4 |
| Last updated | June 18, 2026 |
| Repository | doubleslashse/claude-marketplace ↗ |
What it does
Configure .NET analyzers, fix warnings, and enforce code standards using built-in and custom static analysis tools.
Files
.NET Static Analysis
Built-in Analyzers
.NET Analyzers
.NET SDK includes analyzers for code quality and style. Enable in project file:
<PropertyGroup>
<!-- Enable all .NET analyzers -->
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<!-- Analysis level (latest, 8.0, 7.0, etc.) -->
<AnalysisLevel>latest</AnalysisLevel>
<!-- Analysis mode: Default, Minimum, Recommended, All -->
<AnalysisMode>Recommended</AnalysisMode>
</PropertyGroup>Analysis Categories
| Category | Prefix | Focus |
|---|---|---|
| Design | CA1xxx | API design guidelines |
| Globalization | CA2xxx | Internationalization |
| Performance | CA18xx | Performance optimizations |
| Security | CA2xxx, CA3xxx | Security vulnerabilities |
| Usage | CA2xxx | Correct API usage |
| Naming | CA17xx | Naming conventions |
| Reliability | CA2xxx | Error handling, resources |
Running Analysis
With Build
# Build with analyzers (default)
dotnet build
# Ensure analyzers run
dotnet build /p:RunAnalyzersDuringBuild=true
# Treat warnings as errors
dotnet build /p:TreatWarningsAsErrors=true
# Run only analyzers (no compile)
dotnet build /p:RunAnalyzers=true /p:RunCodeAnalysis=trueAs Separate Step
# Format check (style only)
dotnet format --verify-no-changes
# Format and fix
dotnet format
# Analyze specific project
dotnet build src/MyApp/MyApp.csproj /p:TreatWarningsAsErrors=trueConfiguring Rules
EditorConfig
# .editorconfig
root = true
[*.cs]
# Naming conventions
dotnet_naming_rule.private_fields_should_be_camel_case.severity = warning
dotnet_naming_rule.private_fields_should_be_camel_case.symbols = private_fields
dotnet_naming_rule.private_fields_should_be_camel_case.style = camel_case_style
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
dotnet_naming_style.camel_case_style.capitalization = camel_case
dotnet_naming_style.camel_case_style.required_prefix = _
# Code style
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_expression_bodied_methods = when_on_single_line:suggestion
csharp_prefer_braces = true:warning
# Analyzer rules
dotnet_diagnostic.CA1062.severity = warning # Validate arguments
dotnet_diagnostic.CA2007.severity = none # Don't require ConfigureAwait
dotnet_diagnostic.IDE0044.severity = warning # Make field readonlyGlobalAnalyzerConfig
# .globalconfig
is_global = true
# Apply to all projects
dotnet_diagnostic.CA1062.severity = warning
dotnet_diagnostic.CA2000.severity = errorProject-Level
<PropertyGroup>
<!-- Suppress in entire project -->
<NoWarn>$(NoWarn);CA1062;CA2007</NoWarn>
<!-- Treat specific as error -->
<WarningsAsErrors>$(WarningsAsErrors);CA2000</WarningsAsErrors>
</PropertyGroup>Suppressing Warnings
Code-Level Suppression
// Suppress on member
[SuppressMessage("Design", "CA1062:Validate arguments",
Justification = "Validated by framework")]
public void Process(Request request) { }
// Suppress on line
#pragma warning disable CA1062
public void Process(Request request) { }
#pragma warning restore CA1062
// Suppress all in file
[assembly: SuppressMessage("Design", "CA1062")]Global Suppressions
// GlobalSuppressions.cs
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Design", "CA1062",
Scope = "namespaceanddescendants",
Target = "~N:MyApp.Controllers")]Common Analyzer Rules
CA1062 - Validate Arguments
// Warning: parameter 'request' is never validated
public void Process(Request request)
{
request.Execute(); // CA1062
}
// Fixed
public void Process(Request request)
{
ArgumentNullException.ThrowIfNull(request);
request.Execute();
}CA2007 - ConfigureAwait
// Warning in library code
await SomeAsync(); // CA2007
// Fixed
await SomeAsync().ConfigureAwait(false);
// Or suppress in application code (.editorconfig)
dotnet_diagnostic.CA2007.severity = noneCA1822 - Mark Members Static
// Warning: can be static
public int Calculate(int x) => x * 2; // CA1822
// Fixed
public static int Calculate(int x) => x * 2;IDE0044 - Make Field Readonly
// Warning
private int _value; // IDE0044
// Fixed
private readonly int _value;CA2000 - Dispose Objects
// Warning: not disposed
public void Process()
{
var stream = new FileStream("file.txt", FileMode.Open);
} // CA2000
// Fixed
public void Process()
{
using var stream = new FileStream("file.txt", FileMode.Open);
}dotnet format
Check Formatting
# Check without changes
dotnet format --verify-no-changes
# Check specific files
dotnet format --include "src/**/*.cs" --verify-no-changes
# Exclude paths
dotnet format --exclude "**/Migrations/**"Apply Fixes
# Fix all issues
dotnet format
# Fix style issues only
dotnet format style
# Fix analyzers only
dotnet format analyzers
# Fix specific severity
dotnet format --severity warnTargeting
# Whitespace only
dotnet format whitespace
# Style and analyzers
dotnet format style
dotnet format analyzers
# Specific diagnostics
dotnet format --diagnostics CA1062 IDE0044Third-Party Analyzers
StyleCop.Analyzers
dotnet add package StyleCop.Analyzers# .editorconfig
# Configure StyleCop rules
dotnet_diagnostic.SA1101.severity = none # Prefix local calls with this
dotnet_diagnostic.SA1200.severity = none # Using directives placement
dotnet_diagnostic.SA1633.severity = none # File headerRoslynator
dotnet add package Roslynator.AnalyzersSonarAnalyzer
dotnet add package SonarAnalyzer.CSharpCI Integration
Quality Gate Script
#!/bin/bash
# Run build with analysis
dotnet build --no-restore /p:TreatWarningsAsErrors=true
# Check format
dotnet format --verify-no-changes
# Exit with error if any issues
exit $?Azure DevOps
- task: DotNetCoreCLI@2
displayName: 'Build with Analysis'
inputs:
command: build
arguments: '/p:TreatWarningsAsErrors=true'See analyzers.md for detailed analyzer configurations.
.NET Analyzer Reference
Microsoft.CodeAnalysis.NetAnalyzers
Built into .NET SDK. Configure in project:
<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest-all</AnalysisLevel>
</PropertyGroup>Key Rules
Design (CA1xxx)
| Rule | Description | Severity |
|---|---|---|
| CA1002 | Don't expose generic lists | Warning |
| CA1014 | Mark assemblies with CLSCompliant | Info |
| CA1024 | Use properties where appropriate | Info |
| CA1031 | Don't catch general exceptions | Warning |
| CA1032 | Implement standard exception constructors | Warning |
| CA1040 | Avoid empty interfaces | Warning |
| CA1051 | Don't declare visible instance fields | Warning |
| CA1062 | Validate arguments of public methods | Warning |
Performance (CA18xx)
| Rule | Description | Severity |
|---|---|---|
| CA1802 | Use literals where appropriate | Info |
| CA1805 | Don't initialize unnecessarily | Info |
| CA1812 | Avoid uninstantiated internal classes | Warning |
| CA1822 | Mark members as static | Info |
| CA1825 | Avoid zero-length array allocations | Info |
| CA1827 | Don't use Count/Length when Any | Warning |
| CA1829 | Use Length/Count property | Warning |
| CA1836 | Prefer IsEmpty over Count | Info |
Security (CA2xxx, CA3xxx, CA5xxx)
| Rule | Description | Severity |
|---|---|---|
| CA2100 | Review SQL queries for vulnerabilities | Warning |
| CA2119 | Seal methods that satisfy private interfaces | Warning |
| CA2200 | Rethrow to preserve stack details | Warning |
| CA2213 | Disposable fields should be disposed | Warning |
| CA3001 | Review code for SQL injection | Warning |
| CA3003 | Review code for file path injection | Warning |
| CA5350 | Don't use weak crypto algorithms | Warning |
| CA5351 | Don't use broken crypto algorithms | Error |
Reliability (CA2xxx)
| Rule | Description | Severity |
|---|---|---|
| CA2000 | Dispose objects before losing scope | Warning |
| CA2007 | Consider calling ConfigureAwait | Warning |
| CA2008 | Don't create tasks without passing TaskScheduler | Warning |
| CA2012 | Use ValueTasks correctly | Warning |
| CA2016 | Forward CancellationToken | Info |
StyleCop.Analyzers
dotnet add package StyleCop.Analyzers --version 1.2.0-beta.556Configuration (stylecop.json)
{
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"companyName": "MyCompany",
"documentInterfaces": true,
"documentExposedElements": true,
"documentInternalElements": false
},
"orderingRules": {
"usingDirectivesPlacement": "outsideNamespace"
},
"namingRules": {
"allowCommonHungarianPrefixes": false
}
}
}Key Rules
Documentation (SA16xx)
| Rule | Description | Default |
|---|---|---|
| SA1600 | Elements should be documented | Warning |
| SA1601 | Partial elements should be documented | Warning |
| SA1633 | File should have header | Warning |
Layout (SA15xx)
| Rule | Description | Default |
|---|---|---|
| SA1500 | Braces should not be omitted | Warning |
| SA1501 | Statement should not be on single line | Warning |
| SA1502 | Element should not be on single line | Warning |
Ordering (SA12xx)
| Rule | Description | Default |
|---|---|---|
| SA1200 | Using directives placement | Warning |
| SA1201 | Element order | Warning |
| SA1202 | Element order by access | Warning |
Naming (SA13xx)
| Rule | Description | Default |
|---|---|---|
| SA1300 | Element should begin with upper case | Warning |
| SA1302 | Interface names should begin with I | Warning |
| SA1309 | Field names should not begin with underscore | Warning |
Common Overrides (.editorconfig)
# Disable file headers
dotnet_diagnostic.SA1633.severity = none
# Allow underscore prefix for private fields
dotnet_diagnostic.SA1309.severity = none
# Allow using inside namespace
dotnet_diagnostic.SA1200.severity = none
# Don't require this. prefix
dotnet_diagnostic.SA1101.severity = noneRoslynator
dotnet add package Roslynator.Analyzers
dotnet add package Roslynator.Formatting.Analyzers
dotnet add package Roslynator.CodeAnalysis.AnalyzersKey Rules
Code Analysis (RCS1xxx)
| Rule | Description |
|---|---|
| RCS1001 | Add braces |
| RCS1003 | Add braces to if-else |
| RCS1018 | Add accessibility modifiers |
| RCS1036 | Remove redundant empty line |
| RCS1037 | Remove trailing whitespace |
| RCS1038 | Remove empty statement |
| RCS1049 | Simplify boolean comparison |
| RCS1058 | Use compound assignment |
| RCS1061 | Merge if statement with nested if |
| RCS1073 | Convert if to return statement |
| RCS1077 | Optimize LINQ method call |
| RCS1085 | Use auto-implemented property |
| RCS1118 | Mark local variable as const |
| RCS1123 | Add parentheses when necessary |
| RCS1138 | Add summary to documentation |
| RCS1139 | Add summary element to documentation |
| RCS1140 | Add exception to documentation |
| RCS1146 | Use conditional access |
| RCS1155 | Use StringComparison |
| RCS1163 | Unused parameter |
| RCS1168 | Parameter name differs |
| RCS1169 | Make field read-only |
| RCS1170 | Use read-only auto-implemented property |
| RCS1175 | Unused this parameter |
| RCS1181 | Convert comment to documentation comment |
| RCS1192 | Unnecessary usage of verbatim string literal |
| RCS1197 | Optimize StringBuilder.Append/AppendLine |
| RCS1202 | Avoid NullReferenceException |
| RCS1206 | Use conditional access instead of conditional expression |
| RCS1214 | Unnecessary interpolated string |
| RCS1220 | Use pattern matching instead of combination of 'is' and cast |
| RCS1225 | Make class sealed |
| RCS1229 | Use async/await when necessary |
| RCS1236 | Use exception filter |
| RCS1241 | Implement non-generic counterpart |
| RCS1246 | Use element access |
SonarAnalyzer.CSharp
dotnet add package SonarAnalyzer.CSharpKey Security Rules
| Rule | Description |
|---|---|
| S2068 | Credentials should not be hard-coded |
| S2077 | SQL queries should be parameterized |
| S2078 | LDAP queries should be parameterized |
| S2092 | Cookies should be secure |
| S3330 | Cookies should be "HttpOnly" |
| S5042 | Expanding archive files is security sensitive |
| S5122 | CORS allows all domains |
| S5131 | XSS vulnerabilities |
Recommended Configuration
Minimal (Start Here)
<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest-recommended</AnalysisLevel>
</PropertyGroup>Comprehensive
<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest-all</AnalysisLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="4.6.0" PrivateAssets="all" />
</ItemGroup>.editorconfig Base
root = true
[*.cs]
# Core rules
dotnet_diagnostic.CA1062.severity = warning
dotnet_diagnostic.CA2000.severity = warning
dotnet_diagnostic.CA2007.severity = none # Not needed in apps
dotnet_diagnostic.CA1822.severity = suggestion
# StyleCop overrides
dotnet_diagnostic.SA1101.severity = none # No this. prefix required
dotnet_diagnostic.SA1200.severity = none # Using placement flexible
dotnet_diagnostic.SA1309.severity = none # Allow _privateField
dotnet_diagnostic.SA1633.severity = none # No file headers required