How to run cpplint recursively for nested directories using glob pattern


If you’re using Google’s orig­i­nal cpplin­ter then its dif­fi­cult to sup­port glob pat­tern on python ver­sion < 3.
Google does not main­tain the cpplin­ter. As there are many open PR.

There is a Forked of Google’s cpplin­ter which address most of the miss­ing fea­tures from the orig­i­nal ver­sion and is actively main­tained. Once you switch to the Forked ver­sion then you can pass --recursive flag to tra­verse files recur­sively. For example,


Solu­tion 1 [For Mac / *nix based sys­tems Only]

$python <path_to_cpplint.py> --recursive */* 

Here, */* glob pat­tern tells it to tra­verse all the nested files.


Solu­tion 2 [ For Win­dows and *nix based systems ]

$python <path_to_cpplint.py> --recursive <path_to_dir_where_you_want_to_run_linter_recursively> 

For exam­ple,

  • foo/bar/zoo/a/b/c/app.cpp
  • foo/bar/zoo/a/b/main.cpp
  • foo/bar/zoo/a/pch.h
$python <path_to_cpplint.py> --recursive bar 

will lint all three files nested inside bar direc­tory. This approach works on the Mac / *nix based sys­tems, too.


You may also like...