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的代码风格。

        

        

  • 相关阅读:
    redhat 关机注销命令详解
    CentOS网络配置详解
    Red Hat 6网络配置笔记
    H3C三层交换机S5500初始配置+网络访问策略
    python 发邮件 ,转载:https://mp.weixin.qq.com/s/kmNZ04MlDve4AmCCOoT2HA
    解决不能右键查看元素的问题, 转载:https://mp.weixin.qq.com/s/V_fpPN62Kdf0bz6zgFpVCg
    这几点鲜有人知的爬虫技巧,让你爽歪歪 转载:https://mp.weixin.qq.com/s/52luElhn4nRBZCdQMGEhnw
    一个反爬 JS 逆向分析的例子 转载:https://mp.weixin.qq.com/s/2luhB-AhMIzxVh6rPERzCA
    ssh 端口转发 转载:https://mp.weixin.qq.com/s/uesOCt9gmdST-HpwYTKsIw
    爬虫视频
  • 原文地址:https://www.cnblogs.com/GODYCA/p/3136914.html
Copyright © 2011-2022 走看看