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:
How to implement a feature like NOSONAR in a custom plugin?
How to ensure seamless integration with existing rules to suppress false positives?
Any help or suggestions would be greatly appreciated!
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.
Hi @Scott, thanks for the help.
I tried this as per mentioned by you, but right now my concern is how do i check if this is working fine for the false positives.
Also one more question is, we can directly use this noSonarInFile method and it will work fine or do we need to provide the implementation of this method also as this noSonarFile is abstract class and noSonarInFIle is an abstract method.