-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathlefthook.yml
More file actions
55 lines (48 loc) · 1.5 KB
/
Copy pathlefthook.yml
File metadata and controls
55 lines (48 loc) · 1.5 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
# lefthook.yml
# This file is automatically generated by setup-hooks.sh
pre-commit:
parallel: true
commands:
go-tidy:
glob: "{go.mod,*.go}"
run: go mod tidy && git add go.mod go.sum
go-fmt:
glob: "*.go"
run: |
for file in {staged_files}; do
go fmt "$file"
git add "$file"
done
go-vet:
glob: "**/*.go"
run: go vet ./...
# go-test:
# glob: "*.go"
# run: go test -race ./...
golangci-lint:
glob: "**/*.go"
run: golangci-lint run ./... --timeout 10m
skip:
- run: test "$CI" = "true"
gosec:
glob: "**/*.go"
run: gosec -exclude=G101,G117 ./...
eof-newline:
help: Fail when a staged file does not end with a POSIX newline
# pick the extensions you care about; here are the most common text types
glob: "**/*.{go,sh,md,yml,yaml,json,txt}"
stage_fixed: true # lefthook will git-add any file we modify
run: |
fixed=0
for file in {staged_files}; do
[ -s "$file" ] || continue # skip empty files
# last byte → decimal code (10 == '\n')
last_byte=$(tail -c1 "$file" | od -An -t u1 | tr -d ' ')
if [ "$last_byte" != "10" ]; then
printf '\n' >> "$file" # append missing newline
echo "↪ added newline at EOF → $file"
fixed=$((fixed + 1))
fi
done
echo "✔ fixed $fixed file(s)"
[ "$fixed" -eq 0 ]