How to ignore sonar rule to specific line of code in c#?

uyusuk picture uyusuk · Jun 11, 2019 · Viewed 10.7k times · Source

I use sonarLint. I want the sonar test not to be performed for a specific line.I used '//NOSONAR' but it didn't work. Does not specify the error number. SS

EDIT: The error still appears in sonarlint when I use //NOSONAR. But in the main project (SonarQube) the error no longer appears.

Answer

Peska picture Peska · Jun 11, 2019

This is Visual Studio suggestion, not SonarLint warning. Also, I believe NOSONAR is not supported in Visual Studio. You can either suppress in source:

#pragma warning disable IDE0017
<your code>
#pragma warning restore IDE0017

Or in suppression file:

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0017:Simplify object initialization", Justification = "<Pending>", Scope = "member", Target = "~M:<your class and your method>")]