Google has an awesome C++ coding style guideline and they have done a very good job on creating a very handy C++ lint based on that guideline.

I have downloaded it renamed that script to cpplint, chmod to executable and move to /usr/bin to use. (Also changed the shebang to /us/bin/env python, because default shebang uses the python2.4)

But this script solely itself can not traverse the files in a folder recursively and output the errors to a file, hence I had to write a basic bash script by myself:

1
2
3
4
5
6
7
8
9
#!/bin/bash
if [ -n "$2" ]; then
  exec 2>$2
  if [ -d "$1" ]; then
    find $1 -type f -iname \*.cc -or -iname \*.h -exec sh -c  "cpplint --filter=+build,+readability,+runtime,-whitespace --output=vs7 '{}'" \; 
  fi
else 
  echo "Please enter a log file name to output the errors to and a path for the source folder to traverse for errors: ./check_cpplint [search folder] [log file]"
fi

First parameter of this script is the path of the source code’s folder that your C++ codes are located in and the second one is the file that the errors will be written to.

BTW there is another great c++ lint called cppcheck.

Related Posts: