Description
We should enforce a consistent C/C++ code style by running clang-format as part of the Git pre-commit hook. This prevents unformatted code from being committed and reduces review noise.
Goals
- Ensure all staged C/C++ sources are formatted according to the project’s
.clang-format.
- Fail the commit if formatting is required (or optionally auto-apply formatting and re-stage).
- Keep the hook fast and only operate on staged files.
Proposed implementation
- Integrate
clang-format into the existing pre-commit workflow (e.g., via pre-commit framework).
- Use
.clang-format at repo root as the single source of truth.
- Run only on relevant file extensions:
*.c, *.h, *.cc, *.cpp, *.cxx, *.hpp, *.hxx, *.inl
- Operate only on staged files (avoid scanning the full repo).
Suggested behavior (pick one)
- Check-only (recommended for CI parity)
- Run
clang-format and fail if the output would change files.
- Print the list of files requiring formatting and how to fix:
clang-format -i <files> (or pre-commit run -a)
- Auto-fix
- Run
clang-format -i on staged files, then re-stage modified files.
- Commit proceeds if everything is formatted.
Acceptance criteria
- Committing unformatted C/C++ code is blocked (or auto-fixed) by the hook.
- Hook runs in reasonable time on typical commits (only staged files).
- Works on macOS and Linux (and ideally Windows if supported).
- Clear developer instructions are added to
CONTRIBUTING.md (or equivalent).
Tasks
Notes
- Prefer using
clang-format from a pinned LLVM/clang toolchain version (or document the required minimum version) to avoid formatting diffs across environments.
Description
We should enforce a consistent C/C++ code style by running
clang-formatas part of the Gitpre-commithook. This prevents unformatted code from being committed and reduces review noise.Goals
.clang-format.Proposed implementation
clang-formatinto the existingpre-commitworkflow (e.g., viapre-commitframework)..clang-formatat repo root as the single source of truth.*.c, *.h, *.cc, *.cpp, *.cxx, *.hpp, *.hxx, *.inlSuggested behavior (pick one)
clang-formatand fail if the output would change files.clang-format -i <files>(orpre-commit run -a)clang-format -ion staged files, then re-stage modified files.Acceptance criteria
CONTRIBUTING.md(or equivalent).Tasks
clang-formathook to.pre-commit-config.yaml(or hook scripts if not usingpre-commitconfig)..clang-formatis present and documented (or add it if missing).CONTRIBUTING.md(install + how to run manually).pre-commit run --all-filesto keep CI consistent.Notes
clang-formatfrom a pinned LLVM/clang toolchain version (or document the required minimum version) to avoid formatting diffs across environments.