Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: nargo fmt pre-commit hook #11416

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ esac
hooks_dir=$(git rev-parse --git-path hooks)
echo "(cd barretenberg/cpp && ./format.sh staged)" >$hooks_dir/pre-commit
echo "./yarn-project/precommit.sh" >>$hooks_dir/pre-commit
echo "./noir-projects/precommit.sh" >>$hooks_dir/pre-commit
chmod +x $hooks_dir/pre-commit

github_group "pull submodules"
Expand Down
39 changes: 39 additions & 0 deletions noir-projects/precommit.sh
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.
Loading