Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a possibility to suppress warnings of sonarcloud in source code?

I am facing an issue with some sonarcloud warnings that will not be fixed in the nearest future (and should be disabled for now).

The warnings are raised by sonarcloud during build on CI. There are no any local analysers. Is there a way to suppress some specific warnings in source code on project, file, class and/or method levels?

The official documentation is not of much help, at least I did not manage to find the solution.

Does sonarcloud respect some

#pragma warning disable S3881

or other attribute based approach or some global settings.

like image 700
zds Avatar asked Dec 28 '25 18:12

zds


2 Answers

The #pragma syntax works, but I find it ugly. I prefer adding the attribute, and I found by experimenting that the following one works:

[SuppressMessage("SonarLint", "S125", Justification = "Ignored intentionally as a demo")]
public void When_X_Expect_Y()
{
    //string x = "trigger 'S125 - commented out code' issue in SonarLint";
}

The first argument of SuppressMessage doesn't seem to matter. The second one is crucial and effective.

like image 89
Paweł Bulwan Avatar answered Dec 31 '25 07:12

Paweł Bulwan


Yes SonarCloud respects the #pragma syntax:

#pragma warning disable S3881
// The statement that fails validation
#pragma warning restore S3881

Where you replace S3881 with the number that fails for you.

like image 26
Rolf Avatar answered Dec 31 '25 07:12

Rolf