sonar-dotnet icon indicating copy to clipboard operation
sonar-dotnet copied to clipboard

NET-1685 Analysis warnings in .razor files cannot be suppressed

Open costin-zaharia-sonarsource opened this issue 2 years ago • 8 comments

Description

There are multiple ways to suppress analysis warnings:

  • using .editorconfig files
  • using #pragma warning disable directives
  • using the SupressMessage attribute Details: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/suppress-warnings

Currently none of these work for .razor files.

Repro steps

Create a project with a .razor file that contains the following snippet:

@code {
#pragma warning disable S5332
    public void Do()
    {
        using var smtp = new SmtpClient("host", 25);
    }
#pragma warning restore S5332
}

Expected behavior

The issue should be suppressed.

Actual behavior

The impression does not work.

Known workarounds

Mark the issue as won't fix/false positive or review the hotspot on the server

Related information

  • C#/VB.NET Plugins version 9.10
  • MSBuild version 17.7.3+8ec440e68

The same is true for Razor templates in .cshtml files as well.

Piedone avatar Feb 02 '25 23:02 Piedone

Another workaround

  • Disable some issues on razor files:
  • Image

jean-beziaud avatar Mar 27 '25 10:03 jean-beziaud

I confirm: via .editor.config, it doesn't work too with this configuration:

Image

jean-beziaud avatar Mar 27 '25 14:03 jean-beziaud

Linking back to an internal support ticket for future reference: https://sonarsource.atlassian.net/browse/USER-261

Tim-Pohlmann avatar May 07 '25 08:05 Tim-Pohlmann

Moved to NET-1685

@pavel-mikula-sonarsource is this indeed completed, or did you close it because of the move? Asking because the latest release (https://github.com/SonarSource/sonar-dotnet/releases/tag/10.11.0.117924), published after this being closed, doesn't seem to contain it.

Piedone avatar Jun 06 '25 13:06 Piedone

It was only moved. I'll reopen it so you can get an update once it's done. We've kept opened mostly FPs

Thank you!

Piedone avatar Jun 06 '25 14:06 Piedone