From b25022e0b8732981d4f71f4f6b73b531d7b3ee30 Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Tue, 1 Aug 2023 17:26:04 +0100 Subject: [PATCH 1/4] Added github.com/gordonklaus/ineffassign --- run-go-ineffassign.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 run-go-ineffassign.sh diff --git a/run-go-ineffassign.sh b/run-go-ineffassign.sh new file mode 100755 index 0000000..c7027de --- /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 -set_exit_status "$file" 2>&1 + then + failed=true + fi +done + +if [[ $failed == "true" ]]; then + exit 1 +fi From b432102084dd78658c6f8a25b096db4ec751af48 Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Tue, 1 Aug 2023 17:28:35 +0100 Subject: [PATCH 2/4] added go-ineffassign to hooks --- .pre-commit-hooks.yaml | 6 ++++++ 1 file changed, 6 insertions(+) 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" From e58ce91a10031a3b2a78af43119e647bb2668fd4 Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Tue, 1 Aug 2023 17:31:40 +0100 Subject: [PATCH 3/4] . --- run-go-ineffassign.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-go-ineffassign.sh b/run-go-ineffassign.sh index c7027de..2f1d537 100755 --- a/run-go-ineffassign.sh +++ b/run-go-ineffassign.sh @@ -13,7 +13,7 @@ failed=false for file in "$@"; do # redirect stderr so that violations and summaries are properly interleaved. - if ! $BIN -set_exit_status "$file" 2>&1 + if ! $BIN "$file" 2>&1 then failed=true fi From e36ed14cfec469b4b5dc9fc4edc423ab425dd89a Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Thu, 3 Aug 2023 17:58:48 +0100 Subject: [PATCH 4/4] Revised .pre-commit-config.yaml --- .pre-commit-config.yaml | 15 +++++++++------ run-go-vet.sh | 6 +++--- 2 files changed, 12 insertions(+), 9 deletions(-) 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/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