Search code examples
ceclipsegoogle-style-guidecpplint

How to force cppstyle to use c and h files?


I am using cpptyle within eclipse to check my code style within my C-Project. So my file extensions are *.c and *.h.

cppstyle uses cpplint.py. The documentation of cpplint.py tells, that you have to use the extension parameter if you would like to check files, which do not have the extension cc, h, cpp, cu or cuh.

So in the commandline I use cpplint in this way:

cpplint.py –extensions=h,c src/*

Well, regarding to the documentation of cppstyle, it is not possible to pass any parameters to cpplint.py. The only way to configure cpplint.py is to use those CPPLINT.cfg files, which sadly do not support the extension parameter.

So finally it is not possible to check *.c files within eclipse.

How to force cppstyle to use c and h files?


Solution

  • I found a solution.

    1. Create an little bash script which looks like the fallowing and make it executable:
    #!/bin/bash
    /usr/bin/cpplint.py --extensions=h,c $@
    
    1. In Windows > Preferences/C/C++ > CppStyle: Insert the path to the newly created script instead pointing directly to the cpplint.py

    2. In Windows > Preferences/C/C++ > Code Analysis: Double click each item of the cpplint category and add in the scope's tab the file extension *.c.
      This can also be done by editing the file workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.codan.core.prefs.
      I used the Find&Replace function of my editor to do so for all items.

    This is really not a nice workaround, but it works at least for me.