How do I disable blocks of lines (or single lines of codes) from SonarQube scanning for C# code?

833 views
Skip to first unread message

Joe Tavarez

unread,
Feb 22, 2017, 2:56:50 PM2/22/17
to SonarQube
Hello,
How do I disable blocks of lines (or single lines of codes) from SonarQube scanning for C# code?
We have a SonarQube Server Version 5.6 that kicks off scanning from a continuous integration system and reports its results.

Locally, I installed SonarLint to detect SonarQube bugs and vulnerabilities from MS Visual Studio 2015.
I noticed when I place "#pragma warning disable S2952" it excluded the lines of code that violated that rule, but it only worked with the SonarLint Visual Studio plugin.
For example:

    #pragma warning disable S2952
      myImage.Dispose();
    #pragma warning restore S2952

S2952 being the csharpsquid number, instead all the aforementioned example accomplishes is exclude it from the SonarQube results when it is run locally using [SonarLint][1].

When our continuous integration systems reports its results to the SonarQube server, then the bug is still reported.

I know how to exclude entire projects from SonarQube, but I have not been able to do a line-by-line or block exceptions.

Is this something that can be accomplished in SonarQube V5.6?
Any help or suggestions would be appreciated.


  [1]: http://www.sonarlint.org/visualstudio/index.html

G. Ann Campbell

unread,
Feb 22, 2017, 3:06:37 PM2/22/17
to SonarQube
Hi Joe,

Since you're willing and able to mark both the top and the bottom of each block that should be excluded, then the answer is easy: you want to ignore issues on blocks. That lets you configure the start and end strings that mark blocks to be ignored. You can use Java-syntax regexes here. This configuration will ignore all issues on the block. Additionally, there is the ability to ignore start marker, end marker and rule id. Unfortunately, it won't work to specify rule id in your comment as your code snippet shows.


HTH,
Ann
Reply all
Reply to author
Forward
0 new messages