Skip to content

Harden analyzer precision and code-fix safety - #11

Merged
georgepwall1991 merged 7 commits into
masterfrom
codex/analyzer-hardening-sweep
Mar 16, 2026
Merged

Harden analyzer precision and code-fix safety#11
georgepwall1991 merged 7 commits into
masterfrom
codex/analyzer-hardening-sweep

Conversation

@georgepwall1991

Copy link
Copy Markdown
Owner

Summary

  • reduce analyzer noise by tightening DI003, DI011, and DI014 behavior to high-confidence cases
  • improve DI007 precision and align docs/sample output with current analyzer behavior
  • harden DI005, DI006, DI008, DI003, and DI009 code-fix behavior so unsafe or brittle actions are not offered

Verification

  • dotnet test DependencyInjection.Lifetime.Analyzers.sln

Only offer code fixes when the rewrite is structurally safe, and add regression coverage for code actions that must not appear.\n\nCo-authored-by: Codex <noreply@openai.com>
Stop warning on scoped-to-transient injections, align the documentation, and update DI003 code-fix expectations to match the higher-confidence rule scope.\n\nCo-authored-by: Codex <noreply@openai.com>
Recognize root providers assigned to members and later disposed in Dispose or DisposeAsync, including null-conditional dispose patterns, while keeping looser cleanup paths diagnostic.\n\nCo-authored-by: Codex <noreply@openai.com>
Allow hosted services and endpoint filter factories to inject service-provider abstractions without diagnostics, while preserving reports for ordinary application services.\n\nCo-authored-by: Codex <noreply@openai.com>
Extract the requested type from typeof(...) service-locator calls so DI007 reports the actual dependency instead of falling back to Object, and add regression coverage for the non-generic paths.\n\nCo-authored-by: Codex <noreply@openai.com>
Update DI011 documentation and sample warning counts to match current analyzer behavior, and pass dependency lifetimes through DI003 and DI009 diagnostics so their fixers stop parsing localized message text.\n\nCo-authored-by: Codex <noreply@openai.com>
Only offer the DI006 remove-static fix when the cached provider is not referenced from static contexts, and add regression coverage for static call sites that would otherwise be broken by the rewrite.\n\nCo-authored-by: Codex <noreply@openai.com>
@github-actions

Copy link
Copy Markdown
Contributor

Summary

Summary
Generated on: 03/16/2026 - 12:37:37
Coverage date: 03/16/2026 - 12:37:35
Parser: Cobertura
Assemblies: 1
Classes: 32
Files: 31
Line coverage: 85.7% (2913 of 3398)
Covered lines: 2913
Uncovered lines: 485
Coverable lines: 3398
Total lines: 8063
Branch coverage: 71.3% (1718 of 2408)
Covered branches: 1718
Total branches: 2408
Method coverage: Feature is only available for sponsors
Tag: 70_23143975970

Coverage

DependencyInjection.Lifetime.Analyzers - 85.7%
Name Line Branch
DependencyInjection.Lifetime.Analyzers 85.7% 71.3%
DependencyInjection.Lifetime.Analyzers.CodeFixes.DI001_ScopeMustBeDisposedC
odeFixProvider
86.3% 70%
DependencyInjection.Lifetime.Analyzers.CodeFixes.DI002_ScopeEscapeCodeFixPr
ovider
69.3% 33.3%
DependencyInjection.Lifetime.Analyzers.CodeFixes.DI003_CaptiveDependencyCod
eFixProvider
70.2% 42.1%
DependencyInjection.Lifetime.Analyzers.CodeFixes.DI005_AsyncScopeRequiredCo
deFixProvider
86.7% 73.3%
DependencyInjection.Lifetime.Analyzers.CodeFixes.DI006_StaticProviderCacheC
odeFixProvider
80.2% 71.6%
DependencyInjection.Lifetime.Analyzers.CodeFixes.DI008_DisposableTransientC
odeFixProvider
83.2% 57.5%
DependencyInjection.Lifetime.Analyzers.CodeFixes.DI009_OpenGenericLifetimeM
ismatchCodeFixProvider
74.2% 47%
DependencyInjection.Lifetime.Analyzers.CodeFixes.DI014_RootProviderNotDispo
sedCodeFixProvider
80.3% 61.5%
DependencyInjection.Lifetime.Analyzers.CodeFixes.MemberDeclarationSyntaxExt
ensions
57.1% 33.3%
DependencyInjection.Lifetime.Analyzers.DiagnosticDescriptors 100%
DependencyInjection.Lifetime.Analyzers.Infrastructure.ConstructorSelection 100% 85.7%
DependencyInjection.Lifetime.Analyzers.Infrastructure.OrderedRegistration 96.1%
DependencyInjection.Lifetime.Analyzers.Infrastructure.RegistrationCollector 82.2% 71.4%
DependencyInjection.Lifetime.Analyzers.Infrastructure.ServiceRegistration 100%
DependencyInjection.Lifetime.Analyzers.Infrastructure.WellKnownTypes 100% 85%
DependencyInjection.Lifetime.Analyzers.Resources 89.4% 46.8%
DependencyInjection.Lifetime.Analyzers.Rules.DI001_ScopeDisposalAnalyzer 90.5% 86.6%
DependencyInjection.Lifetime.Analyzers.Rules.DI002_ScopeEscapeAnalyzer 76.4% 62.8%
DependencyInjection.Lifetime.Analyzers.Rules.DI003_CaptiveDependencyAnalyze
r
92.4% 83.3%
DependencyInjection.Lifetime.Analyzers.Rules.DI004_UseAfterDisposeAnalyzer 80.9% 65.9%
DependencyInjection.Lifetime.Analyzers.Rules.DI005_AsyncDisposalAnalyzer 73.9% 60.7%
DependencyInjection.Lifetime.Analyzers.Rules.DI006_StaticProviderCacheAnaly
zer
95.7% 80%
DependencyInjection.Lifetime.Analyzers.Rules.DI007_ServiceLocatorAntiPatter
nAnalyzer
92.9% 82.8%
DependencyInjection.Lifetime.Analyzers.Rules.DI008_DisposableTransientAnaly
zer
91.6% 85.4%
DependencyInjection.Lifetime.Analyzers.Rules.DI009_OpenGenericLifetimeMisma
tchAnalyzer
86.8% 72.5%
DependencyInjection.Lifetime.Analyzers.Rules.DI010_ConstructorOverInjection
Analyzer
91.9% 88%
DependencyInjection.Lifetime.Analyzers.Rules.DI011_ServiceProviderInjection
Analyzer
95.4% 89.4%
DependencyInjection.Lifetime.Analyzers.Rules.DI012_ConditionalRegistrationM
isuseAnalyzer
95% 70.8%
DependencyInjection.Lifetime.Analyzers.Rules.DI013_ImplementationTypeMismat
chAnalyzer
100% 87.5%
DependencyInjection.Lifetime.Analyzers.Rules.DI014_RootProviderNotDisposedA
nalyzer
89.4% 82.7%
DependencyInjection.Lifetime.Analyzers.Rules.DI015_UnresolvableDependencyAn
alyzer
83.9% 66%
DependencyInjection.Lifetime.Analyzers.Rules.DI016_BuildServiceProviderMisu
seAnalyzer
93.1% 84%

@georgepwall1991
georgepwall1991 merged commit d6be8b1 into master Mar 16, 2026
1 check passed
@georgepwall1991
georgepwall1991 deleted the codex/analyzer-hardening-sweep branch March 16, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant