Cpplint is a python script that Google uses as its own C + + code specification Checker tool. If your company also uses the Google C + + code specification, then you need to understand the next cpplint.
Let's talk about the simple use of cpplint under Windows:
1. Download cpplint.py source code from http://google-styleguide.googlecode.com/svn/trunk/cpplint/cpplint.py, and store them in the D:\soft\Cpplint\cpplint.py;
2. Download Python-2.7.10.msi from https://www.python.org/;
3. Install Python and add D:\ProgramFiles\Python27 to the system environment variable path;
4. Write a test file e:/tmp/test.cpp, which reads as follows:
#include <iostream>using namespace Std;int main () {cout<< "Hello!" <<endl;return 0;}
5. Open a command prompt, as follows, and you will find a total of 9 errors:
6. Follow the error prompts, modify the Test.cpp file, the modified file is Test1.cpp, the contents are as follows:
/*# Copyright (c) Bingchun Feng. All rights reserved.*/#include <iostream>int main () { std::cout << "Hello!" << Std::endl; return 0;}
7. Perform, as follows, to find all the errors cleared out:
8. cpplint.py default supported file formats include (see cpplint.py file Line No. 502):. CC,. h,. cpp,. cu,. Cuh, default does not support. hpp files, such as TEST3.HPP, execution will error:
/*# Copyright (c) Bingchun Feng. All rights reserved.*/#ifndef Cpp_lint_test_hpp_#define cpp_lint_test_hpp_class A {public: int Add (int A, int b);
int mul (int a, int b); Private: int m_a, M_b;} #endif //Cpp_lint_test_hpp_
9. Change the cpplint.py file after line No. 502 to support the. hpp file:
_valid_extensions = set ([' CC ', ' h ', ' cpp ', ' cu ', ' cuh ', ' hpp ')
10. Other relevant options Description:
(1), for each problem found, Cpplint will give a confidence score in the interval [1, 5], the higher the score, the more positive the problem, you can control the output through the verbose option level, such as, the confidence score of 1, 2 will no longer output:
E:\tmp>python d:/soft/cpplint/cpplint.py--verbose=3 Test.cpp
(2), if some parts of the code do not want to be checked, or is considered to be cpplint generated false positives, only need to add comments "//Nolint" at the end of the corresponding code line, Cpplint will skip these lines, such as:
return 0; Nolint
(3), if you need to let Cpplint support other file extensions, and do not want to modify the source code, you can pass extensions options such as:
E:\tmp>python d:/soft/cpplint/cpplint.py--extensions=hpp Test.cpp
(4), you can specify the error message output format, support two formats, the default is Emacs format, also supports the Visual Studio format, can be specified through the output option, such as:
E:\tmp>python d:/soft/cpplint/cpplint.py--output test.cpp 2>log.txt
(5), through the filter option, according to their own needs to filter out the specific warning, "-foo" means not to output a warning with foo, "+foo" indicates the output with Foo warning, such as:
E:\tmp>python d:/soft/cpplint/cpplint.py--filter=-whitespace/tab,+whitespace/ending_newline test.cpp
(6), you can use the counting option to display the number of errors for each category, such as:
e:\tmp>pythond:/soft/cpplint/cpplint.py--counting=detailed Test.cpp
(7), the LineLength option can be used to control the maximum length of each line, the default is 80 characters, if the maximum length of each line is allowed to be 120:
E:\tmp>python d:/soft/cpplint/cpplint.py--linelength=120 Test.cpp
For more detailed information on the options, please refer to cpplint.py.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The use of the Google Code specification tool Cpplint