Visual Studio 的 StyleCop 替代方案?

发布于 2024-07-09 10:57:23 字数 1560 浏览 9 评论 0 原文

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

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

发布评论

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

评论(7

您的好友蓝忘机已上羡 2024-07-16 10:57:23

添加规则是或将是 官方支持

按照承诺,我们还将发布
StyleCop 的 SDK 文档
解释如何编写自定义规则
以及如何将该工具集成到
自定义构建环境。 软件开发工具包
文档目前正在最终阶段
审查,我们非常希望发布它
很快。
-- JasonAll

就我们的“内部”风格而言,我通过禁用一些 StyleCop 规则非常接近:

  • 文件头 (SA1633-SA-1640)
  • 代码排序 (SA1200-SA1202)
  • 需要“这个”(SA1101)

你可以这样做通过修改安装目录中的 Settings.StyleCop 文件来全局设置,尽管我采取了将一个文件放在每个项目的源代码树的根目录下的方法。

最终的效果正是我们想要的。 有一些“内部”选择值得标记,但即使没有它们,StyleCop 也为我们带来了很多价值。

Adding rules is, or is going to be, officially supported:

As promised, we will also be releasing
SDK documentation for StyleCop
explaining how to author custom rules
and how to integrate the tool into
custom build environments. The SDK
documentation is currently under final
review and we hope to release it very
soon.
-- JasonAll

In terms of our "in-house" style, I got pretty close by disabling a handful of StyleCop rules:

  • File Headers (SA1633-SA-1640)
  • Code ordering (SA1200-SA1202)
  • Requiring "this" (SA1101)

You can do this globally by modifying the Settings.StyleCop file in the installation directory, though I've taken the approach of putting one at the root of our source tree in each project.

The end effect is much what we want. There are a handful of "in-house" choices that would be nice to flag, but even without them StyleCop is delivering a lot of value for us.

我偏爱纯白色 2024-07-16 10:57:23

StyleCop for ReSharper 可以提供帮助(您需要购买 ReSharper,但该插件是免费的):

ReSharper 的 StyleCop 现已成为功能
完成即已达到
功能与 StyleCop 4.3 相同。

共有 148 条 StyleCop 规则。

  • 其中 38 个必须手动修复(通常是因为您必须键入
    描述性文本或重命名变量)。
  • 在剩余的 110 条规则中,有 58 条由 R# Code Cleanup 修复(静默)
    模式)。
  • 在目前剩下的 52 个中,我们有代码清理规则,可以修复所有问题
    自动地。

我们还提供了 106 个快速修复
提供适当的上下文菜单修复
违反110条规则
可以自动修复

我们还提供了“StyleCop 友好的 ReSharper 代码样式共享设置文件”,该文件将 ReSharper 配置为以 StyleCop 友好的方式自动格式化代码。

StyleCop for ReSharper could help (you'd need to purchase ReSharper, but the plug-in is free):

StyleCop for ReSharper is now feature
complete in that is has reached
feature parity with StyleCop 4.3.

There are 148 StyleCop rules.

  • 38 of these must be fixed manually (normally because you have to type
    descriptive text or rename variables).
  • Of the remaining 110 rules 58 are fixed by R# Code Cleanup (silent
    mode).
  • Of the 52 now remaining we have Code Cleanup rules that fix all of
    them automatically.

We also provide 106 Quick Fixes that
provide in place context menu fixes
for violations for the 110 rules that
can be fixed automatically

We also ship a "StyleCop friendly ReSharper Code Style Sharing Settings file" which configures ReSharper to automatically format code in a StyleCop friendly manner.

喜你已久 2024-07-16 10:57:23

Mono 有 Gendarme,尽管它是开源的,而不是商业的。

There's Gendarme from Mono, although it's Open Source, not commercial.

九命猫 2024-07-16 10:57:23

StyleCop 的替代方案或良好补充是使用商业工具 NDepend 。 使用此工具,我们可以通过 LINQ 查询编写代码规则 (即 CQLinq) 免责声明:我是该工具的开发人员之一

超过200个代码默认情况下建议规则,其中包括设计架构代码质量代码演化命名约定死代码.NET Fx 使用...

CQLinq 致力于编写可以在 Visual Studio 中实时验证,或者可以是 在构建过程中进行验证并在 HTML/javascript 报告中报告

与 StyleCop 甚至 FxCop 相比,CQLinq 的优势在于可以直接编写代码规则,并立即获得结果。 建议使用设施来浏览匹配的代码元素。 具体来说,它看起来像这样:

CQLinq 代码规则

An alternative or a good complement to StyleCop would be to use the commercial tool NDepend. With this tool one can write Code Rule over LINQ Queries (namely CQLinq). Disclaimer: I am one of the developers of the tool

More than 200 code rules are proposed by default, these include design, architecture, code quality, code evolution, naming conventions, dead code, .NET Fx usage...

CQLinq is dedicated to write code rules that can be verified live in Visual Studio, or that can be verified during build process and reported in an HTML/javascript report.

The strength of CQLinq over StyleCop or even FxCop, is that it is straightforward to write a code rule, and get immediately results. Facilities are proposed to browse matched code elements. Concretely this looks like that:

CQLinq code rule

薄情伤 2024-07-16 10:57:23

Agent Smith 非常好。 它需要 Resharper。

Agent Smith is very nice. It requires Resharper.

一杆小烟枪 2024-07-16 10:57:23

查看 Submain 中的 CodeIt.Right

Take a look at CodeIt.Right from Submain.

长伴 2024-07-16 10:57:23

我经常编写单元测试来反映我的类型并检查是否违反了我的自定义规则。

以下是验证某些类型是否不可变的示例: http://blogs.msdn.com/kevinpilchbisson/archive/2007/11/20/enforcing-immutability-in-code.aspx

这是另一个有关单元测试命名的规则:
http://jbazuzicode.blogspot.com/ 2008/11/keeping-test-fixture-and-class-names.html

编辑:第二个链接似乎已经消失在时间的沙子中。

I often write unit tests to reflect over my types and check for violations of my custom rules.

Here's an example for verifying that certain types are immutable: http://blogs.msdn.com/kevinpilchbisson/archive/2007/11/20/enforcing-immutability-in-code.aspx

Here's another, for rules about unit test naming:
http://jbazuzicode.blogspot.com/2008/11/keeping-test-fixture-and-class-names.html

EDIT: The 2nd link seems to be lost to the sands of time.

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