Skip to content

Commit b02994d

Browse files
committed
Add more CI checks forcing code cleanliness
1 parent 5a13a75 commit b02994d

File tree

6 files changed

+119
-4
lines changed

6 files changed

+119
-4
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ go:
66
- 1.3
77
- 1.4
88
- tip
9+
10+
install:
11+
- go get github.com/golang/lint/golint
12+
- export PATH=$GOPATH/bin:$PATH
13+
- go install ./...
14+
15+
script:
16+
- verify/all.sh
17+
- go test ./...

flag.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ func (f *FlagSet) MarkDeprecated(name string, usageMessage string) error {
315315
return nil
316316
}
317317

318-
// Mark the shorthand of a flag deprecated in your program. It will
319-
// continue to function but will not show up in help or usage messages. Using
320-
// this flag will also print the given usageMessage.
318+
// MarkShorthandDeprecated will mark the shorthand of a flag deprecated in your
319+
// program. It will continue to function but will not show up in help or usage
320+
// messages. Using this flag will also print the given usageMessage.
321321
func (f *FlagSet) MarkShorthandDeprecated(name string, usageMessage string) error {
322322
flag := f.Lookup(name)
323323
if flag == nil {
@@ -821,7 +821,7 @@ func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet {
821821
return f
822822
}
823823

824-
// SetIntersperesed sets whether to support interspersed option/non-option arguments.
824+
// SetInterspersed sets whether to support interspersed option/non-option arguments.
825825
func (f *FlagSet) SetInterspersed(interspersed bool) {
826826
f.interspersed = interspersed
827827
}

golangflag.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func (v *flagValueWrapper) Type() string {
6060
return v.flagType
6161
}
6262

63+
// PFlagFromGoFlag will return a *pflag.Flag given a *flag.Flag
6364
func PFlagFromGoFlag(goflag *goflag.Flag) *Flag {
6465
// Remember the default value as a string; it won't change.
6566
flag := &Flag{
@@ -76,6 +77,7 @@ func PFlagFromGoFlag(goflag *goflag.Flag) *Flag {
7677
return flag
7778
}
7879

80+
// AddGoFlag will add the given *flag.Flag to the pflag.FlagSet
7981
func (f *FlagSet) AddGoFlag(goflag *goflag.Flag) {
8082
if f.Lookup(goflag.Name) != nil {
8183
return
@@ -84,6 +86,7 @@ func (f *FlagSet) AddGoFlag(goflag *goflag.Flag) {
8486
f.AddFlag(newflag)
8587
}
8688

89+
// AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet
8790
func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet) {
8891
if newSet == nil {
8992
return

verify/all.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
ROOT=$(dirname "${BASH_SOURCE}")/..
8+
9+
# Some useful colors.
10+
if [[ -z "${color_start-}" ]]; then
11+
declare -r color_start="\033["
12+
declare -r color_red="${color_start}0;31m"
13+
declare -r color_yellow="${color_start}0;33m"
14+
declare -r color_green="${color_start}0;32m"
15+
declare -r color_norm="${color_start}0m"
16+
fi
17+
18+
SILENT=true
19+
20+
function is-excluded {
21+
for e in $EXCLUDE; do
22+
if [[ $1 -ef ${BASH_SOURCE} ]]; then
23+
return
24+
fi
25+
if [[ $1 -ef "$ROOT/hack/$e" ]]; then
26+
return
27+
fi
28+
done
29+
return 1
30+
}
31+
32+
while getopts ":v" opt; do
33+
case $opt in
34+
v)
35+
SILENT=false
36+
;;
37+
\?)
38+
echo "Invalid flag: -$OPTARG" >&2
39+
exit 1
40+
;;
41+
esac
42+
done
43+
44+
if $SILENT ; then
45+
echo "Running in the silent mode, run with -v if you want to see script logs."
46+
fi
47+
48+
EXCLUDE="all.sh"
49+
50+
ret=0
51+
for t in `ls $ROOT/verify/*.sh`
52+
do
53+
if is-excluded $t ; then
54+
echo "Skipping $t"
55+
continue
56+
fi
57+
if $SILENT ; then
58+
echo -e "Verifying $t"
59+
if bash "$t" &> /dev/null; then
60+
echo -e "${color_green}SUCCESS${color_norm}"
61+
else
62+
echo -e "${color_red}FAILED${color_norm}"
63+
ret=1
64+
fi
65+
else
66+
bash "$t" || ret=1
67+
fi
68+
done
69+
exit $ret

verify/gofmt.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
ROOT=$(dirname "${BASH_SOURCE}")/..
8+
9+
pushd "${ROOT}" > /dev/null
10+
11+
GOFMT=${GOFMT:-"gofmt"}
12+
bad_files=$(find . -name '*.go' | xargs $GOFMT -s -l)
13+
if [[ -n "${bad_files}" ]]; then
14+
echo "!!! '$GOFMT' needs to be run on the following files: "
15+
echo "${bad_files}"
16+
exit 1
17+
fi
18+
19+
# ex: ts=2 sw=2 et filetype=sh

verify/golint.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
ROOT=$(dirname "${BASH_SOURCE}")/..
4+
GOLINT=${GOLINT:-"golint"}
5+
6+
pushd "${ROOT}" > /dev/null
7+
bad_files=$($GOLINT -min_confidence=0.9 ./...)
8+
if [[ -n "${bad_files}" ]]; then
9+
echo "!!! '$GOLINT' problems: "
10+
echo "${bad_files}"
11+
exit 1
12+
fi
13+
popd > /dev/null
14+
15+
# ex: ts=2 sw=2 et filetype=sh

0 commit comments

Comments
 (0)