Skip to content

Commit d229faf

Browse files
chore: align files according to platform standards (#52)
Co-authored-by: giantswarm-align-files[bot] <288255335+giantswarm-align-files[bot]@users.noreply.github.com>
1 parent 5abb514 commit d229faf

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

‎.pre-commit-config.yaml‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# devctl
44
#
5-
# https://github.com/giantswarm/devctl/blob/2401f0119ed3772a1c02a28ea6d20422feb4ef38/pkg/gen/input/precommit/internal/file/pre-commit-config.yaml.template
5+
# https://github.com/giantswarm/devctl/blob/84caccc8334479d1752d924494e76942d6ec1188/pkg/gen/input/precommit/internal/file/pre-commit-config.yaml.template
66
#
77
minimum_pre_commit_version: '2.17'
88
default_install_hook_types: [pre-commit, commit-msg]
@@ -43,13 +43,35 @@ repos:
4343
stages: [commit-msg]
4444
args: [--strict]
4545

46-
# Go hooks
47-
- repo: https://github.com/dnephin/pre-commit-golang
48-
rev: v0.5.1
46+
# Go hooks run the tools on the PATH: gofmt and go from the Go toolchain,
47+
# goimports and golangci-lint at the versions zz_generated.pre-commit.yaml installs.
48+
# They replace the archived dnephin/pre-commit-golang and keep its behaviour.
49+
- repo: local
4950
hooks:
5051
- id: go-fmt
52+
name: go fmt
53+
language: system
54+
files: '\.go$'
55+
entry: >-
56+
bash -c 'command -v gofmt > /dev/null || { echo "gofmt not installed or available in the PATH, see https://go.dev/doc/install"; exit 1; };
57+
out="$(gofmt -l -w "$@")"; rc=$?;
58+
[ -z "$out" ] || echo "$out";
59+
[ $rc -eq 0 ] && [ -z "$out" ]' --
5160
- id: go-mod-tidy
61+
name: go mod tidy
62+
language: system
63+
files: '\.go$'
64+
pass_filenames: false
65+
entry: >-
66+
bash -c 'if go mod tidy -v 2>&1 | grep -q "updates to go.mod needed"; then exit 1; fi;
67+
git diff --exit-code go.* > /dev/null 2>&1;
68+
if [ $? -eq 1 ]; then echo "go.mod or go.sum differs, please re-add it to your commit"; exit 1; fi' --
5269
- id: golangci-lint
70+
name: golangci-lint
71+
language: system
72+
types: [go]
73+
pass_filenames: false
74+
entry: golangci-lint run
5375
args:
5476
# Let independent sessions and worktrees lint at the same time.
5577
- --allow-parallel-runners
@@ -59,6 +81,14 @@ repos:
5981
- --max-same-issues=0
6082
- --max-issues-per-linter=0
6183
- id: go-imports
84+
name: go imports
85+
language: system
86+
files: '\.go$'
87+
entry: >-
88+
bash -c 'command -v goimports > /dev/null || { echo "goimports not installed or available in the PATH, see https://pkg.go.dev/golang.org/x/tools/cmd/goimports"; exit 1; };
89+
out="$(goimports -l -w "$@")"; rc=$?;
90+
[ -z "$out" ] || echo "$out";
91+
[ $rc -eq 0 ] && [ -z "$out" ]' --
6292
args: [ -local, github.com/giantswarm/skill-manager ]
6393

6494
# Renovate's gomod manager reads a require line's trailing comment as one

0 commit comments

Comments
 (0)