-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathcheckfmt.sh
More file actions
executable file
·41 lines (36 loc) · 910 Bytes
/
checkfmt.sh
File metadata and controls
executable file
·41 lines (36 loc) · 910 Bytes
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
#!/bin/bash
test_fmt() {
DIR="$1"
hash goimports 2>&- || { echo >&2 "goimports not in PATH."; exit 1; }
for file in $(find -L $DIR -type f -name "*.go" -not -path "./Godeps/*")
do
output=`cat $file | goimports -l 2>&1`
if test $? -ne 0
then
output=`echo "$output" | sed "s,<standard input>,$file,"`
syntaxerrors="${list}${output}\n"
elif test -n "$output"
then
list="${list}${file}\n"
fi
done
exitcode=0
if test -n "$syntaxerrors"
then
echo >&2 "goimports found syntax errors:"
printf "$syntaxerrors"
exitcode=1
fi
if test -n "$list"
then
echo >&2 "goimports needs to format these files (run make fmt and git add):"
printf "$list"
printf "\n"
exitcode=1
fi
exit $exitcode
}
main() {
test_fmt "$@"
}
main "$@"