zoukankan      html  css  js  c++  java
  • C++代码风格检查

    1. 背景

        C++ 是 Google 大部分开源项目的主要编程语言. 正如每个 C++ 程序员都知道的, C++ 有很多强大的特性, 但这种强大不可避免的导致它走向复杂,使代码更容易产生 bug, 难以阅读和维护.

        为了加强代码的一致性,保持统一编程风格,使任何程序员都可以快速读懂你的代码,Google开发了一个C++代码风格检查工具(cpplint),但是该工具仅仅将检查结果输出到控制台,并不很容易读,也并不能很好的和代码结合在一起展示。没有一个html页面的检查报表,也不利于jenkins的集成展示,在这种强大的需求下,Cppstyle这款工具就诞生了。Cppstyle对原有工具的控制台输出做了,从繁杂的检查结果字符串中提出关键信息,结合代码文件,输出了html页面。简洁的页面,更方便的编码人员进行代码风格的修改。

      2. 工具介绍

        该工具在Google原有工具的基础上做了如下几点的改进:

        1. 支持对一个目录底下的所有源文件进行代码检查,同时支持针对一个源文件的代码检查

        2. 支持检查规则的定制,可以在当前目录底下的filter.sdp文件里指定检查规则,通过设置检查规则,可以将不需要检查的规则过滤掉,规则以逗号分隔

        3. 支持html页面展示

      3.  使用方法

        python Gaara.py -s sourcefile > result.html

        检查规则过滤:可在当前目录下filter.sdp设置,并以逗号分隔

        example:

         -whitespace,+whitespace/braces

        将过滤规则为whitespace,但是保留规则whitespace/braces,未指定规则默认保留。目前Google原始工具支持的规则如下:  

       

    'build/class',
      'build/deprecated',
      'build/endif_comment',
      'build/explicit_make_pair',
      'build/forward_decl',
      'build/header_guard',
      'build/include',
      'build/include_alpha',
      'build/include_order',
      'build/include_what_you_use',
      'build/namespaces',
      'build/printf_format',
      'build/storage_class',
      'legal/copyright',
      'readability/alt_tokens',
      'readability/braces',
      'readability/casting',
      'readability/check',
      'readability/constructors',
      'readability/fn_size',
      'readability/function',
      'readability/multiline_comment',
      'readability/multiline_string',
      'readability/namespace',
      'readability/nolint',
      'readability/streams',
      'readability/todo',
      'readability/utf8',
      'runtime/arrays',
      'runtime/casting',
      'runtime/explicit',
      'runtime/int',
      'runtime/init',
      'runtime/invalid_increment',
      'runtime/member_string_references',
      'runtime/memset',
      'runtime/operator',
      'runtime/printf',
      'runtime/printf_format',
      'runtime/references',
      'runtime/rtti',
      'runtime/sizeof',
      'runtime/string',
      'runtime/threadsafe_fn',
      'whitespace/blank_line',
      'whitespace/braces',
      'whitespace/comma',
      'whitespace/comments',
      'whitespace/empty_loop_body',
      'whitespace/end_of_line',
      'whitespace/ending_newline',
      'whitespace/forcolon',
      'whitespace/indent',
      'whitespace/labels',
      'whitespace/line_length',
      'whitespace/newline',
      'whitespace/operators',
      'whitespace/parens',
      'whitespace/semicolon',
      'whitespace/tab',
      'whitespace/todo'

      4.  创新点

        1. html页面展示,帮助开发人员,从繁杂的检查结果中解放出来,更加方便RD修改自己的代码

        2. 可定制检查规则,方便开发人员过滤不需要检查的规则

        2.  可以和持续集成jenkins融合在一起,目前已有RD使用。QA检查RD的代码风格。

        

        

  • 相关阅读:
    【微信分享遮罩层的实现】
    【1:添加音乐功能以及按钮的实:2:微信滑动页面向下滑动按钮】*************实用**************
    【浅谈html5 响应式布局之自动适应屏幕宽度】
    ajax请求下拉列表框的实现(面向对象封装类)
    获取网卡的MAC地址原码;目前支持WIN/LINUX系统 获取机器网卡的物理(MAC)地址(服务器端)
    Sublime Text3快捷键汇总
    完整的ajax请求投票点赞功能的实现【数据库表一(票数)表二(ip限制重复投票)】
    正则表达式验证电话号码的有效性。。。。。。。。。。。。。
    网站镜像如何建立
    水平分割 垂直分割 和 库表散列 概念 说明
  • 原文地址:https://www.cnblogs.com/GODYCA/p/3136914.html
Copyright © 2011-2022 走看看