-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathjustfile
More file actions
138 lines (127 loc) · 4.81 KB
/
Copy pathjustfile
File metadata and controls
138 lines (127 loc) · 4.81 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# show help by default
default:
@just --list --justfile {{ justfile() }}
# update go deps
update *flags:
go get {{ flags }} ./cmd/postmoogle
go mod tidy
go mod vendor
# run linter
lint: comment-guard && swagger
golangci-lint run ./...
# allow single-line comments only, max 120 chars (exemptions in the case block below).
comment-guard:
#!/usr/bin/env sh
set -u
out=$(
git ls-files -- '*.go' '*.rs' '*.ts' '*.tsx' '*.py' '*.cpp' \
| while IFS= read -r f; do
case "$f" in
*/vendor/*|vendor/*) continue ;;
*/node_modules/*|node_modules/*) continue ;;
*/mocks/*|mocks/*) continue ;;
*/automock/*|automock/*) continue ;;
*/target/*|target/*) continue ;;
*/dist/*|dist/*) continue ;;
*/build/*|build/*) continue ;;
*.pb.go) continue ;;
*/docs/docs.go) continue ;;
esac
[ -f "$f" ] || continue
if head -n 10 "$f" | grep -qE '^(//|#) Code generated .* DO NOT EDIT\.$'; then
continue
fi
case "$f" in *.py) ispy=1 ;; *) ispy=0 ;; esac
awk -v PY="$ispy" -v DQ='"""' -v SQ="'''" '
function report(ln, msg) { printf "%s:%d: %s\n", FILENAME, ln, msg }
function chk(n) { if (length($0) > MAXLEN) report(n, "comment over " MAXLEN " chars") }
BEGIN { MAXLEN = 120; MAXDOC = 5 }
{
t = $0
sub(/^[ \t]+/, "", t)
if (PY == "1") {
if (in_doc) {
doc_lines++
chk(NR)
if (index($0, QT) > 0) {
in_doc = 0
if (doc_lines > MAXDOC) report(doc_start, "docstring over " MAXDOC " lines; keep it short")
}
next
}
p = t
while (length(p) > 3 && index("rRbBuUfF", substr(p, 1, 1)) > 0) p = substr(p, 2)
q = ""
if (substr(p, 1, 3) == DQ) { q = DQ } else if (substr(p, 1, 3) == SQ) { q = SQ }
if (q != "") {
if (index(substr(p, 4), q) > 0) { chk(NR); run = 0; next }
in_doc = 1; QT = q; doc_lines = 1; doc_start = NR; chk(NR); run = 0; next
}
if (substr(t, 1, 1) == "#") {
if (substr(t, 1, 2) == "#!") { run = 0; next }
if (t ~ /^#[ \t]*(noqa|nosec|type:|pragma:|fmt:|isort:|pylint:|mypy:|ruff:|flake8:|coding[:=]|-\*-)/) { run = 0; next }
chk(NR)
run++
if (run == 1) run_start = NR
if (run == 2) report(run_start, "multi-line comment; single-line only")
} else {
run = 0
}
next
}
if (in_block) {
chk(NR)
if (index($0, "*/") > 0) {
in_block = 0
report(block_start, "multi-line /* */ comment; single-line only")
}
next
}
if (substr(t, 1, 2) == "/*") {
if (index(substr(t, 3), "*/") > 0) { chk(NR); run = 0; next }
in_block = 1; block_start = NR; chk(NR); next
}
if (substr(t, 1, 2) == "//") {
if (t ~ /^\/\/[ \t]*$/) { next }
if (t ~ /^\/\/[a-z]+:/ || t ~ /^\/\/(line|export|cgo|sys)[ \t]/ || t ~ /^\/\/\/[ \t]*</ || t ~ /^\/\/[ \t]*@[A-Za-z]/) { run = 0; next }
chk(NR)
run++
if (run == 1) run_start = NR
if (run == 2) report(run_start, "multi-line comment; single-line only")
next
}
run = 0
}
' "$f"
done
)
if [ -n "$out" ]; then
printf '%s\n' "$out" | sort
echo "comment-guard: FAIL (single-line comments only, max 120 chars, docstrings max 5 lines)"
exit 1
fi
# automatically fix liter issues
lintfix: && swaggerfix
golangci-lint run --fix ./...
# generate mocks
mocks:
@mockery --all --inpackage --testonly --exclude vendor
# generate swagger docks
swagger:
@swag init --parseDependency --dir ./cmd/postmoogle,./
# automatically fix swagger issues
swaggerfix: && swagger
@swag fmt --dir ./cmd/postmoogle,./
# run unit tests
test packages="./...":
@go test -cover -coverprofile=cover.out -coverpkg={{ packages }} -covermode=set {{ packages }}
@go tool cover -func=cover.out
-@rm -f cover.out
# run app
run *flags:
@go run ./cmd/postmoogle {{ flags }}
install:
@CGO_ENABLED=0 go install -ldflags '-extldflags "-static"' -tags timetzdata,goolm -v ./cmd/postmoogle
# build app
build:
@CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -tags timetzdata,goolm -v ./cmd/postmoogle