dev: Configure the Go linting tool (#7839)

This change configures the devcontainer to use `golangci-lint`
and updates the `bin/lint` script to derive the `golangci-lint`
version from the devcontainer's `Dockerfile`.

Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
This commit is contained in:
Kevin Leimkuhler 2022-02-15 17:08:16 -07:00 committed by GitHub
parent 7f0edb85ae
commit adeaa17ae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 5 deletions

View File

@ -2,6 +2,7 @@ ARG GO_VERSION=1.17
ARG RUST_TOOLCHAIN=1.56.1
FROM docker.io/golang:${GO_VERSION}-bullseye as go
ARG GOLANGCI_LINT_VERSION=v1.44.0
RUN for p in \
github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest \
github.com/ramya-rao-a/go-outline@latest \
@ -10,7 +11,7 @@ RUN for p in \
github.com/josharian/impl@latest \
github.com/haya14busa/goplay/cmd/goplay@latest \
github.com/go-delve/delve/cmd/dlv@latest \
github.com/golangci/golangci-lint/cmd/golangci-lint@latest \
github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION#v} \
golang.org/x/tools/gopls@latest \
; do go install "$p" ; done

View File

@ -14,6 +14,9 @@
"vadimcn.vscode-lldb",
"zxh404.vscode-proto3"
],
"settings": {
"go.lintTool": "golangci-lint"
},
"runArgs": [
"--init",
// Use the host network so we can access k3d, etc.

View File

@ -2,12 +2,11 @@
set -eu
lintversion=1.43.0
cd "$(pwd -P)"
bindir=$( cd "${0%/*}" && pwd )
rootdir=$( cd "$bindir"/.. && pwd )
devcontainerdir=$( cd "$rootdir"/.devcontainer && pwd )
targetbin=$rootdir/target/bin
cd "$rootdir"
@ -20,11 +19,16 @@ elif [ "$(uname -o)" = Msys ]; then
exe=.exe
fi
lintbin=$targetbin/.golangci-lint-$lintversion$exe
lintversion=$(sed -nE 's/^ARG GOLANGCI_LINT_VERSION=(v[^ ]+)/\1/p' "$devcontainerdir"/Dockerfile | head -n 1)
if [ -z "$lintversion" ]; then
echo "GOLANGCI_LINT_VERSION is not set in .devcontainer/Dockerfile" >&2
exit 1
fi
lintbin=$targetbin/.golangci-lint-"$lintversion"$exe
if [ ! -f "$lintbin" ]; then
mkdir -p "$targetbin"
"$bindir"/scurl https://raw.githubusercontent.com/golangci/golangci-lint/v$lintversion/install.sh | sh -s -- -b . v$lintversion
"$bindir"/scurl https://raw.githubusercontent.com/golangci/golangci-lint/"$lintversion"/install.sh | sh -s -- -b . "$lintversion"
mv ./golangci-lint$exe "$lintbin"
fi