How to call clang-format over a cpp project folder?

后端 未结 9 2138
眼角桃花
眼角桃花 2021-01-29 21:43

Is there a way to call something like clang-format --style=Webkit for an entire cpp project folder, rather than running it separately for each file?

I am us

9条回答
  •  清歌不尽
    2021-01-29 22:05

    First create a .clang-format file if it doesn't exist:

    clang-format -style=WebKit -dump-config > .clang-format
    

    Choose whichever predefined style you like, or edit the resulting .clang-format file.

    clang-format configurator is helpful.

    Then run:

    find . -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-format -style=file -i {} \;
    

    Other file extensions than cpp, hpp, cc and cxx can be used in the regular expression, just make sure to separate them with \|.

提交回复
热议问题