6

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.

1 Answer 1

6

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 ...
3
  • 2
    It doesn't work in the current version. I am not the only one complaining about it, there is more people in their bug tracker.
    – Jader Dias
    Oct 19, 2009 at 18:31
  • -1: this was not the question: Jader did not ask whether there are other options to ignore auto-generated code, but rather why it does not work the // <autogenerated> way. I think everybody who can google will be on your linked page first, but it doesn't help if it doesn't work. It does not work for me either, even though my file was indeed auto-generated and the header has been set by that software.
    – Sören
    Apr 9, 2011 at 1:43
  • I updated the post with a code sample. I notice that the question refers to <autogenerated> where my code is actually using <auto-generated>. Perhaps this is the problem? Jan 17, 2012 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.