【C++】cpplint Bertha 。 2022-06-08 09:24 179阅读 0赞 ## 1、简介 ## `cpplint`或`cpplint.py`是Google开发的一款代码静态检查工具,Python实现,用以检查C++代码是否遵循Google代码规范,还可以发现语法错误。 ## 2、示例 ## `test.cpp`示例代码如下: int foo(int a) { if (a < 0) { a = 0; } return a; } int bar(int a) { if (a<0) a = 0; return a; } int func(int a) { if(a < 0) a = 0; return a; } 执行cpplint: $ ./cpplint.py test.cpp 结果: test.cpp:0: No copyright message found. You should have a line: "Copyright [year] <Copyright Owner>" [legal/copyright] [5] test.cpp:9: Missing spaces around < [whitespace/operators] [3] test.cpp:15: Missing space before ( in if( [whitespace/parens] [5] Done processing test.cpp Total errors found: 3 第0行缺少copyright。 第9行的`<`操作符两边缺少空格。 第15行的`(`圆括号与`if`关键字之间缺少空格。 ## 3、参考 ## 【Google C++代码规范】[https://google.github.io/styleguide/cppguide.html][https_google.github.io_styleguide_cppguide.html] 【Wiki】[https://en.wikipedia.org/wiki/Cpplint][https_en.wikipedia.org_wiki_Cpplint] 【源码】[https://pypi.python.org/pypi/cpplint/][https_pypi.python.org_pypi_cpplint] [https_google.github.io_styleguide_cppguide.html]: https://google.github.io/styleguide/cppguide.html [https_en.wikipedia.org_wiki_Cpplint]: https://en.wikipedia.org/wiki/Cpplint [https_pypi.python.org_pypi_cpplint]: https://pypi.python.org/pypi/cpplint/
还没有评论,来说两句吧...