How to stop SonarLint suppressed warnings from continually reappearing in the VS Errors screen

4.8k Views Asked by At

We're trying SonarLint with VS2015 Enterprise and have an irritating problem which could be a show-stopper unless we resolve it. Core i5 processor, 8GB memory, large SSD, Windows 7 Pro:

We have masses of legacy warnings of the same warning code (eg S1444). I can live with the existing code but want to catch them for future work, so I want to suppress the existing warnings but without messy pragmas in the code. So, I multi-select them all in the Error List screen and rt-click, then click In Suppression File. A GlobalSuppressions file is created in the appropriate projects and updated.

However the warnings continue to be displayed. I clean and rebuild the solution and the 'suppressed' warnings continue to be displayed, still with a suppression state of 'Active' (which I am guessing means 'not suppressed').

This means it is almost (or may actually be) impossible to eliminate old warnings so that new ones are clearly exposed, which is the whole point of the exercise.

Is this a bug or am I missing something?

Also I notice that sometimes the rt-click context menu includes Suppress-> and other times it doesn't. How does that work?

2

There are 2 best solutions below

8
On

I can't reproduce the issue you are facing. I have created a ConsoleApplication (C#) and used the default code. I have then selected all issues, right-click and Suppress in Suppression File. I tried to rebuild, clean, restart VS and warnings no longer show up.

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication14
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}

GlobalSuppression.cs

// This file is used by Code Analysis to maintain SuppressMessage 
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given 
// a specific target and scoped to a namespace, type, member, etc.

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Sonar Code Smell", "S1172:Unused method parameters should be removed", Justification = "<Pending>", Scope = "member", Target = "~M:ConsoleApplication14.Program.Main(System.String[])")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Sonar Code Smell", "S1186:Methods should not be empty", Justification = "<Pending>", Scope = "member", Target = "~M:ConsoleApplication14.Program.Main(System.String[])")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Sonar Code Smell", "S1118:Utility classes should not have public constructors", Justification = "<Pending>", Scope = "type", Target = "~T:ConsoleApplication14.Program")]

I am using the latest SonarLint version (2.9.0.384). Could you create a simple repro case so I can work with it to find out what's happening?

0
On
  1. Add GlobalSuppressions.cs file in your project.
  2. Just use "module" as scope. Also target is unnecessery in this case.

This case supressing all warnings of category in your project or assembly.

For Example:

[assembly: SuppressMessage("Major Code Smell", "S1066:Collapsible \"if\" statements should be merged", Justification = "<Pending>", Scope = "module")]