-
Notifications
You must be signed in to change notification settings - Fork 8
/
lint.sh
61 lines (49 loc) · 1.29 KB
/
lint.sh
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
#!/usr/bin/env bash
#
# Lint all modules with golangci-lint.
#
# lint.sh - lints all modules in the repository root, or the current folder if
# not in a git workspace.
#
# lint.sh [folder] - lints all modules in the specified folder.
REPO=`git rev-parse --show-toplevel 2> /dev/null`
if [[ $? != 0 ]]; then
REPO=`pwd`
fi
# Root is the input argument, or REPO if no input argument.
ROOT=${1:-$REPO}
echo "Linting all modules under" $ROOT
set -e
shopt -s expand_aliases
export GO111MODULE=on
go version
pushd $ROOT > /dev/null
ROOTPATH=$(go list -m -f {{.Dir}} 2>/dev/null)
ROOTPATHPATTERN=$(echo $ROOTPATH | sed 's/\\/\\\\/g' | sed 's/\//\\\//g')
MODPATHS=$(go list -m -f {{.Dir}} all 2>/dev/null | grep "^$ROOTPATHPATTERN")
alias superlint='golangci-lint run --deadline=10m \
--disable-all \
--enable govet \
--enable staticcheck \
--enable gosimple \
--enable unconvert \
--enable ineffassign \
--enable structcheck \
--enable goimports \
--enable misspell \
--enable unparam'
# run lint on all listed modules
set +e
ERROR=0
trap 'ERROR=$?' ERR
for MODPATH in $MODPATHS; do
pushd $MODPATH > /dev/null
MOD=$(go list -m)
echo "Linting:" $MOD
superlint
popd > /dev/null
done
popd > /dev/null # ROOT
if [ $ERROR -ne 0 ]; then
exit $ERROR
fi