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 S1144 FP: Private Attributes #8342

Closed
jeremia opened this issue Nov 9, 2023 · 2 comments · Fixed by #9411
Closed

Fix S1144 FP: Private Attributes #8342

jeremia opened this issue Nov 9, 2023 · 2 comments · Fixed by #9411
Assignees
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@jeremia
Copy link

jeremia commented Nov 9, 2023

Description

Regarding S1144: Remove the unused class 'XXX'
For a private attribute class without AttributeUsageAttribute SonarLint always reports the class as unused even if it's used.

Repro steps

namespace ConsoleApp;

public class Test
{
	[Testing]
	public static void Main()
	{
	}

	private sealed class TestingAttribute : Attribute
	{
	}
}

Expected behavior

Only report CA1018: Specify AttributeUsage on XXX, Not S1144.

Actual behavior

Both S1144 and CA1018 is reported

Known workarounds

Att AttributeUsage: This removes both CA1018 (regarding attribute usage) and S1144 (regarding unused class).

Related information

  • C#/VB.NET Plugins version: SonarLint for Visual Studio 7.3.0.77872
  • Visual Studio version: 17.7.6
  • MSBuild / dotnet version: .NET 7
  • SonarScanner for .NET version (if used): Not used
  • Operating System: Windows 10
@pavel-mikula-sonarsource pavel-mikula-sonarsource changed the title Fix S1144 FN: Private Attribute classes without AttributeUsageAttribute are always marked as unused even if they are used. Fix S1144 FP: Private Attribute classes without AttributeUsageAttribute are always marked as unused Nov 9, 2023
antonioaversa added a commit that referenced this issue Nov 14, 2023
@antonioaversa
Copy link
Contributor

Hi @jeremia, thanks for reporting this issue.

I can reproduce it myself, and I can confirm it is indeed an issue that seems to appear when attributes are used.
We have recently encountered similar issues with attributes on private methods.
Your issue has been added to the backlog and will be included in one of our upcoming hardening sprints.

Meanwhile, waiting for a fix, you have the following options:

  • If you are using SonarLint with SonarQube or SonarCloud in connected mode: you can mark the issue as a false-positive in the UI. The rule can also be disabled in your Quality Profile if it’s particularly noisy.
  • If you are using SonarLint in Standalone Mode: you can use #pragma warning disable and #pragma warning restore to locally disable the rule in the source, or the .editorconfig files to disable or change the severity of the rule, if it gets particularly noisy.

Hope it helps,
Antonio

@martin-strecker-sonarsource
Copy link
Contributor

@zsolt-kolbay-sonarsource please also change the title of the issue.

@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource changed the title Fix S1144 FP: Private Attribute classes without AttributeUsageAttribute are always marked as unused Fix S1144 FP: Private Attribute classes Jun 6, 2024
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource changed the title Fix S1144 FP: Private Attribute classes Fix S1144 FP: Private Attributes Jun 6, 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

Successfully merging a pull request may close this issue.

4 participants