dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.09k stars 4.04k forks source link

Support SuppressMessageAttribute suppression for compiler diagnostics #6471

Open mavasani opened 9 years ago

mavasani commented 9 years ago

Compiler diagnostics only respect in source pragma suppressions. This causes lot of nuances for bulk suppression/baselining feature. Additionally, the user experience for suppressing individual or bulk diagnostics from error list is also affected:

  1. If user selects one compiler and one analyzer warning - the suppress in suppressions file command can only work for the latter. User has to repeat the exercise again, with suppress in source command to get compiler warning suppressed.
  2. Bulk suppressing multiple compiler diagnostics adds lot of clutter to source code if done via pragma suppressions.

We should work with the compiler team to enable this functionality post 1.1

srivatsn commented 9 years ago

We've talked about this before and decided against it but given the arguments above for baselining, moving to the compiler team for reconsideration.

mletterle commented 7 years ago

Bumping this, because I got fooled.

It appears that the SupressMessageAttribute works if you're in VisualStudio and have the file open, as it helpfully does not display them in the warnings error list, but they still appear in MSBuild output.

giggio commented 4 years ago

Bumping this up again as it seems that the IDE behavior will be fixed as per #39094. Still, the difference in behavior for analyzer and compiler diagnostics is weird for users. Also I couldn't find docs explaining it. This causes confusion and makes the language harder to use.

sharwell commented 4 years ago

💭 Considering a non-empty set analyzers are eventually going to ship by default in the SDK and those analyzers respect SuppressMessageAttribute, one could argue that the performance overhead of respecting SuppressMessageAttribute in compilation scenarios is no longer opt-in. At some point, this may provide sufficient justification for respecting the attribute for compiler diagnostics.

mavasani commented 4 years ago

Reported at https://developercommunity.visualstudio.com/content/problem/1002401/contextual-action-on-warnings-suppress-in-globalsu.html

weitzhandler commented 4 years ago

I encounter this over and over. I don't like the pragma style which makes me feel like a C++ developer when I'm supposed to write C#. Attributes are scope based, so I can suppress once per method or class, without having to restore - hence doubling my code uglification.

Related

RikkiGibson commented 3 years ago

There are scenarios where a source generator may add partial declarations which result in warnings on partial declarations in user code, which the source generator wants to suppress. SharpLab

If the compiler respected the SuppressMessageAttribute when issuing compiler diagnostics, the generator author could apply the attribute to the partial declaration they control and suppress the warning in the user's code.

53357

statler commented 1 year ago

This seems to be a really popular suggestion, but no love? Please resolve this because, as someone else has quite rightly pointed out - pragma's look like cancer in code :(

mavasani commented 1 year ago

Tagging @jaredpar @jcouv - seems like a popular customer request, but last time @gafter looked at this feature, he was worried about performance implications around this. I am not sure those still hold given Sam's point: https://github.com/dotnet/roslyn/issues/6471#issuecomment-581162825

MartyIX commented 1 year ago

I would love to suppress compiler warnings using SuppressMessageAttribute. It looks much nicer.

A-Stapleton commented 1 year ago

Would be great to have this feature #pragma is a very jarring experience for devs when it shows up in code and the attribute would be much cleaner. 👍

pvlst commented 6 months ago

Are there any news regarding this feature? I spent half an hour trying to suppress irrelevant CS8625 warnings in test classes using the SuppressMessage attribute. And now I've found this 8.5 years old issue.

I guess I'll put exclamation marks everywhere, using #pragma feels like using goto, no way.