如何配置 StyleCop 以抑制生成代码的警告?

发布于 2024-08-08 17:01:19 字数 299 浏览 14 评论 0原文

另一个项目,Visual Studio 的代码分析有这个选项。但我找不到 StyleCop(又名源分析)。

我想要忽略的文件是 dbml 的 .designer.cs 代码,其中包含 // 标记。 一篇博客文章告诉我这就足够了,但就我而言还不够。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴我老 2024-08-15 17:01:19

StyleCop:如何忽略生成的代码

编辑:这是我在 ANTLR 的生成语法中使用标头。这实际上是 StringTemplate 模板的主体,因此两个 \> 条目实际上只是转义的 > 标记。除了 标签和 [GenerateCode] 属性之外,我们仍然必须禁用代码分析期间出现的一些警告。

//------------------------------------------------------------------------------
// \<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 ...

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 ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文