Sonar ignore issues by block not working

  • ALM used: GitHub
  • CI system used: Circle CI
  • Scanner command used: sonar-scanner
  • Languages of the repository: C++
  • Error observed: no error is given, sonar just continues to scan the ignore issue block as if the regex isn’t there
  • Steps to reproduce: run scanner
  • Potential workaround: not clear

Per the title, sonarcloud’s ignore issues in blocks feature is not working as expected. Our beginning regex is \/\/ @SONAR_STOP@ and the end regex is \/\/ @SONAR_START@. We would like to use these tags in order to ignore a block of code that uses a third party library, however all the code between the comments // @SONAR_STOP and // @SONAR_START@ is still being scanned. We have also tried using SONAR_STOP, SONAR_START, @SONAR_STOP@, and @SONAR_START@ as tags based on various other forum responses on the issue, however none have worked.

Hi Jtbaird,

I just tested those regexes on a sample project and they do work correctly.

Please confirm that your Analysis Scope settings look like this:

And that you are indeed using the delimiters in the correct order. i.e.,

// @SONAR_STOP@
code to ignore
// @SONAR_START@

Hi Peeter Piegaze,

I tried exactly like you but it doesn’t work.
I’m working on a maven project with jdk11.
Do you know why it doesn’t work ?

Thanks for your return.

Regards.

Hello Nojiko75,

To help you with your problem, I would need to see a screenshot of your analysis scope settings and a listing of the code where the @SONAR_STOP and @SONAR_START comments are embedded.

Please note that the @SONAR_STOP comes before the @SONAR_START. Reversing them is a common error!

Hello Peeter Piegaze,

This is the screenshot of my analysis scope settings :

and a example of the code where the @SONAR_STOP and @SONAR_START comments are embedded :

/**
 * Close the container.
 */
public static void shutdown() {
    if (postgresContainer != null) { // @SONAR_STOP@
        postgresContainer.close();
        postgresContainer = null;
    }
} // @SONAR_START@

I also tried this code but it didn’t work:

/**
 * Close the container.
 */
public static void shutdown() {
    // @SONAR_STOP@
    if (postgresContainer != null) {
        postgresContainer.close();
        postgresContainer = null;
    }
}
// @SONAR_START@

Thank you for your help.

Hello @Nojiko75,

Using the same settings as you and similar positioning in a Java file for the comments I was able to test and found no problems.

The only thing I can think of is that elsewhere in your project, either in a sonar-project.properties file, in the pom.xml file or in the command line at the invocation of the scanner, you have parameters that override the UI settings of the form

sonar.issues.ignore.block.*

You can see a discussion of these parameters here: How to set sonar.issue.ignore.block in sonar-project.properties

Hi Peeter,

I was trying the same thing in my project, it seems it’s still saying the part of the code is still uncovered, which is dragging the overall coverage down. Any idea how I should change that?

I’ve tried setting the regex in both UI and the config, neither worked.

sonar.issue.ignore.block=e2
sonar.issue.ignore.block.e2.beginBlockRegexp=\/\/ @SONAR_STOP@
sonar.issue.ignore.block.e2.endBlockRegexp=\/\/ @SONAR_START@

and in the code, i’m doing // @SONAR_STOP@ and // @SONAR_START@ around the code i want to ignroe.