Skip to content

Commit 889cc08

Browse files
committed
Fix consistency for 'new()' for diagnostics/suppressions
1 parent aa9df8a commit 889cc08

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ internal static class DiagnosticDescriptors
689689
/// Format: <c>"Using [ObservableProperty] on partial properties requires the C# language version to be set to 'preview', as support for the 'field' keyword is needed by the source generators to emit valid code (add <LangVersion>preview</LangVersion> to your .csproj/.props file)"</c>.
690690
/// </para>
691691
/// </summary>
692-
public static readonly DiagnosticDescriptor CSharpLanguageVersionIsNotPreviewForObservableProperty = new(
692+
public static readonly DiagnosticDescriptor CSharpLanguageVersionIsNotPreviewForObservableProperty = new DiagnosticDescriptor(
693693
id: "MVVMTK0041",
694694
title: "C# language version is not 'preview'",
695695
messageFormat: """Using [ObservableProperty] on partial properties requires the C# language version to be set to 'preview', as support for the 'field' keyword is needed by the source generators to emit valid code (add <LangVersion>preview</LangVersion> to your .csproj/.props file)""",
@@ -705,7 +705,7 @@ internal static class DiagnosticDescriptors
705705
/// Format: <c>"The field {0}.{1} using [ObservableProperty] can be converted to a partial property instead, which is recommended (doing so improves the developer experience and allows other generators and analyzers to correctly see the generated property as well)"</c>.
706706
/// </para>
707707
/// </summary>
708-
public static readonly DiagnosticDescriptor UseObservablePropertyOnPartialProperty = new(
708+
public static readonly DiagnosticDescriptor UseObservablePropertyOnPartialProperty = new DiagnosticDescriptor(
709709
id: UseObservablePropertyOnPartialPropertyId,
710710
title: "Prefer using [ObservableProperty] on partial properties",
711711
messageFormat: """The field {0}.{1} using [ObservableProperty] can be converted to a partial property instead, which is recommended (doing so improves the developer experience and allows other generators and analyzers to correctly see the generated property as well)""",
@@ -753,7 +753,7 @@ internal static class DiagnosticDescriptors
753753
/// Format: <c>"The field {0}.{1} using [ObservableProperty] will generate code that is not AOT compatible in WinRT scenarios (such as UWP XAML and WinUI 3 apps), and a partial property should be used instead (as it allows the CsWinRT generators to correctly produce the necessary WinRT marshalling code)"</c>.
754754
/// </para>
755755
/// </summary>
756-
public static readonly DiagnosticDescriptor WinRTObservablePropertyOnFieldsIsNotAotCompatible = new(
756+
public static readonly DiagnosticDescriptor WinRTObservablePropertyOnFieldsIsNotAotCompatible = new DiagnosticDescriptor(
757757
id: WinRTObservablePropertyOnFieldsIsNotAotCompatibleId,
758758
title: "Using [ObservableProperty] on fields is not AOT compatible for WinRT",
759759
messageFormat: """The field {0}.{1} using [ObservableProperty] will generate code that is not AOT compatible in WinRT scenarios (such as UWP XAML and WinUI 3 apps), and a partial property should be used instead (as it allows the CsWinRT generators to correctly produce the necessary WinRT marshalling code)""",
@@ -769,7 +769,7 @@ internal static class DiagnosticDescriptors
769769
/// Format: <c>"The method {0} using [RelayCommand] within a type also using [GeneratedBindableCustomProperty], which is not supported, and a manually declared command property should be used instead (the [GeneratedBindableCustomProperty] generator cannot see the generated command property that is produced by the MVVM Toolkit generator)"</c>.
770770
/// </para>
771771
/// </summary>
772-
public static readonly DiagnosticDescriptor WinRTRelayCommandIsNotGeneratedBindableCustomPropertyCompatible = new(
772+
public static readonly DiagnosticDescriptor WinRTRelayCommandIsNotGeneratedBindableCustomPropertyCompatible = new DiagnosticDescriptor(
773773
id: "MVVMTK0046",
774774
title: "Using [RelayCommand] is not compatible with [GeneratedBindableCustomProperty]",
775775
messageFormat: """The method {0} using [RelayCommand] within a type also using [GeneratedBindableCustomProperty], which is not supported, and a manually declared command property should be used instead (the [GeneratedBindableCustomProperty] generator cannot see the generated command property that is produced by the MVVM Toolkit generator)""",
@@ -785,7 +785,7 @@ internal static class DiagnosticDescriptors
785785
/// Format: <c>"The type {0} using [GeneratedBindableCustomProperty] is also using [ObservableProperty] on its declared (or inherited) field {1}.{2}: combining the two generators is not supported, and partial properties should be used instead (the [GeneratedBindableCustomProperty] generator cannot see the generated property that is produced by the MVVM Toolkit generator)"</c>.
786786
/// </para>
787787
/// </summary>
788-
public static readonly DiagnosticDescriptor WinRTGeneratedBindableCustomPropertyWithBaseObservablePropertyOnField = new(
788+
public static readonly DiagnosticDescriptor WinRTGeneratedBindableCustomPropertyWithBaseObservablePropertyOnField = new DiagnosticDescriptor(
789789
id: "MVVMTK0047",
790790
title: "Using [GeneratedBindableCustomProperty] is not compatible with [ObservableProperty] on fields",
791791
messageFormat: """The type {0} using [GeneratedBindableCustomProperty] is also using [ObservableProperty] on its declared (or inherited) field {1}.{2}: combining the two generators is not supported, and partial properties should be used instead (the [GeneratedBindableCustomProperty] generator cannot see the generated property that is produced by the MVVM Toolkit generator)""",
@@ -801,7 +801,7 @@ internal static class DiagnosticDescriptors
801801
/// Format: <c>"The type {0} using [GeneratedBindableCustomProperty] is also using [RelayCommand] on its inherited method {1}: combining the two generators is not supported, and a manually declared command property should be used instead (the [GeneratedBindableCustomProperty] generator cannot see the generated property that is produced by the MVVM Toolkit generator)"</c>.
802802
/// </para>
803803
/// </summary>
804-
public static readonly DiagnosticDescriptor WinRTGeneratedBindableCustomPropertyWithBaseRelayCommand = new(
804+
public static readonly DiagnosticDescriptor WinRTGeneratedBindableCustomPropertyWithBaseRelayCommand = new DiagnosticDescriptor(
805805
id: "MVVMTK0048",
806806
title: "Using [GeneratedBindableCustomProperty] is not compatible with [RelayCommand]",
807807
messageFormat: """The type {0} using [GeneratedBindableCustomProperty] is also using [RelayCommand] on its inherited method {1}: combining the two generators is not supported, and a manually declared command property should be used instead (the [GeneratedBindableCustomProperty] generator cannot see the generated property that is produced by the MVVM Toolkit generator)""",
@@ -849,7 +849,7 @@ internal static class DiagnosticDescriptors
849849
/// Format: <c>"This project produced one or more 'MVVMTK0045' warnings due to [ObservableProperty] being used on fields, which is not AOT compatible in WinRT scenarios, but it can't enable partial properties and the associated code fixer because 'LangVersion' is not set to 'preview' (setting 'LangVersion=preview' is required to use [ObservableProperty] on partial properties and address these warnings)"</c>.
850850
/// </para>
851851
/// </summary>
852-
public static readonly DiagnosticDescriptor WinRTObservablePropertyOnFieldsIsNotAotCompatibleCompilationEndInfo = new(
852+
public static readonly DiagnosticDescriptor WinRTObservablePropertyOnFieldsIsNotAotCompatibleCompilationEndInfo = new DiagnosticDescriptor(
853853
id: "MVVMTK0051",
854854
title: "Using [ObservableProperty] with WinRT and AOT requires 'LangVersion=preview'",
855855
messageFormat: """This project produced one or more 'MVVMTK0045' warnings due to [ObservableProperty] being used on fields, which is not AOT compatible in WinRT scenarios, but it can't enable partial properties and the associated code fixer because 'LangVersion' is not set to 'preview' (setting 'LangVersion=preview' is required to use [ObservableProperty] on partial properties and address these warnings)""",
@@ -866,7 +866,7 @@ internal static class DiagnosticDescriptors
866866
/// Format: <c>"The property {0}.{1} is not an incomplete partial definition ([ObservableProperty] must be used on partial property definitions with no implementation part)"</c>.
867867
/// </para>
868868
/// </summary>
869-
public static readonly DiagnosticDescriptor InvalidObservablePropertyDeclarationIsNotIncompletePartialDefinition = new(
869+
public static readonly DiagnosticDescriptor InvalidObservablePropertyDeclarationIsNotIncompletePartialDefinition = new DiagnosticDescriptor(
870870
id: "MVVMTK0052",
871871
title: "Using [ObservableProperty] on an invalid property declaration (not incomplete partial definition)",
872872
messageFormat: """The property {0}.{1} is not an incomplete partial definition ([ObservableProperty] must be used on partial property definitions with no implementation part)""",
@@ -882,7 +882,7 @@ internal static class DiagnosticDescriptors
882882
/// Format: <c>"The property {0}.{1} returns a ref value ([ObservableProperty] must be used on properties returning a type by value)"</c>.
883883
/// </para>
884884
/// </summary>
885-
public static readonly DiagnosticDescriptor InvalidObservablePropertyDeclarationReturnsByRef = new(
885+
public static readonly DiagnosticDescriptor InvalidObservablePropertyDeclarationReturnsByRef = new DiagnosticDescriptor(
886886
id: "MVVMTK0053",
887887
title: "Using [ObservableProperty] on a property that returns byref",
888888
messageFormat: """The property {0}.{1} returns a ref value ([ObservableProperty] must be used on properties returning a type by value)""",
@@ -898,7 +898,7 @@ internal static class DiagnosticDescriptors
898898
/// Format: <c>"The property {0}.{1} returns a byref-like value ([ObservableProperty] must be used on properties of a non byref-like type)"</c>.
899899
/// </para>
900900
/// </summary>
901-
public static readonly DiagnosticDescriptor InvalidObservablePropertyDeclarationReturnsRefLikeType = new(
901+
public static readonly DiagnosticDescriptor InvalidObservablePropertyDeclarationReturnsRefLikeType = new DiagnosticDescriptor(
902902
id: "MVVMTK0054",
903903
title: "Using [ObservableProperty] on a property that returns byref-like",
904904
messageFormat: """The property {0}.{1} returns a byref-like value ([ObservableProperty] must be used on properties of a non byref-like type)""",

src/CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/SuppressionDescriptors.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
using Microsoft.CodeAnalysis;
66

7+
#pragma warning disable IDE0090 // Use 'new SuppressionDescriptor(...)'
8+
79
namespace CommunityToolkit.Mvvm.SourceGenerators.Diagnostics;
810

911
/// <summary>
@@ -14,23 +16,23 @@ internal static class SuppressionDescriptors
1416
/// <summary>
1517
/// Gets a <see cref="SuppressionDescriptor"/> for a field using [ObservableProperty] with an attribute list targeting a property.
1618
/// </summary>
17-
public static readonly SuppressionDescriptor PropertyAttributeListForObservablePropertyField = new(
19+
public static readonly SuppressionDescriptor PropertyAttributeListForObservablePropertyField = new SuppressionDescriptor(
1820
id: "MVVMTKSPR0001",
1921
suppressedDiagnosticId: "CS0657",
2022
justification: "Fields using [ObservableProperty] can use [property:], [set:] and [set:] attribute lists to forward attributes to the generated properties");
2123

2224
/// <summary>
2325
/// Gets a <see cref="SuppressionDescriptor"/> for a field using [ObservableProperty] with an attribute list targeting a get or set accessor.
2426
/// </summary>
25-
public static readonly SuppressionDescriptor PropertyAttributeListForObservablePropertyFieldAccessors = new(
27+
public static readonly SuppressionDescriptor PropertyAttributeListForObservablePropertyFieldAccessors = new SuppressionDescriptor(
2628
id: "MVVMTKSPR0001",
2729
suppressedDiagnosticId: "CS0658",
2830
justification: "Fields using [ObservableProperty] can use [property:], [set:] and [set:] attribute lists to forward attributes to the generated properties");
2931

3032
/// <summary>
3133
/// Gets a <see cref="SuppressionDescriptor"/> for a method using [RelayCommand] with an attribute list targeting a field or property.
3234
/// </summary>
33-
public static readonly SuppressionDescriptor FieldOrPropertyAttributeListForRelayCommandMethod = new(
35+
public static readonly SuppressionDescriptor FieldOrPropertyAttributeListForRelayCommandMethod = new SuppressionDescriptor(
3436
id: "MVVMTKSPR0002",
3537
suppressedDiagnosticId: "CS0657",
3638
justification: "Methods using [RelayCommand] can use [field:] and [property:] attribute lists to forward attributes to the generated fields and properties");

0 commit comments

Comments
 (0)