Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S3993 FP: Parent Attribute Class has defined AttributeUsage #9622

Closed
zsolt-kolbay-sonarsource opened this issue Aug 8, 2024 · 1 comment
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.

Comments

@zsolt-kolbay-sonarsource
Copy link
Contributor

Description

Currently, S3993 raises an issue when the attribute class isn't decorated with [AttributeUsage], but one of its ancestors is. In this case, the information is inherited by the derived attribute, so it isn't necessary to add it. The rule currently advocates doing so for the sake of readability.
We're promoting the rule to Sonar-way, so it's better to make it more lenient for these kinds of scenarios.

Repro steps

[AttributeUsage(AttributeTargets.Class)]
public class BaseAttribute : Attribute
{
}

public class DerivedAttribute : BaseAttribute   // Noncompliant - FP
{
}

Related information

  • C#/VB.NET Plugins version: 9.31
  • Visual Studio version: Visual Studio 2022 (17.10)
  • MSBuild / dotnet version: .NET 8.0
  • Operating System: Windows 10
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource added Type: False Positive Rule IS triggered when it shouldn't be. Area: C# C# rules related issues. labels Aug 8, 2024
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource added this to the 9.32 milestone Aug 8, 2024
@zsolt-kolbay-sonarsource
Copy link
Contributor Author

Not implementing this fix to keep the rule consistent with CA1018 Roslyn analyzer.

@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource removed this from the 9.32 milestone Aug 8, 2024
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource removed their assignment Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

1 participant