How to suppress SonarLint Analyzers rules in Visual Studio 2017

Often when I write unit tests I use Console.WriteLine so  can see the output after the test execution. This can be a great time saver when tests fails.

image

However, if you are using SonarLint it will nag you to death about using Console.WriteLine.

First with a squiggle.

image

So I use the light bulb to suppress it.

image

Even if I select for solution I have to do this a million times because each instance targeted.

[

assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Vulnerability", "S2228:Console logging should not be used", Justification = "<Pending>", Scope = "member", Target = "~M:Airlink.Core.UnitTest.ExportImportTests.ExportImport_Save")]

How do I tell SonarLint once and for all that I do not care about this rule!

Expand your project in Solution Explorer. Now expand References and finally Analyzers. Right-click on Analyzers and select Open Active Rule Set.

image

There you can finally uncheck the rules that do not apply.  Be sure and save your changes.

image

It took me forever to find that. I hope this saves you the pain this caused me.

Comments (1) -

  • Debra White

    11/12/2019 8:58:03 PM | Reply

    Thanks for the great tip. BTW, do you know if there is a way to suppress some rules globally? (I have a lot of projects, don't want to do it on each project one by one) Thanks!

Add comment

Loading