Disable all style warnings for a specific C # class

I work in an application and develop several classes for demo purpose. I know that these classes will be removed in the future.

Is it possible to ignore all style warnings for these classes, since I do not want to waste time on these warnings?

I searched, but found that I can only ignore the settings in the styleruk (this will also affect other classes) or some specific rule (I just want to ignore all warnings).

+7
source share
5 answers

Starting with StyleCop 4.4.0, you can also suppress all rules in the rule namespace using a single suppression attribute. This is indicated by replacing the CheckID rule and the rule name with a single asterisk. The following code example suppresses all the documentation rules for the default StyleCop in the inner class. In this case, StyleCop will still report a violation indicating that the document is not in the outer class, but it ignores all the documentation rules for the inner class and its contents.

public class OuterClass { [SuppressMessage("StyleCop.CSharp.DocumentationRules", "*")] public class InnerClass { public void MyUndocumentedMethod { } } } 

http://stylecop.soyuz5.com/Suppressions.html

+15
source

You can trick StyleCop to not process the file at all by adding this header at the top:

 //------------------------------------------------------------------------------ // <auto-generated> // Well, not really. This is just a trick to get StyleCop off my back. // </auto-generated> //------------------------------------------------------------------------------ 
+18
source

Thanks to Bartล‚omiej Mucha for the answer I just used. As I discovered, "*" works well for a particular rule, but you need to add suppressions for each category. Here's the full set - if you copy them to the top of the class, you should find that all StyleCop errors are suppressed:

 [SuppressMessage("StyleCop.CSharp.NamingRules", "*", Justification = "Reviewed. Suppression is OK here.")] [SuppressMessage("StyleCop.CSharp.LayoutRules", "*", Justification = "Reviewed. Suppression is OK here.")] [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "*", Justification = "Reviewed. Suppression is OK here.")] [SuppressMessage("StyleCop.CSharp.OrderingRules", "*", Justification = "Reviewed. Suppression is OK here.")] [SuppressMessage("StyleCop.CSharp.ReadabilityRules", "*", Justification = "Reviewed. Suppression is OK here.")] [SuppressMessage("StyleCop.CSharp.SpacingRules", "*", Justification = "Reviewed. Suppression is OK here.")] [SuppressMessage("StyleCop.CSharp.DocumentationRules", "*", Justification = "Reviewed. Suppression is OK here.")] internal class MyClass { // ... } 
+12
source

If you want to prevent StyleCop from being run on a file, you can mark it in a .csproj file using the ExcludeFromStyleCop attribute mentioned in http://stylecop.codeplex.com/wikipage?title=Using%20StyleCop%20on%20Legacy%20Projects&referringTitle=Documentation .

+1
source

You can suppress rules by adding attributes to blocks of code. Here is a simple example in the class from the blog post linked below, but you can do this on different members individually:

 [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented")] public class MyUndocumentedClass { public void MyUndocumentedMethod {} } 
-one
source

All Articles