From 6ffc193e4c0709cad5d007fb578e2c053d8f2ece Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay <121798625+zsolt-kolbay-sonarsource@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:05:36 +0200 Subject: [PATCH] Modify S3993: Promote C# rule to Sonar-way (#9626) --- analyzers/rspec/cs/S3993.html | 79 +++++++++++------------ analyzers/rspec/cs/Sonar_way_profile.json | 1 + 2 files changed, 37 insertions(+), 43 deletions(-) diff --git a/analyzers/rspec/cs/S3993.html b/analyzers/rspec/cs/S3993.html index dbb59261656..7ed722a6f0d 100644 --- a/analyzers/rspec/cs/S3993.html +++ b/analyzers/rspec/cs/S3993.html @@ -1,55 +1,48 @@
When defining custom attributes, System.AttributeUsageAttribute
must be used to indicate where the attribute can be applied. This will
-determine its valid locations in the code.
-using System; - -namespace MyLibrary +When defining custom attributes, AttributeUsageAttribute +must be used to indicate where the attribute can be applied. This will:
+
+public sealed class MyAttribute : Attribute // Noncompliant - AttributeUsage is missing { + private string text; - public sealed class MyAttribute :Attribute // Noncompliant - { - string text; + public MyAttribute(string text) + { + this.text = text; + } - public MyAttribute(string myText) - { - text = myText; - } - public string Text - { - get - { - return text; - } - } - } + public string Text => text; }-
-using System; - -namespace MyLibrary +Compliant solution
++[AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Delegate)] +public sealed class MyAttribute : Attribute { + private string text; - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Delegate)] - public sealed class MyAttribute :Attribute - { - string text; + public MyAttribute(string text) + { + this.text = text; + } - public MyAttribute(string myText) - { - text = myText; - } - public string Text - { - get - { - return text; - } - } - } + public string Text => text; }+Resources
+Documentation
+