diff --git a/.github/README.md.header b/.github/README.md.header index f4be891..e259c78 100644 --- a/.github/README.md.header +++ b/.github/README.md.header @@ -1,3 +1,8 @@ # golang-pre-commit -This is a collection of golang [pre-commit](http://pre-commit.com/) hooks. +This is a collection of golang [pre-commit](http://pre-commit.com/) hooks +specifcally for build, generate, unit tests, and other build-time workflow +checks. + +If you need a pre-commit for a linter or formatter, check out the official +[golangci-lint](https://golangci-lint.run/) pre-commit: https://github.com/golangci/golangci-lint/blob/main/.pre-commit-hooks.yaml diff --git a/.github/workflows/update-readme.yaml b/.github/workflows/update-readme.yaml index 6fb524b..6a28005 100644 --- a/.github/workflows/update-readme.yaml +++ b/.github/workflows/update-readme.yaml @@ -61,7 +61,7 @@ jobs: echo -ne ' - repo: https://github.com/bhundven/golang-pre-commit.git\n' >&3 echo -ne " rev: ${LATEST_VER}\n" >&3 echo -ne ' hooks:\n' >&3 - echo -ne ' - id: go-fmt\n' >&3 + echo -ne ' - id: go-generate\n' >&3 echo -ne '```\n\n' >&3 echo -ne "## Available Hooks\n\n" >&3 diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index afc52e9..e95dd9b 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,60 +1,4 @@ --- -- id: go-fmt - name: 'gofmt' - entry: pre-commit-hooks/gofmt.sh - types: [go] - exclude: '(^|/)vendor/' - language: 'script' - description: "Runs `gofmt`. Requires golang: https://go.dev/doc/install" - pass_filenames: true -- id: go-fumpt - name: 'gofumpt' - entry: pre-commit-hooks/go-fumpt.sh - types: [go] - exclude: '(^|/)vendor/' - language: 'script' - description: "Runs `gofumpt`. Requires gofumpt: https://github.com/mvdan/gofumpt" - pass_filenames: true -- id: go-imports - name: 'goimports' - entry: pre-commit-hooks/go-imports.sh - types: [go] - exclude: '(^|/)vendor/' - language: 'script' - description: "Runs `goimports`. Requires goimports: https://pkg.go.dev/golang.org/x/tools/cmd/goimports" - pass_filenames: true -- id: go-vet - name: 'go vet' - entry: pre-commit-hooks/go-vet.sh - types: [go] - exclude: '(^|/)vendor/' - language: 'script' - description: "Runs `go vet`. Requires golang: https://go.dev/doc/install" - pass_filenames: true -- id: go-lint - name: 'golint' - entry: pre-commit-hooks/go-lint.sh - types: [go] - exclude: '(^|/)vendor/' - language: 'script' - description: "[DEPRECATED] Runs `golint`. Requires golint: https://github.com/golang/lint" - pass_filenames: true -- id: golangci-lint - name: 'golangci-lint' - entry: pre-commit-hooks/golangci-lint.sh - types: [go] - exclude: '(^|/)vendor/' - language: 'script' - description: "Runs `golangci-lint`. Requires golangci-lint: https://github.com/golangci/golangci-lint" - pass_filenames: true -- id: go-critic - name: "gocritic" - entry: pre-commit-hooks/go-critic.sh - types: [go] - exclude: '(^|/)vendor/' - language: 'script' - description: "Runs `gocritic`. Requires gocritic: https://github.com/go-critic/go-critic" - pass_filenames: true - id: go-unit-tests name: 'go test' entry: pre-commit-hooks/go-unit-tests.sh diff --git a/pre-commit-hooks/go-critic.sh b/pre-commit-hooks/go-critic.sh deleted file mode 100755 index 44a5566..0000000 --- a/pre-commit-hooks/go-critic.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash -# vi: ts=2:sw=2:et -# vim: ft=bash - -set -euo pipefail - -if ! command -v gocritic &> /dev/null -then - echo "gocritic is not installed or is not in the current PATH" >&2 - echo "Find out more at: https://github.com/go-critic/go-critic" >&2 - exit 1 -fi - -for file in "$@" -do - if ! gocritic check "${file}" 2>&1 - then - exit 1 - fi -done diff --git a/pre-commit-hooks/go-fumpt.sh b/pre-commit-hooks/go-fumpt.sh deleted file mode 100755 index 959cdb1..0000000 --- a/pre-commit-hooks/go-fumpt.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -# vi: ts=2:sw=2:et -# vim: ft=bash - -set -euo pipefail - -if ! command -v gofumpt &> /dev/null -then - echo "gofumpt is not installed or is not in the current PATH" >&2 - echo "Find out more at: https://github.com/mvdan/gofumpt" >&2 - exit 1 -fi - -output="$(gofumpt -l -w "$@")" -echo "${output}" -[[ -z "${output}" ]] diff --git a/pre-commit-hooks/go-imports.sh b/pre-commit-hooks/go-imports.sh deleted file mode 100755 index eb0aab0..0000000 --- a/pre-commit-hooks/go-imports.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -# vi: ts=2:sw=2:et -# vim: ft=bash - -set -euo pipefail - -if ! command -v goimports &> /dev/null -then - echo "goimports is not installed or is not in the current PATH" >&2 - echo "Find out more at: https://pkg.go.dev/golang.org/x/tools/cmd/goimports" >&2 - exit 1 -fi - -output="$(goimports -l -w "$@")" -echo "${output}" -[[ -z "${output}" ]] diff --git a/pre-commit-hooks/go-lint.sh b/pre-commit-hooks/go-lint.sh deleted file mode 100755 index c9872d5..0000000 --- a/pre-commit-hooks/go-lint.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash -# vi: ts=2:sw=2:et -# vim: ft=bash - -set -euo pipefail - -if ! command -v golint &> /dev/null -then - echo "golint is not installed or is not in the current PATH" >&2 - echo "Find out more at: https://github.com/golang/lint" >&2 - exit 1 -fi - -for file in "$@" -do - if ! golint -set_exit_status "${file}" 2>&1 - then - exit 1 - fi -done diff --git a/pre-commit-hooks/go-vet.sh b/pre-commit-hooks/go-vet.sh deleted file mode 100755 index 3c9b7e0..0000000 --- a/pre-commit-hooks/go-vet.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# vi: ts=2:sw=2:et -# vim: ft=bash - -set -euo pipefail - -pkg="$(go list)" -for dir in $(echo "$@" | xargs -n1 dirname | sort -u) -do - go vet "${pkg}/${dir}" -done diff --git a/pre-commit-hooks/gofmt.sh b/pre-commit-hooks/gofmt.sh deleted file mode 100755 index 6895369..0000000 --- a/pre-commit-hooks/gofmt.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# vi: ts=2:sw=2:et -# vim: ft=bash - -set -euo pipefail - -if ! command -v gofmt &> /dev/null -then - echo "gofmt is not installed or is not in the current PATH" >&2 - exit 1 -fi - -output="$(gofmt -l -w "$@")" -echo "${output}" -[[ -z "${output}" ]] diff --git a/pre-commit-hooks/golangci-lint.sh b/pre-commit-hooks/golangci-lint.sh deleted file mode 100755 index 90032a0..0000000 --- a/pre-commit-hooks/golangci-lint.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# vi: ts=2:sw=2:et -# vim: ft=bash - -set -euo pipefail - -if ! command -v golangci-lint &> /dev/null -then - echo "golangci-lint is not installed or is not in the current PATH" >&2 - echo "Find out more at: https://github.com/golangci/golangci-lint" >&2 - exit 1 -fi - -exec golangci-lint run "$@"