From 1f82d834e7ced26da4cc991bd4574e43dafd34f0 Mon Sep 17 00:00:00 2001 From: Erik Wilson Date: Sun, 24 Mar 2019 21:50:02 -0700 Subject: [PATCH] Upgrade to golangci-lint --- .golangci.json | 19 +++++++++++++++++++ .gometalinter.json | 11 ----------- Dockerfile.dapper | 15 ++++++++------- scripts/validate | 27 +++++++-------------------- 4 files changed, 34 insertions(+), 38 deletions(-) create mode 100644 .golangci.json delete mode 100644 .gometalinter.json diff --git a/.golangci.json b/.golangci.json new file mode 100644 index 0000000000..f317e3171c --- /dev/null +++ b/.golangci.json @@ -0,0 +1,19 @@ +{ + "linters": { + "disable-all": true, + "enable": [ + "govet", + "golint", + "goimports", + "misspell", + "ineffassign", + "gofmt" + ] + }, + "run": { + "skip-files": [ + "/zz_generated_" + ], + "deadline": "5m" + } +} diff --git a/.gometalinter.json b/.gometalinter.json deleted file mode 100644 index 3ae06d8d1a..0000000000 --- a/.gometalinter.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "EnableAll": false, - "Enable": [ - "golint", - "goimports", - "misspell", - "ineffassign", - "errcheck" - ], - "Deadline": "1m" -} \ No newline at end of file diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 235a9900c4..0ce9be783f 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -6,17 +6,18 @@ RUN apk -U --no-cache add bash git gcc musl-dev docker vim less file curl wget c RUN pip3 install 'tox==3.6.0' RUN apk -U --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/main/ add sqlite-dev sqlite-static RUN mkdir -p /go/src/golang.org/x && \ - cd /go/src/golang.org/x && git clone https://github.com/golang/tools && git clone https://github.com/golang/lint && \ - git -C /go/src/golang.org/x/lint/golint checkout -b current 06c8688daad7faa9da5a0c2f163a3d14aac986ca && \ - go install golang.org/x/lint/golint -RUN go get -d github.com/alecthomas/gometalinter && \ - git -C /go/src/github.com/alecthomas/gometalinter checkout -b current v2.0.11 && \ - go install github.com/alecthomas/gometalinter && \ - gometalinter --install + cd /go/src/golang.org/x && git clone https://github.com/golang/tools && \ + git -C /go/src/golang.org/x/tools checkout -b current e9f45831faab4562ce3f53f7196b67c08f948e86 && \ + go install golang.org/x/tools/cmd/goimports RUN rm -rf /go/src /go/pkg ARG DAPPER_HOST_ARCH ENV ARCH $DAPPER_HOST_ARCH + +RUN if [ "${ARCH}" == "amd64" ]; then \ + curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.15.0; \ + fi + ENV DAPPER_RUN_ARGS --privileged -v k3s-cache:/go/src/github.com/rancher/k3s/.cache ENV DAPPER_ENV REPO TAG DRONE_TAG IMAGE_NAME ENV DAPPER_SOURCE /go/src/github.com/rancher/k3s/ diff --git a/scripts/validate b/scripts/validate index 90d12fa663..f0d75057fe 100755 --- a/scripts/validate +++ b/scripts/validate @@ -3,34 +3,21 @@ set -e cd $(dirname $0)/.. +if ! command -v golangci-lint; then + echo Skipping validation: no golangci-lint available + exit +fi echo Running validation -PACKAGES="$(go list ./...)" - if [ ! -e build/data ];then mkdir -p build/data fi +echo Running: go generate go generate -echo Running: go vet -go vet ${PACKAGES} -echo Running: gometalinter -for i in ${PACKAGES}; do - if [ -n "$(gometalinter $i | \ - grep -v 'pkg/data/zz_generated_bindata.go' | \ - grep -v 'should have comment.*or be unexported' | \ - grep -v 'cli/cmd.*don.t use underscores in Go name' | \ - grep -v 'cli/cmd.*should be DNS' | \ - tee /dev/stderr)" ]; then - failed=true - fi -done -test -z "$failed" -echo Running: go fmt -test -z "$(go fmt ${PACKAGES} | \ - grep -v 'pkg/data/zz_generated_bindata.go' | \ - tee /dev/stderr)" +echo Running: golangci-lint +golangci-lint run . ./scripts/version.sh