NET-1685 Analysis warnings in .razor files cannot be suppressed
Description
There are multiple ways to suppress analysis warnings:
- using
.editorconfigfiles - using
#pragma warning disabledirectives - using the
SupressMessageattribute 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.
Another workaround
- Disable some issues on razor files:
-
I confirm: via .editor.config, it doesn't work too with this configuration:
Linking back to an internal support ticket for future reference: https://sonarsource.atlassian.net/browse/USER-261
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.
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!