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

IDE0079 triggering false positives on various suppressed diagnostics #75887

Open
DanielRouxSA opened this issue Nov 13, 2024 · 0 comments
Open
Labels
Area-Analyzers Feature - IDE0079 Remove unnecessary suppression untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@DanielRouxSA
Copy link

Version Used:

.NET 9 SDK 9.0.100 (though this also occurs on projects targeting .NET 8)

Steps to Reproduce:

Since the update to Visual Studio 17.12.0 (and thus to the .NET 9 SDK), I am now experiencing false positives for IDE0079 on numerous different analyzer suppressions across my projects.

Below I have a few selected minimal examples. Further down I will list the full list of diagnostic suppressions that I have encountered with false positives for IDE0079.

CA1040:

// For context, the below interface is solely used for polymorphic serialization (as per System.Text.Json requirement).

[SuppressMessage("Design", "CA1040:Avoid empty interfaces")] // IDE0079 triggers here. Removing this line causes CA1040 to correctly trigger on the interface.
[JsonDerivedType(typeof(PolymorphicTypeA), "typeA")]
[JsonDerivedType(typeof(PolymorphicTypeB), "typeB")]
[JsonDerivedType(typeof(PolymorphicTypeC), "typeC")]
[JsonDerivedType(typeof(PolymorphicTypeD), "typeD")]
public interface IPolymorphicSearchResult_V4 { }

CA1815:

#pragma warning disable CA1815 // Override equals and operator equals on value types // IDE0079 triggers here. Removing this suppression causes CA1815 to correctly trigger on the struct.

file readonly struct GuidResponse
{
    #region JSON Properties

    [JsonPropertyName("Response")] public Guid response { get; init; }

    #endregion
}

#pragma warning restore CA1815 // Override equals and operator equals on value types

CA1822:

[SuppressMessage("Performance", "CA1822:Mark members as static")] // IDE0079 triggers here. Removing this line causes CA1822 to correctly trigger on the method.
internal void ValidateNewInstruction(NewInstruction instruction)
{
    // Method implementation that does not access instance data
}

Diagnostic Id:

IDE0079 is triggered.

This is the full list of analyzer suppressions that I have (thus far) encountered that cause the IDE0079 false positives:

  • CA1002
  • CA1008
  • CA1024
  • CA1034
  • CA1040
  • CA1054
  • CA1056
  • CA1308
  • CA1310
  • CA1711
  • CA1815
  • CA1819
  • CA1822
  • CA1849
  • CA1859
  • CA5394
  • VSTHRD100 (From the Visual Studio Threading Analyzers)
  • VSTHRD103 (From the Visual Studio Threading Analyzers)
  • VSTHRD200 (From the Visual Studio Threading Analyzers)

I have also seen a number of analyzers that do not trigger IDE0079 when suppressed, so this does not occur on all suppressions.

Just to be clear, there may well be cases among these analyzers where my way of handling them could be improved as opposed to merely suppressing them; this issue is specifically regarding the false positives for IDE0079 on said suppressions.

Expected Behavior:

IDE0079 does not trigger on suppressions that suppress otherwise active analyzer triggers.

Actual Behavior:

IDE0079 triggers on suppressions that suppress otherwise active analyzer triggers.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 13, 2024
@deepakrathore33 deepakrathore33 added the Feature - IDE0079 Remove unnecessary suppression label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers Feature - IDE0079 Remove unnecessary suppression untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

2 participants