Repository navigation
Expand file tree
/
Copy path.pre-commit-config.yaml
More file actions
104 lines (101 loc) · 4.57 KB
/
Copy path.pre-commit-config.yaml
File metadata and controls
104 lines (101 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# DO NOT EDIT. Generated with:
#
# devctl
#
# https://github.com/giantswarm/devctl/blob/84caccc8334479d1752d924494e76942d6ec1188/pkg/gen/input/precommit/internal/file/pre-commit-config.yaml.template
#
minimum_pre_commit_version: '2.17'
default_install_hook_types: [pre-commit, commit-msg]
# Protobuf-generated code (protoc, buf: *_pb.ts, *_pb.js, *_pb2.py,
# *_pb2_grpc.py, *.pb.go, *_grpc.pb.go) belongs to its generator: a hook that
# rewrote it (end-of-file-fixer, go-imports, ruff --fix) would be undone by
# the next generation, so no hook reads it.
exclude: "(_pb2?|\\.pb)(_grpc)?\\.[^/]+$"
repos:
# base hooks
#
# helm/<chart>/charts/ holds vendored upstream subcharts (vendir-synced).
# Those files are not repo-authored: the auto-fixing hooks would rewrite
# them on every vendir bump and the next vendir sync would revert the fix,
# so the whitespace/shebang/private-key hooks skip the vendored subtree.
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
exclude: "^helm/[^/]+/charts/.*"
- id: detect-private-key
# Upstream charts document key formats with placeholder PEM headers
# (redis-ha's restore.ssh.key example) that the hook cannot tell from
# a key; gitleaks stays the scanner of record for the vendored subtree.
exclude: "^helm/[^/]+/charts/.*"
- id: end-of-file-fixer
exclude: "(.*testdata/.*|^\\.yarn/.*|^helm/[^/]+/charts/.*|.*.patch)"
- id: mixed-line-ending
exclude: "(^helm/[^/]+/charts/.*|.*.patch)"
- id: trailing-whitespace
exclude: "(.*testdata/.*|^\\.yarn/.*|^helm/[^/]+/charts/.*|.*.patch)"
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v4.5.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
args: [--strict]
# Go hooks run the tools on the PATH: gofmt and go from the Go toolchain,
# goimports and golangci-lint at the versions zz_generated.pre-commit.yaml installs.
# They replace the archived dnephin/pre-commit-golang and keep its behaviour.
- repo: local
hooks:
- id: go-fmt
name: go fmt
language: system
files: '\.go$'
entry: >-
bash -c 'command -v gofmt > /dev/null || { echo "gofmt not installed or available in the PATH, see https://go.dev/doc/install"; exit 1; };
out="$(gofmt -l -w "$@")"; rc=$?;
[ -z "$out" ] || echo "$out";
[ $rc -eq 0 ] && [ -z "$out" ]' --
- id: go-mod-tidy
name: go mod tidy
language: system
files: '\.go$'
pass_filenames: false
entry: >-
bash -c 'if go mod tidy -v 2>&1 | grep -q "updates to go.mod needed"; then exit 1; fi;
git diff --exit-code go.* > /dev/null 2>&1;
if [ $? -eq 1 ]; then echo "go.mod or go.sum differs, please re-add it to your commit"; exit 1; fi' --
- id: golangci-lint
name: golangci-lint
language: system
types: [go]
pass_filenames: false
entry: golangci-lint run
args:
# Let independent sessions and worktrees lint at the same time.
- --allow-parallel-runners
# No --timeout: golangci-lint v2 has none by default and a flag would
# override a repo's `run.timeout` in .golangci.yml, its place to set one.
# List all issues found
- --max-same-issues=0
- --max-issues-per-linter=0
- id: go-imports
name: go imports
language: system
files: '\.go$'
entry: >-
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; };
out="$(goimports -l -w "$@")"; rc=$?;
[ -z "$out" ] || echo "$out";
[ $rc -eq 0 ] && [ -z "$out" ]' --
args: [ -local, github.com/giantswarm/agentlab ]
# Renovate's gomod manager reads a require line's trailing comment as one
# word (`// indirect`); a line whose comment has more words is skipped
# without a PR or a dashboard entry, so the dependency silently stops being
# updated. The explanation goes on a comment line above the require instead.
- repo: local
hooks:
- id: go-mod-require-comment
name: "go.mod require comment is one word (Renovate skips the line otherwise; move the explanation to a comment line above it)"
language: pygrep
files: (^|/)go\.mod$
entry: '^\s*(require\s+)?[A-Za-z0-9][^\s,]*[./][^\s,]*\s+v[0-9]\S*\s*//\s*\S+\s+\S'