Search code examples
regexgoogle-style-guidecpplint

How to use the exclude_files regex in cpplint?


I am using cpplint to check my sourcode agains the google style guide.

Cpplint's help says:

cpplint.py supports per-directory configurations specified in CPPLINT.cfg
    files. CPPLINT.cfg file can contain a number of key=value pairs.
    Currently the following options are supported:

    "exclude_files" allows to specify a regular expression to be matched against
    a file name. If the expression matches, the file is skipped and not run
    through liner.

Example file:
        filter=-build/include_order,+build/include_alpha
        exclude_files=.*\.cc

    The above example disables build/include_order warning and enables
    build/include_alpha as well as excludes all .cc from being
    processed by linter, in the current directory (where the .cfg
    file is located) and all sub-directories.

How I use cpplint:

I use cpplint by this command to check all files in my source folder: cpplint src/*.c

Well there is one special file foo.cc which must not be checked. So I tried to create a CPPLIN.cfg to use the exclude_files property. My file looks like this:

set noparent
filter=-build/include_dir
exclude_files=foo.cc

Nevertheless foo.cc is still checked.

What I have already tried to do:

I tried exclude_files=/.*\.cc/. This should exclude all files ending with *.cc. Nevertheless all files are still checked.

I tried to remove my filter from the file. This caused more errors than before. So I am now sure that my CPPLINT.cfg file is found by cpplint.

Question:

How to use the exclude_files regex in cpplint correctly?


Solution

  • Turns out apparently that the doc is wrong: exclude_files only excludes files in the same directory as CPPLINT.cfg, not in subdirectories. See https://github.com/google/styleguide/issues/220

    So the solution would be to create src/CPPLINT.cfg and put exclude_files=.*\.cc in it.