-
-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathlint-code
executable file
·95 lines (74 loc) · 2.01 KB
/
lint-code
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
#!/bin/sh
usage() {
cat <<EOF
Run code lints under development machine.
Usage:
$0 <mode> [--fix]
Mode:
go Run golang lint utilities
vue Run vue lint utilities
all Run both golang and vue lints
EOF
exit 1
}
go() {
local fix=$1
[ "$fix" = "true" ] && EXTRA_ARGS="--fix" || EXTRA_ARGS=""
[ ! -e .golangci.yaml ] && echo "ERROR: Run the script from the project root." && exit 1
for container in agent:docker agent:native api ssh cli; do
echo "Running Golang linter on $container"
case $container in
ssh)
EXTRA_ARGS="$EXTRA_ARGS --build-tags internal_api"
;;
agent:docker)
EXTRA_ARGS="$EXTRA_ARGS --build-tags docker"
container=$(echo $container | cut -d':' -f 1)
;;
agent:native)
EXTRA_ARGS="$EXTRA_ARGS --build-tags native"
container=$(echo $container | cut -d':' -f 1)
;;
esac
# Run golangci-lint on a running container
docker-compose \
-f docker-compose.yml -f docker-compose.dev.yml \
exec $container golangci-lint run ./... $EXTRA_ARGS
done
echo "Running Golang linter on pkg"
docker-compose \
-f docker-compose.yml -f docker-compose.dev.yml \
exec api sh -c "(cd ../pkg; golangci-lint run $EXTRA_ARGS ./... )"
}
vue() {
local fix=$1
[ ! -d ui ] && echo "ERROR: Run the script from the project root." && exit 1
[ "$fix" = "true" ] && EXTRA_ARGS=" -- --fix" || EXTRA_ARGS=":no-fix"
echo "Running UI lints"
# Run linter on a running container
docker-compose \
-f docker-compose.yml -f docker-compose.dev.yml \
exec ui npm run lint$EXTRA_ARGS
}
mode=$1
arg=$2
case "$arg" in
"--fix")
fix="true"
;;
esac
case "$mode" in
"go")
go $fix
;;
"vue")
vue $fix
;;
"all")
go $fix
vue $fix
;;
*)
usage
;;
esac