diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 73841dd..028d933 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,10 @@ -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v0.7.1 +repos: + - repo: https://github.com/jessp01/pre-commit-golang.git + rev: v0.5.3 hooks: - - id: check-merge-conflict - - id: check-yaml - - id: end-of-file-fixer - - id: trailing-whitespace + - id: go-fmt + - id: go-imports + - id: go-vet + - id: go-lint + - id: go-critic + - id: go-ineffassign diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 8363882..030a282 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -93,3 +93,9 @@ files: '\.go$' language: 'script' description: "Runs `go mod vendor`, requires golang" +- id: go-ineffassign + name: 'go ineffassign' + entry: run-go-ineffassign.sh + files: '\.go$' + language: 'script' + description: "Runs `ineffassign`, requires ineffassign" diff --git a/run-go-ineffassign.sh b/run-go-ineffassign.sh new file mode 100755 index 0000000..2f1d537 --- /dev/null +++ b/run-go-ineffassign.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -eu -o pipefail + +BIN=ineffassign +if ! command -v $BIN &> /dev/null ; then + echo "$BIN not installed or available in the PATH" >&2 + echo "please run 'go install github.com/gordonklaus/ineffassign@latest'" >&2 + exit 1 +fi + +failed=false + +for file in "$@"; do + # redirect stderr so that violations and summaries are properly interleaved. + if ! $BIN "$file" 2>&1 + then + failed=true + fi +done + +if [[ $failed == "true" ]]; then + exit 1 +fi diff --git a/run-go-vet.sh b/run-go-vet.sh index 0d21ea4..01b97d5 100755 --- a/run-go-vet.sh +++ b/run-go-vet.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +set -ex pkg=$(go list) -for dir in $(echo $@|xargs -n1 dirname|sort -u); do - go vet $pkg/$dir +for dir in $(echo "$@"|xargs -n1 dirname|sort -u); do + go vet "$pkg/$dir" done