4

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?

haughtonomous
  • 4,602
  • 11
  • 34
  • 52
  • Are you aware of the [Connected Mode](http://www.sonarlint.org/visualstudio/index.html#Connected)? In connected mode, you can remove the rule from the quality profile. That way you can synchronize your standards within your team. – janos Jan 18 '17 at 13:46
  • We don't actually want to use the SonarQube server approach - too complex for our needs. All we want is for suppressed warnings to disappear from the warnings tab on the VS Errors List screen, so that when all warnings have been dealt with or suppressed, we have a 'clean' screen and any new warnings that crop up are obvious. Is this not possible? – haughtonomous Jan 18 '17 at 13:53

2 Answers2

3

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?

Amaury Levé
  • 1,459
  • 10
  • 21
  • Could it be a scaling issue? I am using 2.9.0.355 together with the latest Nuget package on a C# solution that has about 500,000 lines of executable source code (excluding comment lines and curly brackets), and not only is it excruciatingly slow, it exhibits the problem I described. – haughtonomous Jan 18 '17 at 14:52
  • I am not sure but it is worth checking. I will get back to you when done. In the meantime and if you don't mind, could you create a small project to confirm that it is working on the small project? Just to confirm. – Amaury Levé Jan 18 '17 at 14:54
  • 1
    I tried it on a much smaller solution (a mere several thousand lines of code only) and had the same experience. However when I tried it on another, very small, test solution which showed only two warnings, they disappeared after being suppressed, and thereafter weren't displayed even after a rebuild. It does seems to be a scaling issue. I also noticed that in the larger project (above), it is quite slow to remove the suppressed warnings from the Errors List screen, doing it one by one, until it eventually stops. – haughtonomous Jan 18 '17 at 15:19
  • In the very small project this was quick, so the number of warnings being suppressed does seem to have an increasingly detrimental effect on performance. – haughtonomous Jan 18 '17 at 15:19
  • Thanks for the update, we will also try to have a look and see if this performance is coming from our side or is linked to MS. – Amaury Levé Jan 18 '17 at 15:27
  • What SonarLint does and the way it integrates are very nice, but these issues are killing it for us. – haughtonomous Jan 18 '17 at 15:45
  • @NeilHaughton The issue suppression mechanism is implemented by the Roslyn team, and there's nothing specific there for SonarLint. I've also seen that sometimes issues don't disappear. Deleting the `.vs` folder next to your solution solves this problem. – Tamas Jan 23 '17 at 07:44
  • Where did you get the category from (first argument of `SuppressMessageAttribute`)? I don't see it documented at http://www.sonarlint.org/visualstudio/rules/index.html#sonarLintVersion=3.5.0&ruleId=S1172. Did you just make it up, and anything would have worked just the same? – Ohad Schneider Sep 04 '17 at 11:45
0
  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")]
Erhan Urun
  • 228
  • 3
  • 9