Skip to content

chore: add pre-push hook and check_format.sh for C++ formatting - #286

Open
0m4r wants to merge 3 commits into
ktomy:mainfrom
0m4r:chore/add-format-script
Open

0m4r wants to merge 3 commits into
ktomy:mainfrom
0m4r:chore/add-format-script

Conversation

@0m4r

@0m4r 0m4r commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Add a pre-push git hook and a check_format.sh script to enforce the project's C++ formatting rules (defined in .clang-format) and run the host-side test suite before every push.

What changed

New files:

  • scripts/check_format.sh — checks (default) or fixes (--fix) all src/*.{cpp,h} files against .clang-format using clang-format --dry-run --Werror / -i
  • scripts/pre-push.sh — pre-push hook that delegates to check_format.sh --fix and runs test/run_tests.sh in parallel
  • .githooks/pre-push — committed copy of the hook (enabled via git config core.hooksPath .githooks)

Modified:

  • .clang-format — fixed schema type errors (AllowShortIfStatementsOnASingleLine: false → Never, AlignConsecutiveAssignments: false → None, etc.) so the config loads cleanly in clang-format 23.1.5 and the VS Code YAML schema
  • CONTRIBUTING.md — added a "Code formatting" section documenting the check/fix commands and how to enable the pre-push hook

Behavior

On git push, the hook:

  1. Runs scripts/check_format.sh --fix — if any .cpp/.h file gets reformatted, the push is aborted so you can review and commit the formatting first
  2. Runs test/run_tests.sh — if any test fails, the push is aborted
  3. If both pass: ✅ pre-push: all checks passed.

Testing

  • clang-format --style=file --dump-config loads cleanly (exit 0, no warnings)
  • scripts/check_format.sh reports all 92 src/ files as correctly formatted after --fix
  • Pre-push hook verified on both the happy path (formatted + tests green → exit 0) and failure path (unformatted file → ✘ + exit 1)

0m4r added 2 commits November 17, 2026 09:53
Add scripts/check_format.sh to verify and apply clang-format formatting
to src/ C++ sources, scripts/pre-push.sh as a git pre-push hook that
delegates to check_format.sh --fix and runs the host-side test suite,
and .githooks/pre-push as the committed copy (enabled via
git config core.hooksPath .githooks).

The hook aborts the push if clang-format reformats any files or if any
test fails, so contributors review and commit changes before pushing.

// Glucose trends
const uint8_t symbol_doubleUp[] PROGMEM = {
0b01010000,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we preserve this? They are binary and formatted as-is to be human-readable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, I missed this.
thanks for spotting it.
I have added an "ignore" marker for the block of code that have the matrixes.

@ktomy

ktomy commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Hi, I am not a C/C++/embedded dev so I am not at all sure what is the best formatting. If you're a C/C++ dev, just let me know that you know what you are doing and it is not just a random formatting wish.

Write each row of the 5x5 pixel glucose trend arrow bitmaps on its own
line and guard the block with clang-format off/on so clang-format does
not collapse each initializer onto a single line. The vertical layout
keeps each symbol's pixel pattern human-readable while the formatted
output stays identical.
@0m4r

0m4r commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Hi, I am not a C/C++/embedded dev so I am not at all sure what is the best formatting. If you're a C/C++ dev, just let me know that you know what you are doing and it is not just a random formatting wish.

Neither I am.... I simply enforced to apply the rules in .clang-format ad updated some values that were triggering errors.
I have run that config file through an AI, which confirmed it to be good:

There's nothing random or idiosyncratic about this .clang-format. It follows mainstream C/C++ recommendations, it's internally consistent, the codebase conforms to it, and the repo tooling enforces it. You don't need to change the formatting config itself.

@0m4r
0m4r requested a review from ktomy November 19, 2026 07:06

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants