Skip to content
dotnet-roslyn-analyzers logo

Roslyn Analyzer Hooks

dotnet-roslyn-analyzers

Authors Roslyn analyzers. DiagnosticAnalyzer, CodeFixProvider, CodeRefactoring, multi-version.

rudironsoni/Synaxis0installs2stars

SKILL.md

Full skill instructions

Roslyn Analyzer Hooks

Overview

Comprehensive Roslyn analyzer integration for dotnet-agent-harness providing real-time code analysis through agent hooks and enforced quality gates via git hooks.

Architecture

Layer 1: Agent-Level Hooks (Real-time)

  • Trigger: Post-edit on .cs files
  • Execution: Async with 60s timeout
  • Scope: Single file analysis
  • Output: JSON with violations + skill recommendations

Layer 2: Git Hooks (Commit/​Push)

  • pre-commit: Staged files analysis + dotnet format
  • pre-push: Full solution build + tests + doc validation
  • Enforcement: Blocks on errors and warnings

Configuration

Environment Variables

# Skip all analyzer checks (default: false, analyzers run by default)
export DOTNET_AGENT_HARNESS_SKIP_ANALYZERS=true

# Configure timeout (default: 60 seconds)
export DOTNET_AGENT_HARNESS_ANALYZER_TIMEOUT=120

# Minimum severity to report (Error/​Warning/​Info)
export DOTNET_AGENT_HARNESS_ANALYZER_SEVERITY=Warning

# Execution mode (sync/​async)
export DOTNET_AGENT_HARNESS_ANALYZER_MODE=async

Project-Level (.editorconfig)

[*.cs]
# Enable all analyzers
dotnet_analyzer_diagnostic.severity = warning

# Category-based configuration
dotnet_analyzer_diagnostic.category-security.severity = error
dotnet_analyzer_diagnostic.category-performance.severity = warning

# Specific rule overrides
dotnet_diagnostic.CA2007.severity = suggestion  # ConfigureAwait
dotnet_diagnostic.CA1816.severity = error       # GC.SuppressFinalize

Analyzer Packages

Essential (Always Enabled)

  • Microsoft.CodeAnalysis.NetAnalyzers - Built-in .NET analyzers
  • Roslynator.Analyzers - Refactoring and code improvements
  • Roslynator.CodeAnalysis.Analyzers - Code analysis rules
  • Roslynator.Formatting.Analyzers - Formatting rules

Optional

  • StyleCop.Analyzers - Style consistency (enable/​disable via EnableStyleCop)
  • Meziantou.Analyzer - Performance analyzers (EnableMeziantouAnalyzer)

CI Only (High Performance Impact)

  • SonarAnalyzer.CSharp - Security and code smells (+522% build time)

Analyzer-to-Skill Routing

Analyzer CodeSkillDescription
CA2007dotnet-csharp-async-patternsDo not directly await a Task
CA2008dotnet-csharp-async-patternsTaskScheduler required
CA1816dotnet-gc-memoryGC.SuppressFinalize
CA2000dotnet-gc-memoryDispose objects before losing scope
CA1822dotnet-performance-patternsMark members as static
CA1860dotnet-performance-patternsAvoid Enumerable.Any()
CA2100dotnet-security-owaspSQL injection prevention
CA5350dotnet-security-owaspWeak cryptographic algorithms
CA1001dotnet-architecture-patternsIDisposable pattern
CA1063dotnet-architecture-patternsImplement IDisposable correctly

Full mappings in .rulesync/​analyzer-to-skill.json

Git Hooks Installation

Automatic (Recommended)

# Run setup script
bash .githooks/​setup.sh

Manual

# Copy hooks to .git/​hooks/
cp .githooks/​pre-commit .git/​hooks/
cp .githooks/​pre-push .git/​hooks/
chmod +x .git/​hooks/​pre-commit .git/​hooks/​pre-push

Bypass Hooks

# Skip analyzer checks for this commit
DOTNET_AGENT_HARNESS_SKIP_ANALYZERS=true git commit -m "message"

# Bypass all hooks (not recommended)
git commit --no-verify -m "message"

Performance Considerations

ConfigurationBuild Time ImpactWhen to Use
NetAnalyzers only+15%Development (default)
+ Roslynator+98%Development with refactoring
+ StyleCop+49%Style enforcement
Full Suite (CI)+522%CI/​CD pipelines only

Troubleshooting

Analysis Timeouts

Increase timeout:

export DOTNET_AGENT_HARNESS_ANALYZER_TIMEOUT=120

Memory Issues

For large solutions, disable heavy analyzers:

<PropertyGroup>
  <RunSonarAnalyzer>false</​RunSonarAnalyzer>
</​PropertyGroup>

False Positives

Disable specific rules in .editorconfig:

dotnet_diagnostic.CA1707.severity = none

References

More skills from rudironsoni

dotnet-project-analysis logo
rudironsoni/Synaxis

dotnet-project-analysis

Analyzes .NET solution layout and build config -- .sln, .csproj, CPM.

2 0
View
wiki-agents-md logo
rudironsoni/Synaxis

wiki-agents-md

Generates AGENTS.md files for coding agent context

2 0
View
wiki-architect logo
rudironsoni/Synaxis

wiki-architect

Analyzes repos and generates structured catalogues

2 0
View

Using AwesomeAssertions for fluent and readable test assertion skill. Used when writing clear assertions, comparing objects, validating collections, handling complex comparisons. Covers Should(), BeEquivalentTo(), Contain(), ThrowAsync() and complete API. Keywords: assertions, awesome assertions...

2 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View