cpplint.py
(right-click to download)
is a style checker for C and C++ that checks code for consistency with the
Google C++ Style Guide.
cpplint.py
is not a full compiler for C/C++ programs, so
it does not examine the detailed semantics of your code, but it does a good
job of checking general code organization and layout.
We suggest you use it to check all of your code as you write it
and again before you submit code for evaluation and grading.
Generally you should repair any problems that it reports, although occasionally
it will flag something that doesn't apply specifically to CSE 333.
When that happens, often it is a good topic to bring up on the course
discussion board to decide how best to handle the situation.
To use the program, download the
cpplint.py
file by right-clicking on the link
or using the link on
the CSE 333 resources page. There also are links on some assignments and exercises.
You can store the file wherever you'd like. The following examples assume that
cpplint.py
is in the same directory as the code being checked,
but if it is somewhere else, use an appropriate file path to access it or put the
directory containing it in your shell $PATH
variable.
.c
files and .h
headers with C declarations)Assuming that the cpplint.py
file is in your current directory,
enter the following command to check C source files (note the --clint
option):
$bash ./cpplint.py --clint [files to check]The output should look something like these examples:
$bash ./cpplint.py --clint hw1/LinkedList.c hw1/LinkedList.c:44: Missing space before ( in while( [whitespace/parens] [5] hw1/LinkedList.c:44: Missing space before { [whitespace/braces] [5] hw1/LinkedList.c:108: Missing space before ( in if( [whitespace/parens] [5] hw1/LinkedList.c:108: Missing space before { [whitespace/braces] [5] Done processing hw1/LinkedList.c $bash ./cpplint.py --clint ex1.c Done processing ex1.c
.cc
files and .h
headers with C++ declarations)Again, assuming that cpplint.py
is in your current directory,
do the following to check C++ source files (the same as for C code, but without
the --clint
option this time):
$bash ./cpplint.py [files to check]A couple of examples:
$bash ./cpplint.py ex9.cc ex9:10: Closing ) should be moved to the previous line [whitespace/parens] [2] Done processing ex9.cc Total errors found: 1 $bash ./cpplint.py ex10.cc Done processing ex10.cc
Normally cpplint.py
should work correctly out of the box.
The most common error is if the file does not have execute permissions, in
which case you'll get this message:
$bash: ./cpplint.py: Permission deniedIf that happens, give the file execute permissions by running the command
chmod +x cpplint.py
.
If you encounter other problems, please use the course discussion board to help find a solution. If common issues surface, we'll add them here.