NOSONAR for custom sonar plug for language that are not supported by the conventional sonarqube

Hi everyone,

I am working on a custom SonarQube plugin for a programming language that are not supported by the conventional sonar plugin.

My current task is to implement a feature where lines containing a specific keyword (e.g., NOSONAR) are skipped during analysis, similar to how NOSONAR works in the default SonarQube functionality. The goal is to allow developers to suppress specific rule violations (such as false positives) for certain lines of code by including the NOSONAR keyword in those lines.

Since this is a custom plugin, the NOSONAR feature does not work natively, and I need to create this functionality from scratch.

Could anyone provide guidance on:

  1. How to implement a feature like NOSONAR in a custom plugin?
  2. How to ensure seamless integration with existing rules to suppress false positives?
    Any help or suggestions would be greatly appreciated!

Thank you in advance!

Hi,

Adding this feature is straightforward since it’s built into the SonarQube API. Below, I’ll use some code examples from the sonar-python project.

First, inject a NoSonarFilter instance into your Scanner class:

Next, when saving the file measures, call noSonarFilter.noSonarInFile(file, set_of_lines), where set_of_lines is a Set<Integer> containing the line numbers to be ignored in issues. Note that SonarQube doesn’t require the line to contain exactly the text NOSONAR. You can use any identifier you prefer, as it’s your responsibility to populate the set with the desired lines.

I hope this helps!

Hi, okay i got this and also tried to use the same in my code too but my confusion is as this NoSonarFilter class is an abstract class and it provides a method noSonarInFile so do i need need to create a concrete implementation of the NoSonarFilter class and that implementation only will handle the logic of identifying lines containing the NOSONAR keyword and registering them with the filter.