-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: nargo fmt pre-commit hook (#11416)
I was getting annoyed at forgetting to format noir files, and then pushing, then waiting X mins, and then CI reminding me with a failure. Tagging Charlie and Adam, because this would annoy people if I've made a mistake.
- Loading branch information
1 parent
cf3c911
commit 6f2e2e0
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
# Precommit hook for formatting staged noir files. | ||
# We only run the formatter if there are staged *.nr files. | ||
# Nothing should cause a failure, because that would annoy everyone if all they're trying to do is commit. | ||
set -euo pipefail | ||
|
||
cd $(dirname $0) | ||
|
||
export FORCE_COLOR=true | ||
|
||
# Path to nargo binary | ||
NARGO_PATH="../noir/noir-repo/target/release/nargo" | ||
|
||
# Check if there are staged .nr files | ||
staged_nr_files=$(git diff --cached --name-only --diff-filter=d | grep '\.nr$' || true) | ||
|
||
if [[ -n "$staged_nr_files" ]]; then | ||
echo "Detected staged .nr files. Running nargo fmt..." | ||
|
||
# Check if nargo exists (the user might be making a quick change, without wanting to have to bootstrap the entire repo, so we don't want an inconvenient catastrophic failure if this hook can't complete execution; we want to fail gracefully). | ||
if [[ ! -x "$NARGO_PATH" ]]; then | ||
echo "Warning: nargo not found at $NARGO_PATH" | ||
echo " Skipping the nargo fmt commit hook." | ||
exit 0 | ||
fi | ||
|
||
for dir in noir-contracts noir-protocol-circuits mock-protocol-circuits aztec-nr; do | ||
if [[ -d "$dir" ]]; then | ||
echo "Formatting in $dir..." | ||
(cd "$dir" && "../$NARGO_PATH" fmt) || echo "Warning: Formatting failed in $dir, but continuing..." | ||
else | ||
echo "Warning: Directory $dir not found, skipping..." | ||
fi | ||
done | ||
|
||
echo "Formatting completed." | ||
fi | ||
|
||
# We just don't say anything if there are no staged nr files, because no one cares. |