Suppress issue in C++ source file

This problem continues to bother me.
With the option //NOSONAR it is possible to disable ALL errors in a line of a C++ file.
So it was realized that there must be a way to disable errors for a single line directly in the code.

Can someone please answer the following question:

Why is there no way created for C++ to do this like in JAVA using "@SuppressWarnings(“squid:S…)”?

I don’t understand why C++ and JAVA are handled so differently in this case.

I understand your frustration @Matthias.Guelck. We looked at the problem recently and right now the direction we will be taking will be to:

  • deprecate the use of //NOSONAR alone
  • request a RuleKey (or multiple keys) to be provided like “//NOSONAR(S123, S222, …) Justification” => very similar to @SuppressWarnings(“squid:S…) but more language agnostic
  • automatically Open and Close as Won’t Fix issues that are silenced by this mechanism for traceability purpose

Would that work for you?

1 Like

It sounds like it meets the requirements.

As mentioned here and elsewhere, (all?) other static code analysis tools provide such capabilities.
The most perfect implementation I know is provided by eslint.
There you can make the justification of the exception mandatory and even impose a minimum length for the explanation.

Can you estimate when such a solution will be available for Sonar?

1 Like

@Alexandre_Gigleux
Postscript:
What I unfortunately forgot: Thank you very much!

Hello

Has an issue been opened about this point ?

I’m afraid I don’t know.
For a long time the need for this feature was questioned (see previous posts in this thread) and then in June there was the vague announcement by Alexandre Gigleux.
Since then: Nothing!

Well… Any input, @Alexandre_Gigleux ?

I have the same issue. SonarLint in VS2019 requests me to use c++20 std::cast_bit instead of reinterpret_cast in a project that is configured for c++14
It also forces me to add std::wstring solution for a windows API parameter that is of type PWSTR.
which i won’t accept cause that would add additional runtime in my driver, and 0 benefits.

This is not the expected behavior. Could you please create a dedicated post where you describe this issue so that we can understand what happens?

It’s been more than half a year since @Alexandre_Gigleux’s announcement.
Do you have any updates on this topic?

Time flies, and unfortunately, we’ve had to adjust our priorities which has delayed the implementation of the solution I previously described. I waiting for the Clean Code Taxonomy and its impacts on Issue Statuses to be fully implemented and stable before moving on this topic.

In June 21 Marco Comi wrote “we will add //NOSONAR gap for C++ in Visual Studio”

Adding //NOSONAR to a line of C++ in Visual Studio 2022 has no effect.
Do I miss something or is this feature missing?

You missed reading the post before yours.

Do you any news regarding this implementation //NOSONAR(S123, S222, …)

Hi @Stephane_Filion

We investigated the topic, and it is something we want to do at some point.
We have quite a few hot topics at the moment and I cannot give you a timeline at the moment.

Cheers

Geoffray

Support //NOSONAR · Issue #2462 · SonarSource/sonarlint-visualstudio · GitHub was just closed as not planned. Does that mean anything?

1 Like