Sonar-dotnet: Document suppression details

Created on 2 Aug 2017  路  3Comments  路  Source: SonarSource/sonar-dotnet

The FAQ says nothing about suppression, which is a very important subject. I think it should explain SuppressMessage (specifically, how does one know what the _category_ is?) and #pragma warning disable / #pragma warning restore. If there are other suppression possibilities we'd love to know about them too.

Most helpful comment

BTW, it seems that the category isn't checked at all, and that only the part before the colon in the check ID is important. In other words:

[SuppressMessage(
 "you can put anything here", 
 "S1871:you can put anything here too, the only thing that matters is the S1871 before the colon"
)]

Some more related links with GlobalSuppressions.cs guidance:
https://stackoverflow.com/a/41721869/67824
https://stackoverflow.com/a/34640154/67824

All 3 comments

Hi @ohadschn,

If you are using SonarQube then the recommended way is to mark the issue on the server. We are planning to improve SonarLint for Visual Studio to hide issues marked on the server (connected mode).

If you are using only SonarLint for Visual Studio or the analyzer as a NuGet then the recommended way is indeed the suppress message. We haven't communicated much on it as it is the classic way to ignore an issue with Visual Studio.

And yet you do have a section in your FAQ about turning off rules (which is just as classic, if not more so as it has an accessible and easy to understand UI)... IMHO mentioning SuppressMessage and #pragma warning is just as important.

Also, consider a typical MS rule description:
https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1801-review-unused-parameters
It is clear what the _CheckId_, _TypeName_, and _Category_ are to put in the SuppressMessage attribute.

Compare that with a typical SonarLint rule description: http://www.sonarlint.org/visualstudio/rules/index.html#sonarLintVersion=3.4.0&ruleId=S3442
Aside from the _CheckId_ it's hard to figure out the rest.

BTW, SuppressMessageAttribute.MessageId has always been somewhat of a mystery for me, even for MS rules, so if you could clarify that one in your rules, even more power to you.

BTW, it seems that the category isn't checked at all, and that only the part before the colon in the check ID is important. In other words:

[SuppressMessage(
 "you can put anything here", 
 "S1871:you can put anything here too, the only thing that matters is the S1871 before the colon"
)]

Some more related links with GlobalSuppressions.cs guidance:
https://stackoverflow.com/a/41721869/67824
https://stackoverflow.com/a/34640154/67824

Was this page helpful?
0 / 5 - 0 ratings