Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress a StyleCop warning of entire namespace files

Tags:

c#

stylecop

I'm using Style Cop version 4.7. Global suppression don't work for every member of selected namespace.

I have two files in the same namespace (StyleCopSample.Test). When I set suppress message in the first file, messages are suppressing only for this file, but the second file still gets a warnings.

Content of the first file:

[assembly: SuppressMessage("CSharp.DocumentationRules", "*", Scope = "Namespace", Target = "StyleCopSample.Test")]

namespace StyleCopSample.Test
{
  class TestFirst {}
}

Content of the second file:

namespace StyleCopSample.Test
{
  class TestSecond {}
}

I don't want to describe suppress message attribute for every physical file of the same namespace. Any ideas?

Thanks for Your time!

like image 753
Andrius Avatar asked Dec 12 '12 15:12

Andrius


2 Answers

I think it's better just to disable the documentation rules on the StyleCop settings file.

Just open the settings dialog from the project context menu.

Menu item

And then uncheck the 'Documentation Rules' checkbox.

uncheck this item

like image 159
Doug Avatar answered Oct 16 '22 23:10

Doug


The SuppressMessage directive will only process the current file (see the comments in this stylecop issue).

You could possibly achieve what you want via file lists, although this will work best if there are only a few files you want to apply this exclusion to. If you want this applied to all files in a particular project, then the easiest way may be to simply modify the settings via the settings dialog as already mentioned.

Alternatively, you could put all the namespace related files into a separate folder, and have a custom settings file in that folder to exclude these rules from those particular files.

like image 30
Mightymuke Avatar answered Oct 16 '22 22:10

Mightymuke