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

后端 未结 9 2134
眼角桃花
眼角桃花 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 \|.

    0 讨论(0)
  • 2021-01-29 22:05

    When you use Windows (CMD) but don't want to use the PowerShell cannon to shoot this fly, try this:

    for /r %t in (*.cpp *.h) do clang-format -i -style=WebKit "%t"
    

    Don't forget to duplicate the two %s if in a cmd script.

    0 讨论(0)
  • 2021-01-29 22:11

    What about:

    clang-format -i -style=WebKit *.cpp *.h
    

    in the project folder. The -i option makes it inplace (by default formatted output is written to stdout).

    0 讨论(0)
提交回复
热议问题