From 6cce8d18384a5ae1212e7b0f7b7ac9662a89c8c1 Mon Sep 17 00:00:00 2001 From: Arnaud Porterie Date: Mon, 20 Jul 2015 18:32:55 -0700 Subject: [PATCH] Add golint to the development toolbox Add golint to the Dockerfile, and a `validate-lint` task to the Makefile. Currently, the linter will process a harcoded list of packages that will expand as we fix more warnings. Eventually, the linter should process all subpackages of the repo (excluding vendored code). Signed-off-by: Arnaud Porterie --- Dockerfile | 5 ++++ Makefile | 2 +- hack/make/validate-lint | 51 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 hack/make/validate-lint diff --git a/Dockerfile b/Dockerfile index bfeaba8056..a25e3b9037 100644 --- a/Dockerfile +++ b/Dockerfile @@ -117,6 +117,11 @@ RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \ && (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT) \ && go install -v golang.org/x/tools/cmd/cover \ && go install -v golang.org/x/tools/cmd/vet +# Grab Go's lint tool +ENV GO_LINT_COMMIT f42f5c1c440621302702cb0741e9d2ca547ae80f +RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \ + && (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \ + && go install -v github.com/golang/lint/golint # TODO replace FPM with some very minimal debhelper stuff RUN gem install --no-rdoc --no-ri fpm --version 1.3.2 diff --git a/Makefile b/Makefile index f76d127f51..a3d3a0c820 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ test-docker-py: build $(DOCKER_RUN_DOCKER) hack/make.sh binary test-docker-py validate: build - $(DOCKER_RUN_DOCKER) hack/make.sh validate-dco validate-gofmt validate-pkg validate-test validate-toml validate-vet + $(DOCKER_RUN_DOCKER) hack/make.sh validate-dco validate-gofmt validate-pkg validate-lint validate-test validate-toml validate-vet shell: build $(DOCKER_RUN_DOCKER) bash diff --git a/hack/make/validate-lint b/hack/make/validate-lint new file mode 100644 index 0000000000..870b6c0b3b --- /dev/null +++ b/hack/make/validate-lint @@ -0,0 +1,51 @@ +#!/bin/bash + +source "${MAKEDIR}/.validate" + +# We will eventually get to the point when packages should be the complete list +# of subpackages, vendoring excluded, as given by: +# go list ./... | grep -v "^github.com/docker/docker/vendor" +packages=( + builder/parser/dumper + daemon/events + daemon/execdriver/native/template + daemon/network + cliconfig + docker + dockerinit + pkg/chrootarchive + pkg/directory + pkg/fileutils + pkg/homedir + pkg/listenbuffer + pkg/mflag/example + pkg/promise + pkg/pubsub + pkg/random + pkg/symlink + pkg/timeutils + pkg/tlsconfig + pkg/urlutil + pkg/version +) + +errors=() +for p in "$packages"; do + failedLint=$(golint "github.com/docker/docker/$p") + if [ "$failedLint" ]; then + errors+=( "$failedLint" ) + fi +done + +if [ ${#errors[@]} -eq 0 ]; then + echo 'Congratulations! All Go source files have been linted.' +else + { + echo "Errors from golint:" + echo "${errors[@]}" + echo + echo 'Please fix the above errors. You can test via "golint" and commit the result.' + echo + } >&2 + false +fi