From 72dd427d07a731c9c1f402b7fbc5210e5e4b0c6c Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Mon, 10 Oct 2016 11:07:33 -0700 Subject: [PATCH] ref(scripts): use gometalinter for linters --- scripts/validate-go.sh | 65 +++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/scripts/validate-go.sh b/scripts/validate-go.sh index 8c68bac69..ccdfd2fef 100755 --- a/scripts/validate-go.sh +++ b/scripts/validate-go.sh @@ -15,42 +15,37 @@ # limitations under the License. set -euo pipefail -readonly reset=$(tput sgr0) -readonly red=$(tput bold; tput setaf 1) -readonly green=$(tput bold; tput setaf 2) -readonly yellow=$(tput bold; tput setaf 3) - exit_code=0 -find_go_files() { - find . -type f -name "*.go" | grep -v vendor -} - -hash golint 2>/dev/null || go get -u github.com/golang/lint/golint -hash godir 2>/dev/null || go get -u github.com/Masterminds/godir - -echo "==> Running golint..." -for pkg in $(godir pkgs | grep -v proto); do - golint_out=$(golint "$pkg" 2>&1) - if [[ -n "$golint_out" ]]; then - echo "${yellow}${golint_out}${reset}" - fi -done - -echo "==> Running go vet..." -echo -n "$red" -go vet $(godir pkgs) 2>&1 | grep -v "^exit status " || exit_code=${PIPESTATUS[0]} -echo -n "$reset" - -echo "==> Running gofmt..." -failed_fmt=$(find_go_files | xargs gofmt -s -l) -if [[ -n "${failed_fmt}" ]]; then - echo -n "${red}" - echo "gofmt check failed:" - echo "$failed_fmt" - gofmt -s -d "${failed_fmt}" - echo -n "${reset}" - exit_code=1 +if ! hash gometalinter 2>/dev/null ; then + go get github.com/alecthomas/gometalinter + gometalinter --install fi -exit ${exit_code} +echo +echo "==> Running static validations <==" +# Run linters that should return errors +gometalinter \ + --disable-all \ + --enable deadcode \ + --severity deadcode:error \ + --enable gofmt \ + --enable gosimple \ + --enable ineffassign \ + --enable misspell \ + --enable vet \ + --tests \ + --vendor \ + ./... || exit_code=1 + +echo +echo "==> Running linters <==" +# Run linters that should return warnings +gometalinter \ + --disable-all \ + --enable golint \ + --vendor \ + --skip proto \ + ./... || : + +exit $exit_code