Search code examples
sonarqubesonarqube-msbuild-runner

Is SonarQube ignoring isSuppressedInSource?


I am using the SonarQube Scanner for MSBuild 2.0 with SonarQube 5.4. I have added a SonarQube Plugin for the Roslyn Wintellect.Analyzers NuGet package to the SonarQube server and added the rules to the Quality Profile that my SonarQube project uses. In the C# source code I have disabled the "Wintellect003" rule using #pragma (and then I tried the SuppressMessage attribute both inline and then in GlobalSuppressions.cs). The rule is successfully disabled in Visual Studio 2015 and msbuild 14 but SonarQube is not respecting the fact that I have disabled the rule (for this one line of code - I haven't disabled the rule in SonarQube or in the ruleset).

I can see that MsBuild.SonarQube.Runner.exe is recognising the suppression because in the "end" phase it generates the RoslynCA.json file to send to SonarQube and it includes the following section:-

"ruleId": "Wintellect003",
"kind": "warning",
"locations": [
  {
    "analysisTarget": [
      {
        "uri": "file:\/\/\/C:\/CS5Tests/Mycode.cs",
        "region": {
          "startLine": 920,
          "startColumn": 17,
          "endLine": 923,
          "endColumn": 118
        }
      }
    ]
  }
],
"shortMessage": "'if' statements must have braces",
"fullMessage": "If and else statements must use braces even for single line results",
"isSuppressedInSource": true,

As you can see it says that "isSuppressedInSource" is true. Unfortunately SonarQube isn't respecting this setting. Any ideas?

(I have tried stopping the SonarQube server, deleting the data\es folder to clear the cache and restarting the SonarQube server but this hasn't helped).


Solution

  • The C# 5.2 plugin adds support for this:

    https://groups.google.com/d/msg/sonarqube/0gghnIQf3XU/aEMSwMkvBAAJ

    We'd like to release the SonarQube C# Plugin version 5.2.

    What's new?

    Issue suppression through [SuppressMessage] is now supported

    All FxCop issues are imported in SonarQube, even the ones on fields which could not be mapped back to a specific file

    Adds 6 new rules This release closes the gap between the issues you see in Visual Studio and in SonarQube.