test: Add gometalinter to our test suite
Add a bunch of new linters to our tests! We can uncomment each sub linter as we fix up the few remaining issues.
This commit is contained in:
@@ -80,4 +80,5 @@ if [[ $ret != 0 ]]; then
|
|||||||
fi
|
fi
|
||||||
go get golang.org/x/tools/cmd/stringer # for automatic stringer-ing
|
go get golang.org/x/tools/cmd/stringer # for automatic stringer-ing
|
||||||
go get github.com/golang/lint/golint # for `golint`-ing
|
go get github.com/golang/lint/golint # for `golint`-ing
|
||||||
|
go get github.com/alecthomas/gometalinter && gometalinter --install # bonus
|
||||||
cd "$XPWD" >/dev/null
|
cd "$XPWD" >/dev/null
|
||||||
|
|||||||
1
test.sh
1
test.sh
@@ -32,6 +32,7 @@ if env | grep -q -e '^TRAVIS=true$' -e '^JENKINS_URL=' -e '^BUILD_TAG=jenkins';
|
|||||||
run-test ./test/test-gotest.sh --race
|
run-test ./test/test-gotest.sh --race
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
run-test ./test/test-gometalinter.sh
|
||||||
# FIXME: this now fails everywhere :(
|
# FIXME: this now fails everywhere :(
|
||||||
#run-test ./test/test-reproducible.sh
|
#run-test ./test/test-reproducible.sh
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
. test/util.sh
|
. test/util.sh
|
||||||
|
|
||||||
echo running test-golint.sh
|
echo running test-golint.sh
|
||||||
|
# TODO: replace with gometalinter instead of plain golint
|
||||||
# TODO: output a diff of what has changed in the golint output
|
# TODO: output a diff of what has changed in the golint output
|
||||||
# FIXME: test a range of commits, since only the last patch is checked here
|
# FIXME: test a range of commits, since only the last patch is checked here
|
||||||
PREVIOUS='HEAD^'
|
PREVIOUS='HEAD^'
|
||||||
|
|||||||
63
test/test-gometalinter.sh
Executable file
63
test/test-gometalinter.sh
Executable file
@@ -0,0 +1,63 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# check a bunch of linters with the gometalinter
|
||||||
|
# TODO: run this from the test-golint.sh file instead to check for deltas
|
||||||
|
|
||||||
|
. test/util.sh
|
||||||
|
|
||||||
|
echo running test-gometalinter.sh
|
||||||
|
|
||||||
|
failures=''
|
||||||
|
function run-test()
|
||||||
|
{
|
||||||
|
$@ || failures=$( [ -n "$failures" ] && echo "$failures\\n$@" || echo "$@" )
|
||||||
|
}
|
||||||
|
|
||||||
|
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir!
|
||||||
|
cd "${ROOT}"
|
||||||
|
|
||||||
|
# TODO: run more linters here if we're brave...
|
||||||
|
gml='gometalinter --disable-all'
|
||||||
|
#gml="$gml --enable=aligncheck"
|
||||||
|
#gml="$gml --enable=deadcode" # TODO: only a few fixes needed
|
||||||
|
#gml="$gml --enable=dupl"
|
||||||
|
#gml="$gml --enable=errcheck"
|
||||||
|
#gml="$gml --enable=gas"
|
||||||
|
#gml="$gml --enable=goconst"
|
||||||
|
#gml="$gml --enable=gocyclo"
|
||||||
|
gml="$gml --enable=goimports"
|
||||||
|
#gml="$gml --enable=golint" # TODO: only a few fixes needed
|
||||||
|
#gml="$gml --enable=gosimple" # TODO: only a few fixes needed
|
||||||
|
gml="$gml --enable=gotype"
|
||||||
|
#gml="$gml --enable=ineffassign" # TODO: only a few fixes needed
|
||||||
|
#gml="$gml --enable=interfacer" # TODO: only a few fixes needed
|
||||||
|
#gml="$gml --enable=lll --line-length=200" # TODO: only a few fixes needed
|
||||||
|
gml="$gml --enable=misspell"
|
||||||
|
#gml="$gml --enable=safesql" # FIXME: made my machine slow
|
||||||
|
#gml="$gml --enable=staticcheck" # TODO: only a few fixes needed
|
||||||
|
#gml="$gml --enable=structcheck" # TODO: only a few fixes needed
|
||||||
|
gml="$gml --enable=unconvert"
|
||||||
|
#gml="$gml --enable=unparam" # TODO: only a few fixes needed
|
||||||
|
#gml="$gml --enable=unused" # TODO: only a few fixes needed
|
||||||
|
#gml="$gml --enable=varcheck" # TODO: only a few fixes needed
|
||||||
|
gometalinter="$gml"
|
||||||
|
|
||||||
|
# loop through directories in an attempt to scan each go package
|
||||||
|
# TODO: lint the *.go examples as individual files and not as a single *.go
|
||||||
|
for dir in `find . -maxdepth 5 -type d -not -path './old/*' -not -path './old' -not -path './tmp/*' -not -path './tmp' -not -path './.*' -not -path './vendor/*' -not -path './examples/*'`; do
|
||||||
|
match="$dir/*.go"
|
||||||
|
#echo "match is: $match"
|
||||||
|
if ! ls $match &>/dev/null; then
|
||||||
|
#echo "skipping: $match"
|
||||||
|
continue # no *.go files found
|
||||||
|
fi
|
||||||
|
|
||||||
|
run-test $gometalinter "$dir" || fail_test "gometalinter did not pass"
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -n "$failures" ]]; then
|
||||||
|
echo 'FAIL'
|
||||||
|
echo 'The following tests have failed:'
|
||||||
|
echo -e "$failures"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo 'PASS'
|
||||||
Reference in New Issue
Block a user