mirror of https://github.com/docker/buildx.git
hack: add gopls based linters
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
b30566438b
commit
d0cc9ed0cb
|
@ -24,6 +24,7 @@ jobs:
|
|||
matrix:
|
||||
target:
|
||||
- lint
|
||||
- lint-gopls
|
||||
- validate-vendor
|
||||
- validate-docs
|
||||
- validate-generated-files
|
||||
|
|
4
Makefile
4
Makefile
|
@ -43,6 +43,10 @@ validate-all: lint test validate-vendor validate-docs validate-generated-files
|
|||
lint:
|
||||
$(BUILDX_CMD) bake lint
|
||||
|
||||
.PHONY: lint-gopls
|
||||
lint-gopls:
|
||||
$(BUILDX_CMD) bake lint-gopls
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
./hack/test
|
||||
|
|
|
@ -28,7 +28,7 @@ group "default" {
|
|||
}
|
||||
|
||||
group "validate" {
|
||||
targets = ["lint", "validate-vendor", "validate-docs"]
|
||||
targets = ["lint", "lint-gopls", "validate-vendor", "validate-docs"]
|
||||
}
|
||||
|
||||
target "lint" {
|
||||
|
@ -48,6 +48,11 @@ target "lint" {
|
|||
] : []
|
||||
}
|
||||
|
||||
target "lint-gopls" {
|
||||
inherits = ["lint"]
|
||||
target = "gopls-analyze"
|
||||
}
|
||||
|
||||
target "validate-vendor" {
|
||||
inherits = ["_common"]
|
||||
dockerfile = "./hack/dockerfiles/vendor.Dockerfile"
|
||||
|
|
|
@ -3,11 +3,17 @@
|
|||
ARG GO_VERSION=1.21
|
||||
ARG XX_VERSION=1.3.0
|
||||
ARG GOLANGCI_LINT_VERSION=1.57.2
|
||||
ARG GOPLS_VERSION=v0.20.0
|
||||
# disabled: deprecated unusedvariable simplifyrange
|
||||
ARG GOPLS_ANALYZERS="embeddirective fillreturns infertypeargs nonewvars noresultvalues simplifycompositelit simplifyslice stubmethods undeclaredname unusedparams useany"
|
||||
|
||||
|
||||
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
|
||||
|
||||
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine
|
||||
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS golang-base
|
||||
RUN apk add --no-cache git gcc musl-dev
|
||||
|
||||
FROM golang-base AS lint
|
||||
ENV GOFLAGS="-buildvcs=false"
|
||||
ARG GOLANGCI_LINT_VERSION
|
||||
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v${GOLANGCI_LINT_VERSION}
|
||||
|
@ -18,3 +24,49 @@ RUN --mount=target=/go/src/github.com/docker/buildx \
|
|||
--mount=target=/root/.cache,type=cache,id=lint-cache-$TARGETPLATFORM \
|
||||
xx-go --wrap && \
|
||||
golangci-lint run
|
||||
|
||||
FROM golang-base AS gopls
|
||||
RUN apk add --no-cache git
|
||||
ARG GOPLS_VERSION
|
||||
WORKDIR /src
|
||||
RUN git clone https://github.com/golang/tools.git && \
|
||||
cd tools && git checkout ${GOPLS_VERSION}
|
||||
WORKDIR tools/gopls
|
||||
ARG GOPLS_ANALYZERS
|
||||
RUN <<'EOF'
|
||||
set -ex
|
||||
mkdir -p /out
|
||||
for analyzer in ${GOPLS_ANALYZERS}; do
|
||||
mkdir -p internal/cmd/$analyzer
|
||||
cat <<eot > internal/cmd/$analyzer/main.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"golang.org/x/tools/go/analysis/singlechecker"
|
||||
analyzer "golang.org/x/tools/gopls/internal/analysis/$analyzer"
|
||||
)
|
||||
|
||||
func main() { singlechecker.Main(analyzer.Analyzer) }
|
||||
eot
|
||||
echo "Analyzing with ${analyzer}..."
|
||||
go build -o /out/$analyzer ./internal/cmd/$analyzer
|
||||
done
|
||||
EOF
|
||||
|
||||
FROM golang-base AS gopls-analyze
|
||||
COPY --link --from=xx / /
|
||||
ARG GOPLS_ANALYZERS
|
||||
ARG TARGETNAME
|
||||
ARG TARGETPLATFORM
|
||||
WORKDIR /go/src/github.com/docker/buildx
|
||||
RUN --mount=target=. \
|
||||
--mount=target=/root/.cache,type=cache,id=lint-cache-${TARGETNAME}-${TARGETPLATFORM} \
|
||||
--mount=target=/gopls-analyzers,from=gopls,source=/out <<EOF
|
||||
set -ex
|
||||
xx-go --wrap
|
||||
for analyzer in ${GOPLS_ANALYZERS}; do
|
||||
go vet -vettool=/gopls-analyzers/$analyzer ./...
|
||||
done
|
||||
EOF
|
||||
|
||||
FROM lint
|
Loading…
Reference in New Issue