Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mavasani committed Apr 19, 2021
1 parent 500735c commit de17f29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,16 @@ protected static DiagnosticDescriptor CreateDescriptorWithId(
customTags: DiagnosticCustomTags.Create(isUnnecessary, isConfigurable, enforceOnBuild));
#pragma warning restore RS0030 // Do not used banned APIs

// Code style analyzers should not run on generated code, unless explicitly required by the analyzer.
protected virtual GeneratedCodeAnalysisFlags GeneratedCodeAnalysisFlags => GeneratedCodeAnalysisFlags.None;
/// <summary>
/// Flag indicating whether or not analyzer should receive analysis callbacks for generated code.
/// By default, code style analyzers should not run on generated code, so the value is false.
/// </summary>
protected virtual bool ReceiveAnalysisCallbacksForGeneratedCode => false;

public sealed override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags);
var flags = ReceiveAnalysisCallbacksForGeneratedCode ? GeneratedCodeAnalysisFlags.Analyze : GeneratedCodeAnalysisFlags.None;
context.ConfigureGeneratedCodeAnalysis(flags);
context.EnableConcurrentExecution();

InitializeWorker(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public MakeFieldReadonlyDiagnosticAnalyzer()
public override DiagnosticAnalyzerCategory GetAnalyzerCategory() => DiagnosticAnalyzerCategory.SemanticDocumentAnalysis;

// We need to analyze generated code to get callbacks for read/writes to non-generated members in generated code.
protected override GeneratedCodeAnalysisFlags GeneratedCodeAnalysisFlags => GeneratedCodeAnalysisFlags.Analyze;
protected override bool ReceiveAnalysisCallbacksForGeneratedCode => true;

protected override void InitializeWorker(AnalysisContext context)
{
Expand Down

0 comments on commit de17f29

Please sign in to comment.