admin 管理员组

文章数量: 1184232


2024年3月26日发(作者:ahrefs是什么公司)

Cpplint

是google推出的C++编码规范检查工具(python脚本),

/p/google-styleguide/ 这是google使用的一个C++代码风

格规范,可以作为平常开发的参考。

Cpplint用法比较简单,首先系统需要安装python工具,然后把放在项

目目录下,再进入命令行,它的的语法结构如下:

Syntax: [ -- verbose= #] [ -- output= vs7] [ -- filter=- x,+ y,...]

[ -- counting= total| toplevel| detailed]

< file> [ file] ...

cpplint对于发现的每一个问题, 都会给出一个位于区间[1, 5]之间的置信度评分, 分

数越高就代表问题越肯定. 你可以通过verbose选项控制输出哪些级别.

如果代码中有些部分不希望被检查, 或者你认为cpplint产生了误报, 只需要在行尾添

加注释 ‘// NOLINT’, cpplint就会跳过这些行. 如果你想过滤掉特定的警告, 就需要设

置filter选项了(-表示不输出, +表示输出), 比如:

Examples: -- filter=- whitespace,+ whitespace/ braces

-- filter= whitespace,runtime/ printf,+ runtime/ printf_format

-- filter=- ,+ build/ include_what_you_use

cpplint的输出格式有’emacs’和’vc7′两种, 默认是’emacs’.

cpplint只分析.cc, cpp 和 .h文件, 一次可以分析一到多个

以下是我自己在hisi-v7300的libpng文件里找了个.h文件分析了下代码规范,所得

出的结果。

root@ubuntu11:/file/statsvninput/hisi-v7300/libpng#python

/home/kes/my-app/src/main/ -verbose=5 --output=vs7

--filter=-whitespace,-readability,-legal pngconf.h

pngconf.h(20): #ifndef header guard has wrong style, please use:

LIBPNG_PNGCONF_H_ [build/header_guard] [5]

pngconf.h(1665): #endif line should be "#endif // LIBPNG_PNGCONF_H_"

[build/header_guard] [5]

pngconf.h(1642): Never use sprintf. Use snprintf instead. [runtime/printf]

[5]

pngconf.h(1643): Never use sprintf. Use snprintf instead. [runtime/printf]

[5]

pngconf.h(1645): Never use sprintf. Use snprintf instead. [runtime/printf]


本文标签: 规范 输出 工具 需要 代码