Browse code

Use gometalinter for linting

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2017/08/18 02:52:14
Showing 13 changed files
... ...
@@ -115,17 +115,6 @@ RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" \
115 115
 ENV PATH /go/bin:/usr/local/go/bin:$PATH
116 116
 ENV GOPATH /go
117 117
 
118
-# Dependency for golint
119
-ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
120
-RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \
121
-	&& (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT)
122
-
123
-# Grab Go's lint tool
124
-ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
125
-RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \
126
-	&& (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \
127
-	&& go install -v github.com/golang/lint/golint
128
-
129 118
 # Install CRIU for checkpoint/restore support
130 119
 ENV CRIU_VERSION 2.12.1
131 120
 # Install dependancy packages specific to criu
... ...
@@ -215,7 +204,7 @@ RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \
215 215
 # Please edit hack/dockerfile/install-binaries.sh to update them.
216 216
 COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
217 217
 COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
218
-RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy dockercli
218
+RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy dockercli gometalinter
219 219
 ENV PATH=/usr/local/cli:$PATH
220 220
 
221 221
 # Activate bash completion and include Docker's completion if mounted with DOCKER_BASH_COMPLETION_PATH
... ...
@@ -98,17 +98,6 @@ RUN mkdir /usr/src/go && curl -fsSL https://golang.org/dl/go${GO_VERSION}.src.ta
98 98
 ENV PATH /go/bin:/usr/src/go/bin:$PATH
99 99
 ENV GOPATH /go
100 100
 
101
-# Dependency for golint
102
-ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
103
-RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \
104
-	&& (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT)
105
-
106
-# Grab Go's lint tool
107
-ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
108
-RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \
109
-	&& (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \
110
-	&& go install -v github.com/golang/lint/golint
111
-
112 101
 # Only install one version of the registry, because old version which support
113 102
 # schema1 manifests is not working on ARM64, we should skip integration-cli
114 103
 # tests for schema1 manifests on ARM64.
... ...
@@ -81,17 +81,6 @@ ENV GOPATH /go
81 81
 ENV GOARCH arm
82 82
 ENV GOARM 7
83 83
 
84
-# Dependency for golint
85
-ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
86
-RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \
87
-	&& (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT)
88
-
89
-# Grab Go's lint tool
90
-ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
91
-RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \
92
-	&& (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \
93
-	&& go install -v github.com/golang/lint/golint
94
-
95 84
 # Install seccomp: the version shipped upstream is too old
96 85
 ENV SECCOMP_VERSION 2.3.2
97 86
 RUN set -x \
... ...
@@ -94,17 +94,6 @@ RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" \
94 94
 ENV PATH /go/bin:/usr/local/go/bin:$PATH
95 95
 ENV GOPATH /go
96 96
 
97
-# Dependency for golint
98
-ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
99
-RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \
100
-	&& (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT)
101
-
102
-# Grab Go's lint tool
103
-ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
104
-RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \
105
-	&& (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \
106
-	&& go install -v github.com/golang/lint/golint
107
-
108 97
 # Install two versions of the registry. The first is an older version that
109 98
 # only supports schema1 manifests. The second is a newer version that supports
110 99
 # both. This allows integration-cli tests to cover push/pull with both schema1
... ...
@@ -87,17 +87,6 @@ RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-s390x.tar.gz" \
87 87
 ENV PATH /go/bin:/usr/local/go/bin:$PATH
88 88
 ENV GOPATH /go
89 89
 
90
-# Dependency for golint
91
-ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
92
-RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \
93
-	&& (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT)
94
-
95
-# Grab Go's lint tool
96
-ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
97
-RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \
98
-	&& (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \
99
-	&& go install -v github.com/golang/lint/golint
100
-
101 90
 # Install two versions of the registry. The first is an older version that
102 91
 # only supports schema1 manifests. The second is a newer version that supports
103 92
 # both. This allows integration-cli tests to cover push/pull with both schema1
... ...
@@ -12,3 +12,6 @@ VNDR_COMMIT=9909bb2b8a0b7ea464527b376dc50389c90df587
12 12
 # CLI
13 13
 DOCKERCLI_REPO=https://github.com/docker/cli
14 14
 DOCKERCLI_COMMIT=3dfb8343b139d6342acfd9975d7f1068b5b1c3d3
15
+
16
+# Linting
17
+GOMETALINTER_COMMIT=f7b6e55301c9c67035003b7ba7f8a1cde532d338
... ...
@@ -54,6 +54,19 @@ install_dockercli() {
54 54
 	go build -o /usr/local/bin/docker github.com/docker/cli/cmd/docker
55 55
 }
56 56
 
57
+install_gometalinter() {
58
+	echo "Installing gometalinter version $GOMETALINTER_COMMIT"
59
+	go get -d github.com/alecthomas/gometalinter
60
+	cd "$GOPATH/src/github.com/alecthomas/gometalinter"
61
+	git checkout -q "$GOMETALINTER_COMMIT"
62
+	go build -o /usr/local/bin/gometalinter github.com/alecthomas/gometalinter
63
+	(
64
+		export GOBIN=/usr/local/bin
65
+		export GOPATH="$PWD/_linters/"
66
+		go install github.com/golang/lint/golint
67
+	)
68
+}
69
+
57 70
 for prog in "$@"
58 71
 do
59 72
 	case $prog in
... ...
@@ -80,6 +93,10 @@ do
80 80
 			install_containerd
81 81
 			;;
82 82
 
83
+		gometalinter)
84
+			install_gometalinter
85
+			;;
86
+
83 87
 		tini)
84 88
 			echo "Install tini version $TINI_COMMIT"
85 89
 			git clone https://github.com/krallin/tini.git "$GOPATH/tini"
... ...
@@ -114,7 +131,7 @@ do
114 114
 			;;
115 115
 
116 116
 		*)
117
-			echo echo "Usage: $0 [tomlv|runc|runc-dynamic|containerd|containerd-dynamic|tini|proxy|proxy-dynamic|vndr|dockercli]"
117
+			echo echo "Usage: $0 [tomlv|runc|runc-dynamic|containerd|containerd-dynamic|tini|proxy|proxy-dynamic|vndr|dockercli|gometalinter]"
118 118
 			exit 1
119 119
 
120 120
 	esac
... ...
@@ -6,13 +6,11 @@ export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6 6
 
7 7
 . $SCRIPTDIR/dco
8 8
 . $SCRIPTDIR/default-seccomp
9
-. $SCRIPTDIR/gofmt
10
-. $SCRIPTDIR/lint
9
+. $SCRIPTDIR/gometalinter
11 10
 . $SCRIPTDIR/pkg-imports
12 11
 . $SCRIPTDIR/swagger
13 12
 . $SCRIPTDIR/swagger-gen
14 13
 . $SCRIPTDIR/test-imports
15 14
 . $SCRIPTDIR/toml
16
-. $SCRIPTDIR/vet
17 15
 . $SCRIPTDIR/changelog-well-formed
18 16
 . $SCRIPTDIR/changelog-date-descending
19 17
deleted file mode 100755
... ...
@@ -1,33 +0,0 @@
1
-#!/usr/bin/env bash
2
-
3
-export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4
-source "${SCRIPTDIR}/.validate"
5
-
6
-IFS=$'\n'
7
-files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' |
8
-	grep -v '^vendor/' |
9
-	grep -v '\.pb\.go$' || true) )
10
-unset IFS
11
-
12
-badFiles=()
13
-for f in "${files[@]}"; do
14
-	# we use "git show" here to validate that what's committed is formatted
15
-	if [ "$(git show "$VALIDATE_HEAD:$f" | gofmt -s -l)" ]; then
16
-		badFiles+=( "$f" )
17
-	fi
18
-done
19
-
20
-if [ ${#badFiles[@]} -eq 0 ]; then
21
-	echo 'Congratulations!  All Go source files are properly formatted.'
22
-else
23
-	{
24
-		echo "These files are not properly gofmt'd:"
25
-		for f in "${badFiles[@]}"; do
26
-			echo " - $f"
27
-		done
28
-		echo
29
-		echo 'Please reformat the above files using "gofmt -s -w" and commit the result.'
30
-		echo
31
-	} >&2
32
-	false
33
-fi
34 1
new file mode 100755
... ...
@@ -0,0 +1,6 @@
0
+#!/usr/bin/env bash
1
+set -e -o pipefail
2
+
3
+SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4
+
5
+gometalinter --config $SCRIPTDIR/gometalinter.json ./...
0 6
new file mode 100644
... ...
@@ -0,0 +1,14 @@
0
+{
1
+  "Vendor": true,
2
+  "Deadline": "2m",
3
+  "Sort": ["linter", "severity", "path"],
4
+  "Exclude": [".*\\.pb\\.go"],
5
+
6
+  "Enable": [
7
+    "gofmt",
8
+    "golint",
9
+    "vet"
10
+  ],
11
+
12
+  "LineLength": 200
13
+}
0 14
deleted file mode 100755
... ...
@@ -1,31 +0,0 @@
1
-#!/usr/bin/env bash
2
-
3
-export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4
-source "${SCRIPTDIR}/.validate"
5
-
6
-IFS=$'\n'
7
-files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' | grep -v '^api/types/container/' | grep -v '\.pb\.go$'  || true) )
8
-unset IFS
9
-
10
-errors=()
11
-for f in "${files[@]}"; do
12
-	failedLint=$(golint "$f")
13
-	if [ "$failedLint" ]; then
14
-		errors+=( "$failedLint" )
15
-	fi
16
-done
17
-
18
-if [ ${#errors[@]} -eq 0 ]; then
19
-	echo 'Congratulations!  All Go source files have been linted.'
20
-else
21
-	{
22
-		echo "Errors from golint:"
23
-		for err in "${errors[@]}"; do
24
-			echo "$err"
25
-		done
26
-		echo
27
-		echo 'Please fix the above errors. You can test via "golint" and commit the result.'
28
-		echo
29
-	} >&2
30
-	false
31
-fi
32 1
deleted file mode 100755
... ...
@@ -1,32 +0,0 @@
1
-#!/usr/bin/env bash
2
-
3
-export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4
-source "${SCRIPTDIR}/.validate"
5
-
6
-IFS=$'\n'
7
-files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' | grep -v '^api/types/container/' || true) )
8
-unset IFS
9
-
10
-errors=()
11
-for f in "${files[@]}"; do
12
-	failedVet=$(go vet "$f")
13
-	if [ "$failedVet" ]; then
14
-		errors+=( "$failedVet" )
15
-	fi
16
-done
17
-
18
-
19
-if [ ${#errors[@]} -eq 0 ]; then
20
-	echo 'Congratulations!  All Go source files have been vetted.'
21
-else
22
-	{
23
-		echo "Errors from go vet:"
24
-		for err in "${errors[@]}"; do
25
-			echo " - $err"
26
-		done
27
-		echo
28
-		echo 'Please fix the above errors. You can test via "go vet" and commit the result.'
29
-		echo
30
-	} >&2
31
-	false
32
-fi