Skip to content

Commit

Permalink
test: misc: Create new linter test using golangci-lint instead of gom…
Browse files Browse the repository at this point in the history
…etalinter
  • Loading branch information
ginywiny committed Aug 10, 2021
1 parent c555478 commit 9d05a93
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# test-golangci-lint configuration file for golangci-lint

run:
skip-files:
- lang/lexer.nn.go
- lang/y.go
- bindata/bindata.go
- lang/types/kind_stringer.go
- lang/interpolate/parse.generated.go
- lang/interpolate/interpolate/parse.generated.go

linters:
disable-all: true
enable:
- goimports
- revive # using revive instead of golint as it runs more quickly
- misspell
3 changes: 3 additions & 0 deletions misc/make-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ go get golang.org/x/lint/golint # for `golint`-ing
go get golang.org/x/tools/cmd/goimports # for fmt
go get github.com/kevinburke/go-bindata/go-bindata # for compiling in non golang files
go get github.com/dvyukov/go-fuzz/go-fuzz # for fuzzing the mcl lang bits
# heavily recommended to use curl to install instead of go get under https://golangci-lint.run/usage/install/
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.41.1

if in_ci; then
go get -u gopkg.in/alecthomas/gometalinter.v1 && \
mv "$(dirname $(command -v gometalinter.v1))/gometalinter.v1" "$(dirname $(command -v gometalinter.v1))/gometalinter" && \
Expand Down
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ if label-block "basic"; then
run-testsuite ./test/test-examples.sh
run-testsuite ./test/test-gotest.sh
run-testsuite ./test/test-gometalinter.sh
run-testsuite ./test/test-golangci-lint.sh
run-testsuite ./test/test-golint.sh # test last, because this test is somewhat arbitrary
# FIXME: this now fails everywhere :(
skip-testsuite ./test/test-reproducible.sh
Expand Down
48 changes: 48 additions & 0 deletions test/test-golangci-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# print current running test
echo running "$0"

command -v golangci-lint >/dev/null 2>&1 || { echo >&2 "golangci-lint not found"; exit 1; }

# configure settings for test scripts
ROOT=$(dirname "${BASH_SOURCE}")/..
cd "${ROOT}" # Enter mgmt root
. test/util.sh

failures=''
function run-test()
{
$@ || failures=$( [ -n "$failures" ] && echo "$failures\\n$@" || echo "$@" )
}

# using .golangci.yml config file settings in ROOT
gcl='golangci-lint run'

# commented out from gometalinter linter test
# aligncheck, dupl, errcheck, gas, goconst, gocyclo, gotype, unconvert

# TODO: only a few fixes needed before using following linters:
# deadcode, gosimple, ineffassign, interfacer, lll --line-length=200
# safesql, staticcheck, structcheck, unparam, unused, varcheck

for dir in `find * -maxdepth 9 -type d -not -path 'old/*' -not -path 'old' -not -path 'tmp/*' -not -path 'tmp' -not -path 'vendor/*' -not -path 'examples/*' -not -path 'test/*' -not -path 'interpolate/*'`; do

# doesn't acquire files individually, but treats them as a set of * files
match="$dir/*.go"

if ! ls $match &>/dev/null; then
continue # no *.go files found
fi

run-test $gcl "$dir" || fail_test "golangci-lint did not pass"
done

if [[ -n "$failures" ]]; then
echo 'FAIL'
echo 'The following tests have failed:'
echo -e "$failures"
echo
exit 1
fi
echo 'PASS'

0 comments on commit 9d05a93

Please sign in to comment.