From 6f7d4a7a01ec752cea5211fd0b4ec3e29b0371a9 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Mon, 28 Sep 2015 08:04:19 +0000 Subject: [PATCH] Use lint from tools.git - Do lint first, on circle. --- .gitignore | 2 +- .travis.yml | 1 - Makefile | 4 +++ bin/lint | 86 ----------------------------------------------------- circle.yml | 2 ++ 5 files changed, 7 insertions(+), 88 deletions(-) delete mode 100755 bin/lint diff --git a/.gitignore b/.gitignore index fa3c6548..143b10a6 100644 --- a/.gitignore +++ b/.gitignore @@ -62,4 +62,4 @@ Vagrantfile.local test/tls/*.pem test/coverage test/coverage.* -.tools/ +.tools diff --git a/.travis.yml b/.travis.yml index d987e04c..0439e89b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,6 @@ install: - go get ./... script: - - bin/lint . - make tests after_success: diff --git a/Makefile b/Makefile index 5ac94b3c..624d29d9 100644 --- a/Makefile +++ b/Makefile @@ -115,6 +115,10 @@ tests: $(COVER_EXE) $(ENSURE_TOOLS) .tools/test +lint: + $(ENSURE_TOOLS) + .tools/lint -nocomment -notestpackage . + $(PUBLISH): publish_%: $(IMAGES_UPTODATE) $(SUDO) docker tag -f $(DOCKERHUB_USER)/$* $(DOCKERHUB_USER)/$*:$(WEAVE_VERSION) $(SUDO) docker push $(DOCKERHUB_USER)/$*:$(WEAVE_VERSION) diff --git a/bin/lint b/bin/lint deleted file mode 100755 index 32e791fb..00000000 --- a/bin/lint +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/bash -# This scipt lints go files for common errors. -# -# Its runs gofmt and go vet, and optionally golint and -# gocyclo, if they are installed. -# -# With no arguments, it lints the current files staged -# for git commit. Or you can pass it explicit filenames -# (or directories) and it will lint them. -# -# To use this script automatically, run: -# ln -s ../../bin/lint .git/hooks/pre-commit - -set -eu - -function lint_go { - filename="$1" - result=0 - - if [ -n "$(gofmt -l "${filename}")" ]; then - result=1 - echo "${filename}: run gofmt -w ${filename}!" - fi - - go tool vet "${filename}" || result=$? - - # golint is completely optional. If you don't like it - # don't have it installed. - if type golint >/dev/null 2>&1; then - # golint doesn't set an exit code it seems - lintoutput=$(golint "${filename}" | grep -vE 'comment|dot imports') - if [ "$lintoutput" != "" ]; then - result=1 - echo "$lintoutput" - fi - fi - - # gocyclo is completely optional. If you don't like it - # don't have it installed. Also never blocks a commit, - # it just warns. - if type gocyclo >/dev/null 2>&1; then - gocyclo -over 25 "${filename}" | while read line; do - echo "${filename}": higher than 25 cyclomatic complexity - "${line}" - done - fi - - return $result -} - -function lint { - filename="$1" - ext="${filename##*\.}" - - # Don't lint this script - if [ "${filename}" = "bin/lint" ]; then - return - fi - - # Don't lint files that don't exist - if ! [ -a "${filename}" ]; then - return - fi - - case "$ext" in - go) lint_go "${filename}" - ;; - esac -} - -function lint_files { - lint_result=0 - while read filename; do - lint "${filename}" || lint_result=1 - done - exit $lint_result -} - -function list_files { - if [ $# -gt 0 ]; then - find "$@" -type f - else - git diff --cached --name-only - fi -} - -list_files "$@" | lint_files diff --git a/circle.yml b/circle.yml index 655c01dc..f590e330 100644 --- a/circle.yml +++ b/circle.yml @@ -37,6 +37,8 @@ dependencies: test: override: + - cd $SRCDIR; make lint: + parallel: true - docker run -v /home/ubuntu:/home/go -e COVERDIR=test/coverage -e SLOW=true -e CIRCLECI -e CIRCLE_BUILD_NUM -e CIRCLE_NODE_TOTAL -e CIRCLE_NODE_INDEX weaveworks/weave-test: parallel: true - docker run -v /var/run/docker.sock:/run/docker.sock -v /home/ubuntu:/home/go -e COVERAGE=true weaveworks/weave-build: