Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba45963

Browse files
authored
Merge pull request #964 from CommunityToolkit/dev/fix-attribute-target-suppression
Fix suppressions for custom attribute targets
2 parents cb478f1 + d52dec9 commit ba45963

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/Suppressors/ObservablePropertyAttributeWithSupportedTargetDiagnosticSuppressor.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,16 @@ public override void ReportSuppressions(SuppressionAnalysisContext context)
5555
semanticModel.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservablePropertyAttribute") is INamedTypeSymbol observablePropertySymbol &&
5656
fieldSymbol.HasAttributeWithType(observablePropertySymbol))
5757
{
58-
context.ReportSuppression(Suppression.Create(PropertyAttributeListForObservablePropertyField, diagnostic));
58+
// Emit the right suppression based on the attribute modifier. For 'property:', Roslyn
59+
// will emit the 'CS0657' warning, whereas for 'get:' or 'set:', it will emit 'CS0658'.
60+
if (attributeTarget.Identifier.IsKind(SyntaxKind.PropertyKeyword))
61+
{
62+
context.ReportSuppression(Suppression.Create(PropertyAttributeListForObservablePropertyField, diagnostic));
63+
}
64+
else
65+
{
66+
context.ReportSuppression(Suppression.Create(PropertyAttributeListForObservablePropertyFieldAccessors, diagnostic));
67+
}
5968
}
6069
}
6170
}

0 commit comments

Comments
 (0)