Skip to content

Commit 034d8a4

Browse files
committed
Fix analyzers not running after generators
1 parent 0bf8edd commit 034d8a4

File tree

7 files changed

+19
-15
lines changed

7 files changed

+19
-15
lines changed

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/Diagnostics/Analyzers/ExplicitPropertyMetadataTypeAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public sealed class ExplicitPropertyMetadataTypeAnalyzer : DiagnosticAnalyzer
2727
/// <inheritdoc/>
2828
public override void Initialize(AnalysisContext context)
2929
{
30-
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
30+
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
3131
context.EnableConcurrentExecution();
3232

3333
context.RegisterCompilationStartAction(static context =>

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/Diagnostics/Analyzers/InvalidPropertyDefaultValueCallbackTypeAnalyzer.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public sealed class InvalidPropertyDefaultValueCallbackTypeAnalyzer : Diagnostic
2929
/// <inheritdoc/>
3030
public override void Initialize(AnalysisContext context)
3131
{
32-
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
32+
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
3333
context.EnableConcurrentExecution();
3434

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

4040
context.RegisterSymbolAction(context =>
4141
{
42-
IPropertySymbol propertySymbol = (IPropertySymbol)context.Symbol;
42+
// Ensure that we have some target property to analyze (also skip implementation parts)
43+
if (context.Symbol is not IPropertySymbol { PartialDefinitionPart: null } propertySymbol)
44+
{
45+
return;
46+
}
4347

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

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/Diagnostics/Analyzers/InvalidPropertyDefaultValueTypeAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public sealed class InvalidPropertyDefaultValueTypeAnalyzer : DiagnosticAnalyzer
2828
/// <inheritdoc/>
2929
public override void Initialize(AnalysisContext context)
3030
{
31-
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
31+
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
3232
context.EnableConcurrentExecution();
3333

3434
context.RegisterCompilationStartAction(static context =>
@@ -39,7 +39,7 @@ public override void Initialize(AnalysisContext context)
3939
context.RegisterOperationAction(context =>
4040
{
4141
// We only care about attributes on properties
42-
if (context.ContainingSymbol is not IPropertySymbol propertySymbol)
42+
if (context.ContainingSymbol is not IPropertySymbol { PartialDefinitionPart: null } propertySymbol)
4343
{
4444
return;
4545
}

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/Diagnostics/Analyzers/InvalidPropertyForwardedAttributeDeclarationAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public sealed class InvalidPropertyForwardedAttributeDeclarationAnalyzer : Diagn
3131
/// <inheritdoc/>
3232
public override void Initialize(AnalysisContext context)
3333
{
34-
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
34+
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
3535
context.EnableConcurrentExecution();
3636

3737
context.RegisterCompilationStartAction(static context =>

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/Diagnostics/Analyzers/InvalidPropertyNullableAnnotationAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public sealed class InvalidPropertyNullableAnnotationAnalyzer : DiagnosticAnalyz
2929
/// <inheritdoc/>
3030
public override void Initialize(AnalysisContext context)
3131
{
32-
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
32+
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
3333
context.EnableConcurrentExecution();
3434

3535
context.RegisterCompilationStartAction(static context =>
@@ -46,7 +46,7 @@ public override void Initialize(AnalysisContext context)
4646
context.RegisterSymbolAction(context =>
4747
{
4848
// Validate that we have a property that is of some type that could potentially become 'null'
49-
if (context.Symbol is not IPropertySymbol { Type.IsValueType: false, NullableAnnotation: not NullableAnnotation.None } propertySymbol)
49+
if (context.Symbol is not IPropertySymbol { PartialDefinitionPart: null, Type.IsValueType: false, NullableAnnotation: not NullableAnnotation.None } propertySymbol)
5050
{
5151
return;
5252
}

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/Diagnostics/Analyzers/PropertyDeclarationWithPropertyNameSuffixAnalyzer.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public sealed class PropertyDeclarationWithPropertyNameSuffixAnalyzer : Diagnost
2323
/// <inheritdoc/>
2424
public override void Initialize(AnalysisContext context)
2525
{
26-
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
26+
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
2727
context.EnableConcurrentExecution();
2828

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

3434
context.RegisterSymbolAction(context =>
3535
{
36-
IPropertySymbol propertySymbol = (IPropertySymbol)context.Symbol;
36+
// Ensure that we have some target property to analyze (also skip implementation parts)
37+
if (context.Symbol is not IPropertySymbol { PartialDefinitionPart: null } propertySymbol)
38+
{
39+
return;
40+
}
3741

3842
// We only want to lookup the attribute if the property name actually ends with the 'Property' suffix
3943
if (!propertySymbol.Name.EndsWith("Property"))

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/Diagnostics/Analyzers/UnsupportedCSharpLanguageVersionAnalyzer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ public override void Initialize(AnalysisContext context)
4444

4545
context.RegisterSymbolAction(context =>
4646
{
47-
// Ensure that we have some target property to analyze (also skip implementation parts)
48-
if (context.Symbol is not IPropertySymbol { PartialDefinitionPart: null } propertySymbol)
49-
{
50-
return;
51-
}
47+
IPropertySymbol propertySymbol = (IPropertySymbol)context.Symbol;
5248

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

0 commit comments

Comments
 (0)