docs/code_style.md
This project uses clang-format to keep the code style consistent. The .clang-format file in the project root is based on the Google C++ style guide with a few project-specific tweaks.
Make sure clang-format is available before you use it:
Windows:
winget install LLVM
# or with Chocolatey
choco install llvm
Linux:
sudo apt install clang-format # Ubuntu/Debian
sudo dnf install clang-tools-extra # Fedora
macOS:
brew install clang-format
Format a single file:
clang-format -i path/to/your/file.cpp
Format the entire project:
# Run from the project root
find main -iname '*.h' -o -iname '*.cc' | xargs clang-format -i
Check formatting without modifying files (useful in CI / pre-commit):
clang-format --dry-run -Werror path/to/your/file.cpp
Visual Studio Code:
C_Cpp.formatting to clangFormat in settings.editor.formatOnSave.CLion:
Editor > Code Style > C/C++ in the settings.Formatter to clang-format.{ on the same line as the control statement).// clang-format off
your code
// clang-format on
Formatting fails:
clang-format is too old..clang-format file.Output differs from what you expected:
.clang-format in the project root is actually picked up..clang-format higher in the tree is winning.Questions and suggestions are welcome - please open an issue or a pull request.