-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add pre-commit hook Co-authored-by: Gianguido Sora <gsora@users.noreply.github.com> * add go tools installation notes * Update CONTRIBUTING.md * run both go mod and golangci-lint * silence which * add go.mod go.sum after go mod tidy * update README * look up golangci-lint specifically in GOPATH/bin * don't run golangci-lint * exclude proto files Co-authored-by: Gianguido Sora <gsora@users.noreply.github.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
4b3eb0e
commit 6469447
Showing
3 changed files
with
67 additions
and
3 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,21 @@ | ||
# Git hooks | ||
|
||
Installation: | ||
|
||
``` | ||
$ git config core.hooksPath contrib/githooks | ||
``` | ||
|
||
## pre-commit | ||
|
||
The hook automatically runs `gofmt`, `goimports`, and `misspell` | ||
to correctly format the `.go` files included in the commit, provided | ||
that all the aforementioned commands are installed and available | ||
in the user's search `$PATH` environment variable: | ||
|
||
``` | ||
$ go get golang.org/x/tools/cmd/goimports | ||
$ go get github.com/golangci/misspell/cmd/misspell@master | ||
``` | ||
|
||
It also runs `go mod tidy` and `golangci-lint` if available. |
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,41 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
CMDS='git go gofmt goimports misspell' | ||
STAGED_GO_FILES=$(git diff --cached --name-only -- '*.go') | ||
|
||
f_echo_stderr() { | ||
echo $@ >&2 | ||
} | ||
|
||
f_exit_success() { | ||
[ x"$@" != "x" ] && f_echo_stderr $@ || exit 0 | ||
} | ||
trap f_exit_success EXIT | ||
|
||
f_check_cmds() { | ||
for cmd in ${CMDS}; do | ||
which ${cmd} &>/dev/null || f_exit_success "couldn't find ${cmd}, skipping" | ||
done | ||
} | ||
|
||
f_check_cmds | ||
|
||
if [[ $STAGED_GO_FILES != "" ]]; then | ||
f_echo_stderr "[pre-commit] fmt'ing staged files..." | ||
for file in $STAGED_GO_FILES; do | ||
if [[ $file =~ vendor/ ]] || [[ $file =~ client/lcd/statik/ ]] || [[ $file =~ tests/mocks/ ]] || [[ $file =~ \.pb\.go ]]; then | ||
continue | ||
fi | ||
|
||
gofmt -w -s $file | ||
misspell -w $file | ||
goimports -w -local github.com/cosmos/cosmos-sdk $file | ||
git add $file | ||
|
||
done | ||
fi | ||
|
||
# Run go mod tidy | ||
go mod tidy && git add go.mod go.sum |