Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RS1008 not reported on ISymbol fields of diagnostic analyzer #7196

Closed
Rekkonnect opened this issue Feb 16, 2024 · 1 comment · Fixed by #7197
Closed

RS1008 not reported on ISymbol fields of diagnostic analyzer #7196

Rekkonnect opened this issue Feb 16, 2024 · 1 comment · Fixed by #7197

Comments

@Rekkonnect
Copy link

Analyzer

Diagnostic ID: RS1008: Avoid storing per-compilation data into the fields of a diagnostic analyzer

Analyzer source

Microsoft.CodeAnalysis.CSharp.Analyzers 3.3.4

Describe the bug

The above diagnostic is not reported on field instances of type ISymbol, but it is correctly reported on other relevant types like IMethodSymbol, INamedTypeSymbol, Compilation, etc.

Example Code

Consider the following analyzer:

[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class TestAnalyzer : DiagnosticAnalyzer
{
    private ISymbol _symbol;

    public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
        => ImmutableArray<DiagnosticDescriptor>.Empty;

    public override void Initialize(AnalysisContext context)
    {
        context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.ReportDiagnostics);
        context.EnableConcurrentExecution();
    }
}

Expected behavior

A warning should be reported on the type of the field _symbol, like it would if the field's type was IMethodSymbol, INamedTypeSymbol, etc.

Actual behavior

The warning is not present.

@mpidash
Copy link
Contributor

mpidash commented Feb 17, 2024

Fields of type IOperation are also not reported.
It seems that the analyzer only checks if the field type implements IOperation or ISymbol, but not if it is an exact match.

I will prepare a PR for this issue.

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 a pull request may close this issue.

2 participants