Skip to content

Commit 5798dbc

Browse files
committed
Fix IDE suppression for new analyzer
1 parent d85bbf4 commit 5798dbc

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

CommunityToolkit.Mvvm.SourceGenerators/CommunityToolkit.Mvvm.SourceGenerators.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Suppressors\ObservablePropertyAttributeWithPropertyTargetDiagnosticSuppressor.cs" />
5656
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\DiagnosticDescriptors.cs" />
5757
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\DiagnosticExtensions.cs" />
58+
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\SuppressionDescriptors.cs" />
5859
<Compile Include="$(MSBuildThisFileDirectory)Extensions\AttributeDataExtensions.cs" />
5960
<Compile Include="$(MSBuildThisFileDirectory)Extensions\CompilationExtensions.cs" />
6061
<Compile Include="$(MSBuildThisFileDirectory)Extensions\HashCodeExtensions.cs" />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Microsoft.CodeAnalysis;
2+
3+
namespace CommunityToolkit.Mvvm.SourceGenerators.Diagnostics;
4+
5+
/// <summary>
6+
/// A container for all <see cref="SuppressionDescriptors"/> instances for suppressed diagnostics by analyzers in this project.
7+
/// </summary>
8+
internal static class SuppressionDescriptors
9+
{
10+
/// <summary>
11+
/// Gets a <see cref="SuppressionDescriptor"/> for a field using [ObservableProperty] with on attribute list targeting a property.
12+
/// </summary>
13+
public static readonly SuppressionDescriptor PropertyAttributeListForObservablePropertyField = new(
14+
id: "MVVMTKSPR0001",
15+
suppressedDiagnosticId: "CS0657",
16+
justification: "Fields using [ObservableProperty] can use [property:] attribute lists to forward attributes to the generated properties");
17+
}

CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/Suppressors/ObservablePropertyAttributeWithPropertyTargetDiagnosticSuppressor.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.CodeAnalysis.CSharp;
99
using Microsoft.CodeAnalysis.CSharp.Syntax;
1010
using Microsoft.CodeAnalysis.Diagnostics;
11+
using static CommunityToolkit.Mvvm.SourceGenerators.Diagnostics.SuppressionDescriptors;
1112

1213
namespace CommunityToolkit.Mvvm.SourceGenerators;
1314

@@ -30,14 +31,6 @@ namespace CommunityToolkit.Mvvm.SourceGenerators;
3031
[DiagnosticAnalyzer(LanguageNames.CSharp)]
3132
public sealed class ObservablePropertyAttributeWithPropertyTargetDiagnosticSuppressor : DiagnosticSuppressor
3233
{
33-
/// <summary>
34-
/// Gets a <see cref="SuppressionDescriptor"/> for a field using [ObservableProperty] with on attribute list targeting a property.
35-
/// </summary>
36-
private static readonly SuppressionDescriptor PropertyAttributeListForObservablePropertyField = new(
37-
id: "MVVMTKSPR0001",
38-
suppressedDiagnosticId: "CS0657",
39-
justification: "Fields using [ObservableProperty] can use [property:] attribute lists to forward attributes to the generated properties");
40-
4134
/// <inheritdoc/>
4235
public override ImmutableArray<SuppressionDescriptor> SupportedSuppressions => ImmutableArray.Create(PropertyAttributeListForObservablePropertyField);
4336

0 commit comments

Comments
 (0)