-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
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-formatinto the existingpre-commitworkflow (e.g., viapre-commitframework). - Use
.clang-formatat 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-formatand fail if the output would change files. - Print the list of files requiring formatting and how to fix:
clang-format -i <files>(orpre-commit run -a)
- Auto-fix
- Run
clang-format -ion 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
- Add
clang-formathook to.pre-commit-config.yaml(or hook scripts if not usingpre-commitconfig). - Ensure
.clang-formatis present and documented (or add it if missing). - Restrict hook to staged C/C++ files only.
- Add documentation in
CONTRIBUTING.md(install + how to run manually). - Add a small test/CI job (optional) that runs
pre-commit run --all-filesto keep CI consistent.
Notes
- Prefer using
clang-formatfrom a pinned LLVM/clang toolchain version (or document the required minimum version) to avoid formatting diffs across environments.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request