How to Verify NoSonarFilter Functionality in a Custom SonarQube Plugin

I am working on activating the NOSONAR feature in a custom SonarQube plugin we implemented for the Natural mainframe language. To achieve this, I used the NoSonarFilter.NoSonarInFile() method, as documented in the SonarQube API Javadocs, and followed the approach mentioned in this community post.

However, I have two key concerns:

  1. How can I verify if the NOSONAR functionality is working correctly?
    That is, how do I confirm that lines containing NOSONAR are being successfully ignored by the analysis?

  2. Regarding NoSonarFilter Implementation: Since NoSonarFilter is an abstract class and its method NoSonarInFile() is also abstract, do I need to provide an explicit implementation for it, or does the SonarQube API handle it automatically when configuring this feature?

Since I am relatively new to this, any guidance on confirming its correct functionality and ensuring proper implementation would be greatly appreciated.

Hi,

Welcome to the community!

Add it to a line where an issue is raised?

The rule implementation in the Java analyzer may help.

 
HTH,
Ann

Hi, thanks for the response

Yes I got it what you mentioned but actually I want to check locally whether NOSONAR is working correctly before deploying it and verifying it on the SonarQube server. Is there any way to do this?

For the second point, it seems that a rule has been created to identify where NOSONAR has been used throughout the code. However, my question is: Since NoSonarFilter is an abstract class and NoSonarInFile() is an abstract method, do we need to implement our own functionality for them to ensure that NOSONAR actually skips the lines during analysis? Or does SonarQube handle this automatically on its own?

I appreciate your guidance on this. Thanks again!

Hi,

It sounds like you’re looking for a rule unit test. That, or you could run SonarQube on your localhost.

I can’t tell you off-hand. That’s why I referred you to one of our implementations of the rule. Presumably you need to do for your own plugin whatever was done there.

 
HTH,
Ann

Certainly, yes. was asking for Unit Test

Got it, thanks a lot for your valuable time and your guidance on this.