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.
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.
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...
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:
发布评论
评论(7)
添加规则是或将是 官方支持:
就我们的“内部”风格而言,我通过禁用一些 StyleCop 规则非常接近:
你可以这样做通过修改安装目录中的 Settings.StyleCop 文件来全局设置,尽管我采取了将一个文件放在每个项目的源代码树的根目录下的方法。
最终的效果正是我们想要的。 有一些“内部”选择值得标记,但即使没有它们,StyleCop 也为我们带来了很多价值。
Adding rules is, or is going to be, officially supported:
In terms of our "in-house" style, I got pretty close by disabling a handful of StyleCop rules:
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.
StyleCop for ReSharper 可以提供帮助(您需要购买 ReSharper,但该插件是免费的):
我们还提供了“StyleCop 友好的 ReSharper 代码样式共享设置文件”,该文件将 ReSharper 配置为以 StyleCop 友好的方式自动格式化代码。
StyleCop for ReSharper could help (you'd need to purchase ReSharper, but the plug-in is free):
We also ship a "StyleCop friendly ReSharper Code Style Sharing Settings file" which configures ReSharper to automatically format code in a StyleCop friendly manner.
Mono 有 Gendarme,尽管它是开源的,而不是商业的。
There's Gendarme from Mono, although it's Open Source, not commercial.
StyleCop 的替代方案或良好补充是使用商业工具 NDepend 。 使用此工具,我们可以通过 LINQ 查询编写代码规则 (即 CQLinq) 。 免责声明:我是该工具的开发人员之一
超过200个代码默认情况下建议规则,其中包括设计、架构、代码质量、代码演化、 命名约定、死代码、.NET Fx 使用...
CQLinq 致力于编写可以在 Visual Studio 中实时验证,或者可以是 在构建过程中进行验证并在 HTML/javascript 报告中报告。
与 StyleCop 甚至 FxCop 相比,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:
Agent Smith 非常好。 它需要 Resharper。
Agent Smith is very nice. It requires Resharper.
查看 Submain 中的 CodeIt.Right。
Take a look at CodeIt.Right from Submain.
我经常编写单元测试来反映我的类型并检查是否违反了我的自定义规则。
以下是验证某些类型是否不可变的示例: 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.