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 using clang-format.py
and vim
to do this, but I assume there is a way to apply this once.
To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc . It should work on macOS/Linux/Windows. The workflow to format your changed code: Make codes changes in Electron repository.
Run clang-tidy on you entire codebaseIn the build folder, run run-clang-tidy . It might be a different command ( run-clang-tidy.py or run-clang-tidy-VERSIONNUMBER ) depending on your distro's packaging preference.
clang-format file, we need to place it in the project folder or in any parent folder of the file you want to format. clang-format.exe searches for the config file automatically starting with the folder where the file you want to format is located, all the way to the topmost directory.
Unfortunately, there is no way to apply clang-format recursively. *.cpp
will only match files in the current directory, not subdirectories. Even **/*
doesn't work.
Luckily, there is a solution: grab all the file names with the find
command and pipe them in. For example, if you want to format all .h
and .cpp
files in the directory foo/bar/
recursively, you can do
find foo/bar/ -iname *.h -o -iname *.cpp | xargs clang-format -i
See here for additional discussion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With