Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ ssvsigner-golangci-lint:
deadcode-lint:
./scripts/deadcode.sh

.PHONY: install-hooks
install-hooks:
git config core.hooksPath scripts/git-hooks
@echo "git hooks installed (core.hooksPath -> scripts/git-hooks)"

.PHONY: ssvsigner-boundary-lint
ssvsigner-boundary-lint:
./scripts/ssvsigner_boundary.sh
Expand Down
56 changes: 56 additions & 0 deletions scripts/git-hooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh
# Pre-push hook: run the misspell linter (locale US, same as .golangci.yaml's
# misspell config) on the .go/.md files this push introduces or modifies, so
# spelling failures surface locally instead of on the PR's lint check.
#
# Install with: make install-hooks
# Bypass for a one-off push: git push --no-verify

root=$(git rev-parse --show-toplevel) || exit 0

# go tool compiles misspell from tool.mod on first use and caches it; go may
# not be on PATH in GUI-spawned shells, so fall back to the default install.
if command -v go >/dev/null 2>&1; then
GO=go
elif [ -x /usr/local/go/bin/go ]; then
GO=/usr/local/go/bin/go
else
exit 0
fi

ZERO=0000000000000000000000000000000000000000
status=0

while read -r local_ref local_sha remote_ref remote_sha; do
[ "$local_sha" = "$ZERO" ] && continue # deleting a remote ref

if [ "$remote_sha" = "$ZERO" ]; then
# New remote branch: diff against the merge-base with stage (or main).
base=$(git merge-base "$local_sha" origin/stage 2>/dev/null) ||
base=$(git merge-base "$local_sha" origin/main 2>/dev/null) || continue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Hardcoded base refs skip linting

If a contributor's checkout lacks local origin/stage and origin/main refs, both merge-base commands fail and the silent continue permits the new branch push without running misspell, defeating the hook's purpose of surfacing failures before CI.

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.

Fixed in 231d6b7.

else
base=$remote_sha
fi

files=$(git diff --name-only --diff-filter=ACMR "$base" "$local_sha" -- '*.go' '*.md')
[ -z "$files" ] && continue

# Check the blobs at local_sha, not the working tree, so uncommitted edits
# don't mask (or fake) findings in what's actually being pushed.
for f in $files; do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Unquoted path list loses filenames

For a pushed Go or Markdown path containing whitespace or shell glob characters, for f in $files applies field splitting and pathname expansion, so the hook reads nonexistent or unintended blobs and can omit spelling findings from the actual changed file.

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.

Fixed in 064d3f3.

out=$(git show "$local_sha:$f" 2>/dev/null |
GOWORK=off "$GO" tool -modfile="$root/tool.mod" misspell -locale US -error 2>&1)
if [ -n "$out" ]; then
echo "pre-push: misspell found issues in $f:" >&2
echo "$out" | sed "s|^stdin| $f|" >&2
status=1
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Tool errors resemble spelling findings

When go tool cannot resolve or execute misspell, its stderr is captured in out and labeled as a spelling issue, blocking the push with instructions to amend code instead of reporting the actual local tool failure.

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.

Fixed in f43e970.

done
done

if [ "$status" -ne 0 ]; then
echo "" >&2
echo "pre-push: fix the spellings above and amend/commit — the CI lint check (golangci-lint misspell) fails on them." >&2
echo "pre-push: bypass once with: git push --no-verify" >&2
fi
exit $status
1 change: 1 addition & 0 deletions tool.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tool (
github.com/ethereum/go-ethereum/cmd/abigen
github.com/ferranbt/fastssz/sszgen
github.com/golangci/golangci-lint/v2/cmd/golangci-lint
github.com/golangci/misspell/cmd/misspell
github.com/swaggo/swag/cmd/swag
go.uber.org/mock/mockgen
golang.org/x/tools/cmd/deadcode
Expand Down