From 3d2bb6e808babe24918ee52a6804bdcccf1af2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Tue, 19 Jul 2022 09:52:28 +0200 Subject: [PATCH] CA1018: Mark attributes with AttributeUsageAttribute --- .editorconfig | 3 +++ .../Messages/ProtocolVersionAttribute.cs | 1 + .../CodeCoverage/TestSDKAutoGeneratedCode.cs | 1 + .../Attributes/DataCollectorAttachmentProcessor.cs | 1 + .../Attributes/DataCollectorFriendlyNameAttribute.cs | 1 + .../DataCollector/Attributes/DataCollectorTypeUriAttribute.cs | 1 + .../VersionAttribute.cs | 1 + 7 files changed, 9 insertions(+) diff --git a/.editorconfig b/.editorconfig index 0d7f4ab593..0b172c41ab 100644 --- a/.editorconfig +++ b/.editorconfig @@ -230,6 +230,9 @@ dotnet_diagnostic.CA1822.severity = warning # not default, increased severity to # CA1816: Dispose methods should call SuppressFinalize dotnet_diagnostic.CA1816.severity = warning # not default, increased severity to ensure it is applied +# CA1018: Mark attributes with AttributeUsageAttribute +dotnet_diagnostic.CA1018.severity = warning # not default, increased severity to ensure it is applied + #### C# Coding Conventions #### # var preferences diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/ProtocolVersionAttribute.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/ProtocolVersionAttribute.cs index 1e1e164b71..662ef22dbc 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/ProtocolVersionAttribute.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/ProtocolVersionAttribute.cs @@ -7,6 +7,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; [Conditional("DEBUG")] +[AttributeUsage(AttributeTargets.Field)] internal class ProtocolVersionAttribute : Attribute { public ProtocolVersionAttribute(int added, Type payloadType) diff --git a/src/Microsoft.TestPlatform.ObjectModel/CodeCoverage/TestSDKAutoGeneratedCode.cs b/src/Microsoft.TestPlatform.ObjectModel/CodeCoverage/TestSDKAutoGeneratedCode.cs index 39cdc1b8e8..5f224d9b9d 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/CodeCoverage/TestSDKAutoGeneratedCode.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/CodeCoverage/TestSDKAutoGeneratedCode.cs @@ -8,6 +8,7 @@ namespace Microsoft.VisualStudio.TestPlatform; /// /// Only to be used to Test platform, to exclude auto generated code from CodeCoverage /// +[AttributeUsage(AttributeTargets.All)] public class TestSDKAutoGeneratedCode : Attribute { } diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/Attributes/DataCollectorAttachmentProcessor.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/Attributes/DataCollectorAttachmentProcessor.cs index fdd9257d8a..5039313d00 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/Attributes/DataCollectorAttachmentProcessor.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/Attributes/DataCollectorAttachmentProcessor.cs @@ -8,6 +8,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; /// /// Registers an attachment processor for a data collector. /// +[AttributeUsage(AttributeTargets.Class)] public class DataCollectorAttachmentProcessorAttribute : Attribute { /// diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/Attributes/DataCollectorFriendlyNameAttribute.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/Attributes/DataCollectorFriendlyNameAttribute.cs index 9c6289f1ef..e56934e8af 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/Attributes/DataCollectorFriendlyNameAttribute.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/Attributes/DataCollectorFriendlyNameAttribute.cs @@ -8,6 +8,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; /// /// Provides a friendly name for the data collector. /// +[AttributeUsage(AttributeTargets.Class)] public class DataCollectorFriendlyNameAttribute : Attribute { /// diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/Attributes/DataCollectorTypeUriAttribute.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/Attributes/DataCollectorTypeUriAttribute.cs index 296e2573cd..e551ea387b 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/Attributes/DataCollectorTypeUriAttribute.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/Attributes/DataCollectorTypeUriAttribute.cs @@ -9,6 +9,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; /// Provides unique identification of a data collector in the form of a URI. /// Recommended format: 'datacollector://Company/Product/Version' /// +[AttributeUsage(AttributeTargets.Class)] public class DataCollectorTypeUriAttribute : Attribute { /// diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/VersionAttribute.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/VersionAttribute.cs index 8afb6466f0..dbe5de5bc1 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/VersionAttribute.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/VersionAttribute.cs @@ -7,6 +7,7 @@ namespace Microsoft.TestPlatform.PlatformAbstractions; [Conditional("DEBUG")] +[AttributeUsage(AttributeTargets.Method)] internal class VersionAttribute : Attribute { public string? Description { get; set; }