-
Notifications
You must be signed in to change notification settings - Fork 150
chore: catch lint failures before push (misspell + scoped golangci-lint) #2994
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
base: stage
Are you sure you want to change the base?
Changes from 1 commit
05ffd66
6026fa6
231d6b7
f43e970
064d3f3
c29d588
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a contributor's checkout lacks local
origin/stageandorigin/mainrefs, both merge-base commands fail and the silentcontinuepermits the new branch push without running misspell, defeating the hook's purpose of surfacing failures before CI.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 231d6b7.