chore: add automatic clang-format with pre-commit hooks#572
chore: add automatic clang-format with pre-commit hooks#572jorgesg82 merged 5 commits intodevelopmentfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces repository-wide C/C++ formatting infrastructure using clang-format integrated via pre-commit, with supporting CI checks and developer setup documentation.
Changes:
- Add
.clang-formatstyle configuration and apre-commithook to runclang-format. - Add a helper script to install git hooks for
pre-commit/pre-push. - Add a GitHub Actions workflow to run formatting checks in CI, and document local setup in the README.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
tools/install-git-hooks.sh |
Adds a helper script to install pre-commit hooks locally. |
README.md |
Documents local formatter setup and manual formatting execution. |
.pre-commit-config.yaml |
Defines the clang-format hook and its scope. |
.github/workflows/format-checks.yml |
Adds CI job to run pre-commit formatting checks. |
.clang-format |
Adds shared clang-format style rules for the repo. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| echo "Instala con: pip install pre-commit" | ||
| exit 1 | ||
| fi | ||
|
|
There was a problem hiding this comment.
This installer only checks for pre-commit, but the configured hook uses language: system and calls clang-format, so the hooks will fail if clang-format isn’t installed locally. Consider also checking command -v clang-format and providing install guidance (and/or switch to a pinned pre-commit clang-format repo to avoid system dependencies).
| if ! command -v clang-format >/dev/null 2>&1; then | |
| echo "clang-format no esta instalado." | |
| echo "Instala clang-format con tu gestor de paquetes (por ejemplo: 'apt install clang-format' o 'brew install clang-format')." | |
| exit 1 | |
| fi |
|
|
||
| Install hooks once: | ||
| ```sh |
There was a problem hiding this comment.
The README setup instructions don’t mention installing clang-format, but the pre-commit hook currently relies on a system clang-format binary (language: system). Add the required clang-format install step (or change the hook to a pinned pre-commit clang-format repo so developers don’t need to install it manually).
| Install hooks once: | |
| ```sh | |
| Make sure `clang-format` is installed and available on your `PATH`, as the pre-commit hook invokes the system `clang-format` binary. | |
| Install dependencies and hooks once: | |
| ```sh | |
| # Install clang-format (examples; use the one appropriate for your OS) | |
| # Debian/Ubuntu: sudo apt-get install clang-format | |
| # Fedora: sudo dnf install clang-tools-extra | |
| # macOS (Homebrew): brew install clang-format |
| - name: Install tools | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| python -m pip install pre-commit | ||
| sudo apt-get update | ||
| sudo apt-get install -y clang-format | ||
|
|
There was a problem hiding this comment.
CI installs whatever clang-format version is provided by Ubuntu apt at the time, while local dev machines may have different versions (and the hook uses language: system). To avoid inconsistent formatting results, consider pinning clang-format via a pre-commit repo (mirrors-clang-format) or explicitly installing a specific clang-format-<version> package here and documenting the required version locally.
c451752 to
66ea811
Compare
Summary
.clang-formatstyle for C/C++.pre-commit-config.yamlwith clang-format hook on commit/pushtools/install-git-hooks.sh.github/workflows/format-checks.ymlNotes