The rule "Track uses of "NOSONAR" comments" does not behave as expected

SonarQube 8.9.6

Hello,

The C++ rule cpp:S1291 "Track uses of “NOSONAR” should actually find all places in the code that are marked with NOSONAR. However, this only works if the NOSONAR is in a block comment and not if it is in a line comment.

The NOSONAR is recognized in lines 43, 60 and 75, but not in lines 49 and 68.

Welcome @Stef,

This is indeed an issue in our analyzer, which is already known as [CPP-2049] - Jira. The problem is not directly related to block-comments vs line-comment, but the fact that if a line contains NOSONAR, all issues on this line will be silenced, even issues that report that this line contains NOSONAR

This problem was never considered as high-priority to fix, because the recommended way to silence issues is not to use NOSONAR, but to mark it as Won’t fix or False positive in the UI. This is preferred for the following reasons:

  • It avoids cluttering the source code.
  • NOSONAR is a blunt tool, that will not work nicely when a line contains several issues
  • Even if an issue is corrected, NOSONAR comments may remain, thus confusing the readers of the code

Hope this helps!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.