使用StyleCop进行代码审查

简介:         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 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.

         原文地址:原文地址

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

使用图例如下:


相关文章
|
2月前
|
程序员
提高代码质量的五个技巧
【2月更文挑战第2天】写出高质量的代码是每个程序员的追求,但是实现这一目标并不容易。本文将介绍五个技巧,帮助你提高代码的质量。
38 1
|
10月前
|
XML 安全 Linux
C++代码审查工具Cppcheck和TscanCode
C++代码审查工具Cppcheck和TscanCode
|
安全 Java 测试技术
关于代码评审(CodeReview)那些不得不说的事儿
关于代码评审(CodeReview)那些不得不说的事儿
163 1
关于代码评审(CodeReview)那些不得不说的事儿
|
开发者
聊聊软件开发的代码审查
聊聊软件开发的代码审查
聊聊软件开发的代码审查
|
自然语言处理 监控 安全
如何提高代码质量
说起代码质量,脑子里会冒出很多词,命名规范、格式规范、日志规范、单元测试覆盖率... 但我觉得,代码质量总结起来就两个:好看和好用。 好看是指代码可读性好,容易理解、容易维护,别人接手了不骂你;好用则指代码健壮,不容易出错,机器跑着不骂你。即使出错,也容易定位,容易止损和恢复。
|
程序员 API
如何提高代码质量?
本文从 产品,接口,指标,日志,代码清晰度,代码复杂度 等方面,谈谈如何提高代码质量。
3935 0