mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Use gometalinter for linting
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
30eb4d8cdc
commit
d7e2c4ce77
13 changed files with 43 additions and 156 deletions
13
Dockerfile
13
Dockerfile
|
@ -115,17 +115,6 @@ RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" \
|
||||||
ENV PATH /go/bin:/usr/local/go/bin:$PATH
|
ENV PATH /go/bin:/usr/local/go/bin:$PATH
|
||||||
ENV GOPATH /go
|
ENV GOPATH /go
|
||||||
|
|
||||||
# Dependency for golint
|
|
||||||
ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
|
|
||||||
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)
|
|
||||||
|
|
||||||
# Grab Go's lint tool
|
|
||||||
ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
|
|
||||||
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
|
|
||||||
|
|
||||||
# Install CRIU for checkpoint/restore support
|
# Install CRIU for checkpoint/restore support
|
||||||
ENV CRIU_VERSION 2.12.1
|
ENV CRIU_VERSION 2.12.1
|
||||||
# Install dependancy packages specific to criu
|
# Install dependancy packages specific to criu
|
||||||
|
@ -215,7 +204,7 @@ RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \
|
||||||
# Please edit hack/dockerfile/install-binaries.sh to update them.
|
# Please edit hack/dockerfile/install-binaries.sh to update them.
|
||||||
COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
|
COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
|
||||||
COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
|
COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
|
||||||
RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy dockercli
|
RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy dockercli gometalinter
|
||||||
ENV PATH=/usr/local/cli:$PATH
|
ENV PATH=/usr/local/cli:$PATH
|
||||||
|
|
||||||
# Activate bash completion and include Docker's completion if mounted with DOCKER_BASH_COMPLETION_PATH
|
# 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
|
||||||
ENV PATH /go/bin:/usr/src/go/bin:$PATH
|
ENV PATH /go/bin:/usr/src/go/bin:$PATH
|
||||||
ENV GOPATH /go
|
ENV GOPATH /go
|
||||||
|
|
||||||
# Dependency for golint
|
|
||||||
ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
|
|
||||||
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)
|
|
||||||
|
|
||||||
# Grab Go's lint tool
|
|
||||||
ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
|
|
||||||
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
|
|
||||||
|
|
||||||
# Only install one version of the registry, because old version which support
|
# Only install one version of the registry, because old version which support
|
||||||
# schema1 manifests is not working on ARM64, we should skip integration-cli
|
# schema1 manifests is not working on ARM64, we should skip integration-cli
|
||||||
# tests for schema1 manifests on ARM64.
|
# tests for schema1 manifests on ARM64.
|
||||||
|
|
|
@ -81,17 +81,6 @@ ENV GOPATH /go
|
||||||
ENV GOARCH arm
|
ENV GOARCH arm
|
||||||
ENV GOARM 7
|
ENV GOARM 7
|
||||||
|
|
||||||
# Dependency for golint
|
|
||||||
ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
|
|
||||||
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)
|
|
||||||
|
|
||||||
# Grab Go's lint tool
|
|
||||||
ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
|
|
||||||
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
|
|
||||||
|
|
||||||
# Install seccomp: the version shipped upstream is too old
|
# Install seccomp: the version shipped upstream is too old
|
||||||
ENV SECCOMP_VERSION 2.3.2
|
ENV SECCOMP_VERSION 2.3.2
|
||||||
RUN set -x \
|
RUN set -x \
|
||||||
|
|
|
@ -94,17 +94,6 @@ RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" \
|
||||||
ENV PATH /go/bin:/usr/local/go/bin:$PATH
|
ENV PATH /go/bin:/usr/local/go/bin:$PATH
|
||||||
ENV GOPATH /go
|
ENV GOPATH /go
|
||||||
|
|
||||||
# Dependency for golint
|
|
||||||
ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
|
|
||||||
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)
|
|
||||||
|
|
||||||
# Grab Go's lint tool
|
|
||||||
ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
|
|
||||||
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
|
|
||||||
|
|
||||||
# Install two versions of the registry. The first is an older version that
|
# Install two versions of the registry. The first is an older version that
|
||||||
# only supports schema1 manifests. The second is a newer version that supports
|
# only supports schema1 manifests. The second is a newer version that supports
|
||||||
# both. This allows integration-cli tests to cover push/pull with both schema1
|
# 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" \
|
||||||
ENV PATH /go/bin:/usr/local/go/bin:$PATH
|
ENV PATH /go/bin:/usr/local/go/bin:$PATH
|
||||||
ENV GOPATH /go
|
ENV GOPATH /go
|
||||||
|
|
||||||
# Dependency for golint
|
|
||||||
ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
|
|
||||||
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)
|
|
||||||
|
|
||||||
# Grab Go's lint tool
|
|
||||||
ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
|
|
||||||
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
|
|
||||||
|
|
||||||
# Install two versions of the registry. The first is an older version that
|
# Install two versions of the registry. The first is an older version that
|
||||||
# only supports schema1 manifests. The second is a newer version that supports
|
# only supports schema1 manifests. The second is a newer version that supports
|
||||||
# both. This allows integration-cli tests to cover push/pull with both schema1
|
# both. This allows integration-cli tests to cover push/pull with both schema1
|
||||||
|
|
|
@ -12,3 +12,6 @@ VNDR_COMMIT=9909bb2b8a0b7ea464527b376dc50389c90df587
|
||||||
# CLI
|
# CLI
|
||||||
DOCKERCLI_REPO=https://github.com/docker/cli
|
DOCKERCLI_REPO=https://github.com/docker/cli
|
||||||
DOCKERCLI_COMMIT=3dfb8343b139d6342acfd9975d7f1068b5b1c3d3
|
DOCKERCLI_COMMIT=3dfb8343b139d6342acfd9975d7f1068b5b1c3d3
|
||||||
|
|
||||||
|
# Linting
|
||||||
|
GOMETALINTER_COMMIT=f7b6e55301c9c67035003b7ba7f8a1cde532d338
|
||||||
|
|
|
@ -54,6 +54,19 @@ install_dockercli() {
|
||||||
go build -o /usr/local/bin/docker github.com/docker/cli/cmd/docker
|
go build -o /usr/local/bin/docker github.com/docker/cli/cmd/docker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
install_gometalinter() {
|
||||||
|
echo "Installing gometalinter version $GOMETALINTER_COMMIT"
|
||||||
|
go get -d github.com/alecthomas/gometalinter
|
||||||
|
cd "$GOPATH/src/github.com/alecthomas/gometalinter"
|
||||||
|
git checkout -q "$GOMETALINTER_COMMIT"
|
||||||
|
go build -o /usr/local/bin/gometalinter github.com/alecthomas/gometalinter
|
||||||
|
(
|
||||||
|
export GOBIN=/usr/local/bin
|
||||||
|
export GOPATH="$PWD/_linters/"
|
||||||
|
go install github.com/golang/lint/golint
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
for prog in "$@"
|
for prog in "$@"
|
||||||
do
|
do
|
||||||
case $prog in
|
case $prog in
|
||||||
|
@ -80,6 +93,10 @@ do
|
||||||
install_containerd
|
install_containerd
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
gometalinter)
|
||||||
|
install_gometalinter
|
||||||
|
;;
|
||||||
|
|
||||||
tini)
|
tini)
|
||||||
echo "Install tini version $TINI_COMMIT"
|
echo "Install tini version $TINI_COMMIT"
|
||||||
git clone https://github.com/krallin/tini.git "$GOPATH/tini"
|
git clone https://github.com/krallin/tini.git "$GOPATH/tini"
|
||||||
|
@ -114,7 +131,7 @@ do
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
echo echo "Usage: $0 [tomlv|runc|runc-dynamic|containerd|containerd-dynamic|tini|proxy|proxy-dynamic|vndr|dockercli]"
|
echo echo "Usage: $0 [tomlv|runc|runc-dynamic|containerd|containerd-dynamic|tini|proxy|proxy-dynamic|vndr|dockercli|gometalinter]"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -6,13 +6,11 @@ export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
. $SCRIPTDIR/dco
|
. $SCRIPTDIR/dco
|
||||||
. $SCRIPTDIR/default-seccomp
|
. $SCRIPTDIR/default-seccomp
|
||||||
. $SCRIPTDIR/gofmt
|
. $SCRIPTDIR/gometalinter
|
||||||
. $SCRIPTDIR/lint
|
|
||||||
. $SCRIPTDIR/pkg-imports
|
. $SCRIPTDIR/pkg-imports
|
||||||
. $SCRIPTDIR/swagger
|
. $SCRIPTDIR/swagger
|
||||||
. $SCRIPTDIR/swagger-gen
|
. $SCRIPTDIR/swagger-gen
|
||||||
. $SCRIPTDIR/test-imports
|
. $SCRIPTDIR/test-imports
|
||||||
. $SCRIPTDIR/toml
|
. $SCRIPTDIR/toml
|
||||||
. $SCRIPTDIR/vet
|
|
||||||
. $SCRIPTDIR/changelog-well-formed
|
. $SCRIPTDIR/changelog-well-formed
|
||||||
. $SCRIPTDIR/changelog-date-descending
|
. $SCRIPTDIR/changelog-date-descending
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
||||||
source "${SCRIPTDIR}/.validate"
|
|
||||||
|
|
||||||
IFS=$'\n'
|
|
||||||
files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' |
|
|
||||||
grep -v '^vendor/' |
|
|
||||||
grep -v '\.pb\.go$' || true) )
|
|
||||||
unset IFS
|
|
||||||
|
|
||||||
badFiles=()
|
|
||||||
for f in "${files[@]}"; do
|
|
||||||
# we use "git show" here to validate that what's committed is formatted
|
|
||||||
if [ "$(git show "$VALIDATE_HEAD:$f" | gofmt -s -l)" ]; then
|
|
||||||
badFiles+=( "$f" )
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ ${#badFiles[@]} -eq 0 ]; then
|
|
||||||
echo 'Congratulations! All Go source files are properly formatted.'
|
|
||||||
else
|
|
||||||
{
|
|
||||||
echo "These files are not properly gofmt'd:"
|
|
||||||
for f in "${badFiles[@]}"; do
|
|
||||||
echo " - $f"
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echo 'Please reformat the above files using "gofmt -s -w" and commit the result.'
|
|
||||||
echo
|
|
||||||
} >&2
|
|
||||||
false
|
|
||||||
fi
|
|
6
hack/validate/gometalinter
Executable file
6
hack/validate/gometalinter
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e -o pipefail
|
||||||
|
|
||||||
|
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
gometalinter --config $SCRIPTDIR/gometalinter.json ./...
|
14
hack/validate/gometalinter.json
Normal file
14
hack/validate/gometalinter.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"Vendor": true,
|
||||||
|
"Deadline": "2m",
|
||||||
|
"Sort": ["linter", "severity", "path"],
|
||||||
|
"Exclude": [".*\\.pb\\.go"],
|
||||||
|
|
||||||
|
"Enable": [
|
||||||
|
"gofmt",
|
||||||
|
"golint",
|
||||||
|
"vet"
|
||||||
|
],
|
||||||
|
|
||||||
|
"LineLength": 200
|
||||||
|
}
|
|
@ -1,31 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
||||||
source "${SCRIPTDIR}/.validate"
|
|
||||||
|
|
||||||
IFS=$'\n'
|
|
||||||
files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' | grep -v '^api/types/container/' | grep -v '\.pb\.go$' || true) )
|
|
||||||
unset IFS
|
|
||||||
|
|
||||||
errors=()
|
|
||||||
for f in "${files[@]}"; do
|
|
||||||
failedLint=$(golint "$f")
|
|
||||||
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:"
|
|
||||||
for err in "${errors[@]}"; do
|
|
||||||
echo "$err"
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echo 'Please fix the above errors. You can test via "golint" and commit the result.'
|
|
||||||
echo
|
|
||||||
} >&2
|
|
||||||
false
|
|
||||||
fi
|
|
|
@ -1,32 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
||||||
source "${SCRIPTDIR}/.validate"
|
|
||||||
|
|
||||||
IFS=$'\n'
|
|
||||||
files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' | grep -v '^api/types/container/' || true) )
|
|
||||||
unset IFS
|
|
||||||
|
|
||||||
errors=()
|
|
||||||
for f in "${files[@]}"; do
|
|
||||||
failedVet=$(go vet "$f")
|
|
||||||
if [ "$failedVet" ]; then
|
|
||||||
errors+=( "$failedVet" )
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
if [ ${#errors[@]} -eq 0 ]; then
|
|
||||||
echo 'Congratulations! All Go source files have been vetted.'
|
|
||||||
else
|
|
||||||
{
|
|
||||||
echo "Errors from go vet:"
|
|
||||||
for err in "${errors[@]}"; do
|
|
||||||
echo " - $err"
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echo 'Please fix the above errors. You can test via "go vet" and commit the result.'
|
|
||||||
echo
|
|
||||||
} >&2
|
|
||||||
false
|
|
||||||
fi
|
|
Loading…
Add table
Reference in a new issue