linelength 参数
设置单行字符数量限制,使用方式:python cpplint.py --linelength=<字符数量>,如:设置单行字符数量限制为100字符,python cpplint.py --linelength=100。
filter 参数
设置静态检查规则,使用方式:python cpplint.py --filter=<规则列表>,如:关闭所有规则,并开启"检查逗号前后空格是否正确"规则,python cpplint.py --filter=-,+whitespace/comma。本文以2.0.2版本为例,介绍各规则的作用
| 主类别 | 子类别 | 说明 |
|---|---|---|
| whitespace | whitespace/blank_line | 检查空行数量/位置是否合理 |
| whitespace/braces | 检查大括号前后空格/换行是否合理 | |
| whitespace/comma | 检查逗号前后空格是否正确 | |
| whitespace/comments | 检查注释与代码/标记之间的空格 | |
| whitespace/empty_conditional_body | 检查条件语句是否为空且未使用注释占位 | |
| whitespace/empty_if_body | 检查if语句是否为空且未使用注释占位 | |
| whitespace/empty_loop_body | 检查是否存在空循环体问题 | |
| whitespace/end_of_line | 检查行尾是否多余空白或换行问题 | |
| whitespace/ending_newline | 检查文件末尾是否有单个换行 | |
| whitespace/forcolon | 检查for中冒号周围的空格 | |
| whitespace/indent | 检查缩进宽度/混用空格等 | |
| whitespace/indent_namespace | 检查命名空间内是否缩进 | |
| whitespace/line_length | 检查单行长度是否超过限制 | |
| whitespace/newline | 检查不当的换行/多余空行 | |
| whitespace/operators | 检查运算符周围的空格 | |
| whitespace/parens | 检查括号周围的空格 | |
| whitespace/semicolon | 检查分号前是否有多余空格 | |
| whitespace/tab | 检查是否使用了 Tab 缩进 | |
| whitespace/todo | 检查 TODO 注释的格式 | |
| readability | readability/alt_tokens | 检查是否使用C++替代的运算符,如and、or等 |
| readability/braces | 检查大括号格式 | |
| readability/casting | 检查类型转换的格式,不建议C风格强转 | |
| readability/check | 检查CHECK/EXPECT/ASSERT一类宏的可读性用法 |
|
| readability/constructors | 检查构造函数可读性 | |
| readability/fn_size | 检查函数体是否过长/过复杂 | |
| readability/inheritance | 检查继承相关可读性 | |
| readability/multiline_comment | 检查多行注释的格式与对齐 | |
| readability/multiline_string | 检查多行字符串的拆分/拼接方式是否规范 | |
| readability/namespace | 检查命名空间的结尾注释、缩进、嵌套可读性 | |
| readability/nolint | 检查NOLINT使用是否正确 |
|
| readability/nul | 检查空字符/NULL的写法与使用 | |
| readability/todo | 检查TODO注释格式 |
|
| readability/utf8 | 检查文件是否包含UTF-8编码的字符 | |
| runtime | runtime/arrays | 检查数组的使用是否安全(如避免越界) |
| runtime/casting | 检查运行时类型转换是否安全 | |
| runtime/explicit | 检查构造函数是否标记为explicit |
|
| runtime/int | 检查整数类型的选择是否合理 | |
| runtime/init | 检查变量是否已初始化 | |
| runtime/invalid_increment | 检查是否存在无效的自增自减用法 | |
| runtime/member_string_references | 检查是否返回了临时或内部字符串的引用 | |
| runtime/memset | 检查memset的使用是否安全 |
|
| runtime/operator | 检查运算符重载的使用是否合理 | |
| runtime/printf | 检查printf格式字符串和参数是否匹配 |
|
| runtime/printf_format | 检查printf格式字符串和参数是否匹配 |
|
| runtime/references | 检查引用传递是否安全 | |
| runtime/string | 检查std::string的不安全/低效用法 |
|
| runtime/threadsafe_fn | 检查函数是否线程安全 | |
| runtime/vlog | 检查日志宏(如VLOG)的使用是否正确 |
|
| build | build/c++11 | 检查是否使用了C++11特性 |
| build/c++17 | 检查是否使用了C++17特性 | |
| build/deprecated | 检查是否使用了已弃用的函数或特性 | |
| build/endif_comment | 检查#endif是否带有对应的注释 |
|
| build/explicit_make_pair | 检查std::make_pair是否显式指定了模板参数 |
|
| build/forward_decl | 检查前置声明的使用是否正确 | |
| build/header_guard | 检查头文件保护宏是否存在且命名/格式正确 | |
| build/include | 检查#include指令的路径或格式是否正确 |
|
| build/include_subdir | 检查是否带子目录路径 | |
| build/include_alpha | 检查头文件是否按字母顺序排列 | |
| build/include_order | 检查#include的顺序是否符合规范 |
|
| build/include_what_you_use | 检查是否包含了不必要的头文件 | |
| build/namespaces_headers | 检查头文件中是否使用了using namespace |
|
| build/namespaces_literals | 检查用户是否定义字面量的命名空间 | |
| build/namespaces | 检查命名空间是否规范 | |
| build/printf_format | 检查printf或类似函数的格式字符串是否正确 |
|
| build/storage_class | 检查存储类(如static)的使用是否正确 |
|
| legal | legal/copyright | 检查文件头部是否包含正确的版权声明 |