Skip to content

Commit 39a631f

Browse files
committed
Better module/pkg support. Argument support for all hooks. Re-worked docs
1 parent 361bab2 commit 39a631f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+906
-705
lines changed

.pre-commit-hooks.yaml

Lines changed: 163 additions & 296 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 191 additions & 170 deletions
Large diffs are not rendered by default.

go-build-dir.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

go-build-mod.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
export GO111MODULE=on
4+
35
# Walks up the file path looking for go.mod
46
#
57
function find_module_roots() {
@@ -13,14 +15,33 @@ function find_module_roots() {
1315
while [ "${path}" != "." ] && [ ! -f "${path}/go.mod" ]; do
1416
path=$(dirname "${path}")
1517
done
16-
echo "${path}"
18+
if [ -f "${path}/go.mod" ]; then
19+
echo "${path}"
20+
fi
1721
done
1822
}
1923

24+
FILES=()
25+
26+
# Build file list while looking for optional argument marker
27+
#
28+
while [ $# -gt 0 ] && [ "$1" != "-" ] && [ "$1" != "--" ]; do
29+
FILES+=("$1")
30+
shift
31+
done
32+
33+
# Remove argument marker if present
34+
#
35+
if [ $# -gt 0 ]; then
36+
if [ "$1" == "-" ] || [ "$1" == "--" ]; then
37+
shift
38+
fi
39+
fi
40+
2041
errCode=0
21-
for sub in $(find_module_roots "$@" | sort -u) ; do
42+
for sub in $(find_module_roots "${FILES}" | sort -u) ; do
2243
pushd "${sub}" >/dev/null
23-
go build ./...
44+
go build "$@" ./...
2445
if [ $? -ne 0 ]; then
2546
errCode=1
2647
fi

go-build-pkg.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
#!/usr/bin/env bash
2+
3+
export GO111MODULE=off
4+
5+
FILES=()
6+
7+
# Build file list while looking for optional argument marker
8+
#
9+
while [ $# -gt 0 ] && [ "$1" != "-" ] && [ "$1" != "--" ]; do
10+
FILES+=("$1")
11+
shift
12+
done
13+
14+
# Remove argument marker if present
15+
#
16+
if [ $# -gt 0 ]; then
17+
if [ "$1" == "-" ] || [ "$1" == "--" ]; then
18+
shift
19+
fi
20+
fi
21+
222
errCode=0
3-
pkg=$(go list) # repo root package
4-
for sub in $(echo "$@" | xargs -n1 dirname | sort -u); do
5-
go build "${pkg}/${sub}"
23+
for sub in $(echo "${FILES}" | xargs -n1 dirname | sort -u); do
24+
go build "$@" "./${sub}"
625
if [ $? -ne 0 ]; then
726
errCode=1
827
fi

go-build-repo-dir.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

go-build-repo-mod.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
export GO111MODULE=on
4+
5+
# '-' and '--' are optional argument markers for parity with file scripts
6+
# Remove them if present
7+
#
8+
if [ $# -gt 0 ]; then
9+
if [ "$1" == "-" ] || [ "$1" == "--" ]; then
10+
shift
11+
fi
12+
fi
13+
14+
errCode=0
15+
# Assume parent folder of go.mod is module root folder
16+
#
17+
for sub in $(find . -name go.mod | xargs -n1 dirname | sort -u) ; do
18+
pushd "${sub}" >/dev/null
19+
go build "$@" ./...
20+
if [ $? -ne 0 ]; then
21+
errCode=1
22+
fi
23+
popd >/dev/null
24+
done
25+
exit $errCode

go-build-repo-pkg.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
#!/usr/bin/env bash
22
set -e
3-
pkg=$(go list) # repo root package
4-
go build "$@" "${pkg}/..."
3+
4+
export GO111MODULE=off
5+
6+
# '-' and '--' are optional argument markers for parity with file scripts
7+
# Remove them if present
8+
#
9+
if [ $# -gt 0 ]; then
10+
if [ "$1" == "-" ] || [ "$1" == "--" ]; then
11+
shift
12+
fi
13+
fi
14+
15+
go build "$@" ./...

go-build-repo.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

go-critic.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
#!/usr/bin/env bash
2+
3+
FILES=()
4+
5+
# Build file list while looking for optional argument marker
6+
#
7+
while [ $# -gt 0 ] && [ "$1" != "-" ] && [ "$1" != "--" ]; do
8+
FILES+=("$1")
9+
shift
10+
done
11+
12+
# Remove argument marker if present
13+
#
14+
if [ $# -gt 0 ]; then
15+
if [ "$1" == "-" ] || [ "$1" == "--" ]; then
16+
shift
17+
fi
18+
fi
19+
220
errCode=0
3-
for file in "$@"; do
4-
gocritic check "${file}"
21+
for file in "${FILES}"; do
22+
gocritic check "$@" "${file}"
523
if [ $? -ne 0 ]; then
624
errCode=1
725
fi

0 commit comments

Comments
 (0)