Skip to content

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

  1. Create .clang-format at the repo root with chosen style (LLVM, Google, or a custom config starting from BasedOnStyle: LLVM).
  2. Add a format CMake target or a Python formatting entrypoint.
  3. Enable clang-format on-save in VS Code (xaver.clang-format extension).
  4. Add a Python CI check that verifies no formatting diff exists.
# .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-format file 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.