Skip to content

Commit

Permalink
Fix analyzers not running after generators
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Jan 2, 2025
1 parent 0bf8edd commit 034d8a4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed class ExplicitPropertyMetadataTypeAnalyzer : DiagnosticAnalyzer
/// <inheritdoc/>
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.EnableConcurrentExecution();

context.RegisterCompilationStartAction(static context =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public sealed class InvalidPropertyDefaultValueCallbackTypeAnalyzer : Diagnostic
/// <inheritdoc/>
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.EnableConcurrentExecution();

context.RegisterCompilationStartAction(static context =>
Expand All @@ -39,7 +39,11 @@ public override void Initialize(AnalysisContext context)

context.RegisterSymbolAction(context =>
{
IPropertySymbol propertySymbol = (IPropertySymbol)context.Symbol;
// Ensure that we have some target property to analyze (also skip implementation parts)
if (context.Symbol is not IPropertySymbol { PartialDefinitionPart: null } propertySymbol)
{
return;
}

// If the property is not using '[GeneratedDependencyProperty]', there's nothing to do
if (!propertySymbol.TryGetAttributeWithAnyType(generatedDependencyPropertyAttributeSymbols, out AttributeData? attributeData))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed class InvalidPropertyDefaultValueTypeAnalyzer : DiagnosticAnalyzer
/// <inheritdoc/>
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.EnableConcurrentExecution();

context.RegisterCompilationStartAction(static context =>
Expand All @@ -39,7 +39,7 @@ public override void Initialize(AnalysisContext context)
context.RegisterOperationAction(context =>
{
// We only care about attributes on properties
if (context.ContainingSymbol is not IPropertySymbol propertySymbol)
if (context.ContainingSymbol is not IPropertySymbol { PartialDefinitionPart: null } propertySymbol)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public sealed class InvalidPropertyForwardedAttributeDeclarationAnalyzer : Diagn
/// <inheritdoc/>
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.EnableConcurrentExecution();

context.RegisterCompilationStartAction(static context =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public sealed class InvalidPropertyNullableAnnotationAnalyzer : DiagnosticAnalyz
/// <inheritdoc/>
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.EnableConcurrentExecution();

context.RegisterCompilationStartAction(static context =>
Expand All @@ -46,7 +46,7 @@ public override void Initialize(AnalysisContext context)
context.RegisterSymbolAction(context =>
{
// Validate that we have a property that is of some type that could potentially become 'null'
if (context.Symbol is not IPropertySymbol { Type.IsValueType: false, NullableAnnotation: not NullableAnnotation.None } propertySymbol)
if (context.Symbol is not IPropertySymbol { PartialDefinitionPart: null, Type.IsValueType: false, NullableAnnotation: not NullableAnnotation.None } propertySymbol)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed class PropertyDeclarationWithPropertyNameSuffixAnalyzer : Diagnost
/// <inheritdoc/>
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.EnableConcurrentExecution();

context.RegisterCompilationStartAction(static context =>
Expand All @@ -33,7 +33,11 @@ public override void Initialize(AnalysisContext context)

context.RegisterSymbolAction(context =>
{
IPropertySymbol propertySymbol = (IPropertySymbol)context.Symbol;
// Ensure that we have some target property to analyze (also skip implementation parts)
if (context.Symbol is not IPropertySymbol { PartialDefinitionPart: null } propertySymbol)
{
return;
}

// We only want to lookup the attribute if the property name actually ends with the 'Property' suffix
if (!propertySymbol.Name.EndsWith("Property"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ public override void Initialize(AnalysisContext context)

context.RegisterSymbolAction(context =>
{
// Ensure that we have some target property to analyze (also skip implementation parts)
if (context.Symbol is not IPropertySymbol { PartialDefinitionPart: null } propertySymbol)
{
return;
}
IPropertySymbol propertySymbol = (IPropertySymbol)context.Symbol;

// If the property is not using '[GeneratedDependencyProperty]', there's nothing to do
if (!propertySymbol.TryGetAttributeWithAnyType(generatedDependencyPropertyAttributeSymbols, out AttributeData? attributeData))
Expand Down

0 comments on commit 034d8a4

Please sign in to comment.