Apply the provider access rule to Razor markup as well

This commit is contained in:
Thorsten Sommer 2026-08-12 20:43:06 +02:00
parent 494e48ddd3
commit 292b52ddcb
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -34,7 +34,12 @@ public sealed class ProviderAccessAnalyzer : DiagnosticAnalyzer
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
//
// We analyze generated code as well, because Razor markup ends up in generated files. Without
// this, any `ConfigurationData.Providers` access written directly in a `.razor` file would
// bypass this rule entirely. The Razor compiler maps the diagnostic back to the `.razor` line:
//
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.EnableConcurrentExecution();
context.RegisterSyntaxNodeAction(this.AnalyzeMemberAccess, SyntaxKind.SimpleMemberAccessExpression);
}