Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure StyleCop to suppress warnings on generated code?

Another project, Visual Studio's Code Analysis has this option. But I couldn't find it for StyleCop (AKA Source Analysis).

The file I want to ignore is a dbml's .designer.cs code, that includes the // <autogenerated> tag. A blog post tells me that it would be sufficient, but in my case it is not.

like image 672
Jader Dias Avatar asked Oct 19 '09 18:10

Jader Dias


1 Answers

StyleCop: How To Ignore Generated Code

Edit: Here is the header I use in generated grammars for ANTLR. This is actually the body of a StringTemplate template, so the two \> entries are actually just escaped > marks. Aside from the <auto-generated> tag and the [GeneratedCode] attribute, we still had to disable some warnings which appeared during code analysis.

//------------------------------------------------------------------------------
// \<auto-generated>
//     This code was generated by a tool.
//     ANTLR Version: ANTLRVersion
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// \</auto-generated>
//------------------------------------------------------------------------------

// $ANTLR <ANTLRVersion> <fileName>

// The variable 'variable' is assigned but its value is never used.
#pragma warning disable 219
// Unreachable code detected.
#pragma warning disable 162
// Missing XML comment for publicly visible type or member 'Type_or_Member'
#pragma warning disable 1591
// CLS compliance checking will not be performed on 'type' because it is not visible from outside this assembly.
#pragma warning disable 3019
// 'type' does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute.
#pragma warning disable 3021

[System.CodeDom.Compiler.GeneratedCode("ANTLR", "<ANTLRVersion>")]
[System.CLSCompliant(false)]
public class ...
like image 70
Sam Harwell Avatar answered Oct 06 '22 01:10

Sam Harwell