使用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.

         原文地址:原文地址

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

使用图例如下:


目录
相关文章
|
11月前
|
网络协议 Unix Shell
FreeBSD的特点是什么?如何使用?
【10月更文挑战第29天】FreeBSD的特点是什么?如何使用?
321 2
|
11月前
|
机器学习/深度学习 数据采集 人工智能
运维新纪元:AIOps引领智能运维变革####
本文探讨了人工智能与运维管理深度融合的前沿趋势——AIOps(Artificial Intelligence for Operations),它通过机器学习、大数据分析等技术手段,为现代IT运维体系带来前所未有的智能化升级。不同于传统依赖人力的运维模式,AIOps能够实现故障预测、自动化修复、性能优化等功能,大幅提升系统稳定性和运营效率。文章将深入分析AIOps的核心价值、关键技术组件、实施路径以及面临的挑战,旨在为读者揭示这一新兴领域如何重塑运维行业的未来。 ####
|
前端开发 安全 Java
Spring Boot项目中VO层设计:选择继承或组合的灵活实践
Spring Boot项目中VO层设计:选择继承或组合的灵活实践
829 0
|
人工智能 自然语言处理 开发工具
Agent调研--19类Agent框架对比(下)
Agent调研--19类Agent框架对比(下)
3713 0
|
数据安全/隐私保护
(只需五步)注册谷歌账号详细步骤,解决“此电话号码无法验证”问题
注册google一直不方便,因为如果直接去google官网注册,那么它大概率会显示“此电话号码无法用于进行验证”接下来,按着教程来一步步做,就可以实现跳过此限制,成功用手机号注册google了。很简单的。
15334 1
基于sortablejs实现拖拽element-ui el-table表格行进行排序
基于sortablejs实现拖拽element-ui el-table表格行进行排序
el-table 取消鼠标移入时变色
el-table 取消鼠标移入时变色
302 0
|
存储 程序员 Python
用Python实现微信多开,1行代码免费用
用Python实现微信多开,1行代码免费用
540 2
用Python实现微信多开,1行代码免费用
|
域名解析 缓存 负载均衡
记一次Nginx DNS缓存导致转发问题
记一次Nginx DNS缓存导致转发问题
11757 3
|
机器学习/深度学习 移动开发 前端开发
Sublime Text3快捷键大全--正则表达式元字符-详细说明
Sublime Text3快捷键大全--正则表达式元字符-详细说明
443 0