From 42c144f765a2b7cae1313b0a84b0f4a2b8c860ed Mon Sep 17 00:00:00 2001 From: Michael Lesko-Krleza Date: Fri, 6 Aug 2021 20:07:24 -0400 Subject: [PATCH] test: misc: Create new linter test using golangci-lint instead of gometalinter --- .golangci.yml | 17 ++++++++++++++ misc/make-deps.sh | 3 +++ test.sh | 1 + test/test-golangci-lint.sh | 48 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 .golangci.yml create mode 100644 test/test-golangci-lint.sh diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000000..71d1cdecca --- /dev/null +++ b/.golangci.yml @@ -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 \ No newline at end of file diff --git a/misc/make-deps.sh b/misc/make-deps.sh index 15558f30d7..8fed981ee3 100755 --- a/misc/make-deps.sh +++ b/misc/make-deps.sh @@ -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" && \ diff --git a/test.sh b/test.sh index 9fec17a6e1..4f51b55232 100755 --- a/test.sh +++ b/test.sh @@ -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 diff --git a/test/test-golangci-lint.sh b/test/test-golangci-lint.sh new file mode 100644 index 0000000000..7ea4ced394 --- /dev/null +++ b/test/test-golangci-lint.sh @@ -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' \ No newline at end of file