Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create golangci_lint test script #676

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
25 changes: 25 additions & 0 deletions misc/make-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,35 @@ 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

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" && \
gometalinter --install # bonus

# # heavily recommended to use curl to install instead of go get under https://golangci-lint.run/usage/install/
# glc_version = "v1.42.0"
# curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh > $(go env GOPATH)/bin/golangci-lint
# chmod +x $(go env GOPATH)/bin/golangci-lint
# # curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh
# echo "THIS IS IN BIN!"
# ls $(go env GOPATH)/bin/
# echo "THIS IS IN GOLANGCI-LINT!"
# ls $(go env GOPATH)/bin/golangci-lint
# # puts binary into $(go env GOPATH)/bin/golangci-lint
# # heavily recommended to install specific version of golangci-lint as per https://golangci-lint.run/usage/install/
# # used to avoid breaking builds when new linter errors are introduced from a new release (minor or major)
# sh -s -- -b $(go env GOPATH)/bin/golangci-lint $glc_version
# sh -s -- -b $(go env GOPATH)/bin/golangci-lint v1.42.0

# curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.42.0
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh > $(go env GOPATH)/bin/golangci-lint-install
chmod u+x $(go env GOPATH)/bin/golangci-lint-install
./$(go env GOPATH)/bin/golangci-lint-install v1.42.0
echo "INSTALLED!"
export PATH=$PATH:$(go env GOPATH)/bin
golangci-lint --version

fi
fold_end "Install golang tools"

Expand Down
4 changes: 4 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ if in_ci; then
run-testsuite ./test/test-gotest.sh --race
run-testsuite ./test/test-integration.sh --race
fi
if label-block "basic"; then
run-testsuite ./test/test-golangci-lint.sh
fi

# XXX: fix and enable these on travis (sudo: go: command not found)
#run-testsuite ./test/test-gotest.sh --root
Expand All @@ -97,6 +100,7 @@ else
REASON="CI server only test" skip-testsuite ./test/test-gotest.sh --race
REASON="CI server only test" skip-testsuite ./test/test-integration.sh
REASON="CI server only test" skip-testsuite ./test/test-integration.sh --race
REASON="CI server only test" skip-testsuite ./test/test-golangci-test.sh

REASON="CI server only test" skip-testsuite ./test/test-gotest.sh --root
REASON="CI server only test" skip-testsuite ./test/test-gotest.sh --root --race
Expand Down
47 changes: 47 additions & 0 deletions test/test-golangci-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/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
glc='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 $glc "$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'