您的位置:首页 > 编程语言

使用StyleCop进行代码审查

2014-01-13 08:34 411 查看
StyleCop analyzes C# source code to enforcea set of style and consistency rules. It can be run from inside of Visual Studio orintegrated into an MSBuild project

SourceAnalysis(StyleCop)不是代码格式化(代码美化)工具,而是代码规范检查工具(CodeReview 工具),它不仅仅检查代码格式,而是编码规范,包括命名和注释等。SourceAnalysis(StyleCop)目的是帮助项目团队执行一系列常用的源代码格式规范,这些规范是关于如何开发布局规整,易读,易维护并且文档良好的优雅代码的(help
teams enforce a common set of best practices for layout, readability,maintainability, and documentation of C# source code)。

SourceAnalysis (StyleCop) 现在包含了 200 个左右的最佳实践规则(bestpractice rules),这些规则与 VisualStudio 2005 和  VisualStudio 2008 中默认的代码格式化规则是一致的。

  SourceAnalysis(StyleCop)可以作为 Visual studio 的插件运行.

  同时SourceAnalysis (StyleCop)也可以作为 MSBuild 任务(安装时有选项)通过命令行执行。

  SourceAnalysis(StyleCop)是代码级别的,更适合于程序员在编程过程中使用。

  SourceAnalysis(StyleCop)不提供灵活的规则设置,而是使用所谓 one-size-fits-all的方式强制人们用同样的习惯书写代码,因此 SourceAnalysis (StyleCop)的终极目标是:The ultimate goal of Source Analysis is to allow you to produce elegant,consistent code that your team members and others who view your code
will findhighly readable.

  SourceAnalysis(StyleCop)检查的规则包括:

布局(Layout of elements, statements,expressions, and query clauses )

括号位置(Placement of curly brackets,parenthesis, square brackets, etc )

空格(Spacing around keywords andoperator symbols )

行距(Line spacing )

参数位置(Placement of method parameterswithin method declarations or method calls )

元素标准排列(Standard ordering of elementswithin a class )

注释格式(Formatting of documentationwithin element headers and file headers )

命名(Naming of elements, fields andvariables )

内置类型的使用(Use of the built-in types )

访问修饰符的使用(Use of access modifiers )

文件内容(Allowed contents of files )

Debugging文本(Debugging text)

开始使用这些工具时可能会觉得对我们要求太苛刻,但根据微软自己的经验:aftera short adjustment period, they came to appreciate the rules enforced by SourceAnalysis, and even began to find it difficult to read
code not written in thisstyle.

原文地址:原文地址

工具下载地址:工具下载地址

使用图例如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: