roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

Support SuppressMessageAttribute suppression for compiler diagnostics

Open mavasani opened this issue 9 years ago • 12 comments

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

mavasani avatar Oct 30 '15 19:10 mavasani

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

srivatsn avatar Nov 04 '15 18:11 srivatsn

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.

mletterle avatar Aug 31 '17 20:08 mletterle

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.

giggio avatar Feb 02 '20 16:02 giggio

💭 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.

sharwell avatar Feb 02 '20 18:02 sharwell

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

mavasani avatar Apr 24 '20 19:04 mavasani

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

weitzhandler avatar Aug 23 '20 06:08 weitzhandler

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

RikkiGibson avatar May 17 '21 22:05 RikkiGibson

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 :(

statler avatar Mar 30 '23 00:03 statler

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

mavasani avatar Mar 30 '23 04:03 mavasani

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

MartyIX avatar Sep 25 '23 12:09 MartyIX

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. 👍

A-Stapleton avatar Nov 21 '23 11:11 A-Stapleton

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.

pvlst avatar May 08 '24 21:05 pvlst