clang-format — enforce consistent code formatting
Summary¶
No code formatter is currently enforced. This creates noise in diffs and
makes code review harder. clang-format with LLVM 22.1.0 (already installed)
can enforce a consistent style.
Setup Steps¶
- Create
.clang-formatat the repo root with chosen style (LLVM, Google, or a custom config starting fromBasedOnStyle: LLVM). - Add a
formatCMake target or a Python formatting entrypoint. - Enable clang-format on-save in VS Code (
xaver.clang-formatextension). - Add a Python CI check that verifies no formatting diff exists.
Recommended Config Starting Point¶
# .clang-format
BasedOnStyle: LLVM
IndentWidth: 4
TabWidth: 4
UseTab: ForContinuationAndIndentation
BreakBeforeBraces: Allman
ColumnLimit: 120
Adjust to match existing code style — the goal is consistency, not forcing a different style on all existing code at once.
Migration Strategy¶
Do not reformat all files in one commit. That makes git blame useless.
Instead:
1. Apply formatting only to files changed in each new PR.
2. Once the majority of files are formatted, do a single bulk-format
commit with no logic changes and a clear commit message.
Acceptance Criteria¶
- [ ]
.clang-formatfile committed to repo root - [ ] CI check fails if any staged file has formatting diff
- [ ] VS Code formats on save
Prerequisite¶
CI-001 (CMake) — not strictly required but recommended so CI runs in the same environment as the build.