Browse code

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 <arnaud.porterie@docker.com>

Arnaud Porterie authored on 2015/07/21 10:32:55
Showing 3 changed files
... ...
@@ -117,6 +117,11 @@ RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \
117 117
 	&& (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT) \
118 118
 	&& go install -v golang.org/x/tools/cmd/cover \
119 119
 	&& go install -v golang.org/x/tools/cmd/vet
120
+# Grab Go's lint tool
121
+ENV GO_LINT_COMMIT f42f5c1c440621302702cb0741e9d2ca547ae80f
122
+RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \
123
+	&& (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \
124
+	&& go install -v github.com/golang/lint/golint
120 125
 
121 126
 # TODO replace FPM with some very minimal debhelper stuff
122 127
 RUN gem install --no-rdoc --no-ri fpm --version 1.3.2
... ...
@@ -65,7 +65,7 @@ test-docker-py: build
65 65
 	$(DOCKER_RUN_DOCKER) hack/make.sh binary test-docker-py
66 66
 
67 67
 validate: build
68
-	$(DOCKER_RUN_DOCKER) hack/make.sh validate-dco validate-gofmt validate-pkg validate-test validate-toml validate-vet
68
+	$(DOCKER_RUN_DOCKER) hack/make.sh validate-dco validate-gofmt validate-pkg validate-lint validate-test validate-toml validate-vet
69 69
 
70 70
 shell: build
71 71
 	$(DOCKER_RUN_DOCKER) bash
72 72
new file mode 100644
... ...
@@ -0,0 +1,51 @@
0
+#!/bin/bash
1
+
2
+source "${MAKEDIR}/.validate"
3
+
4
+# We will eventually get to the point when packages should be the complete list
5
+# of subpackages, vendoring excluded, as given by:
6
+#  go list ./... | grep -v "^github.com/docker/docker/vendor"
7
+packages=(
8
+	builder/parser/dumper
9
+	daemon/events
10
+	daemon/execdriver/native/template
11
+	daemon/network
12
+	cliconfig
13
+	docker
14
+	dockerinit
15
+	pkg/chrootarchive
16
+	pkg/directory
17
+	pkg/fileutils
18
+	pkg/homedir
19
+	pkg/listenbuffer
20
+	pkg/mflag/example
21
+	pkg/promise
22
+	pkg/pubsub
23
+	pkg/random
24
+	pkg/symlink
25
+	pkg/timeutils
26
+	pkg/tlsconfig
27
+	pkg/urlutil
28
+	pkg/version
29
+)
30
+
31
+errors=()
32
+for p in "$packages"; do
33
+	failedLint=$(golint "github.com/docker/docker/$p")
34
+	if [ "$failedLint" ]; then
35
+		errors+=( "$failedLint"  )
36
+	fi
37
+done
38
+
39
+if [ ${#errors[@]} -eq 0 ]; then
40
+	echo 'Congratulations!  All Go source files have been linted.'
41
+else
42
+	{
43
+		echo "Errors from golint:"
44
+		echo "${errors[@]}"
45
+		echo
46
+		echo 'Please fix the above errors. You can test via "golint" and commit the result.'
47
+		echo
48
+	} >&2
49
+	false
50
+fi