diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..348fedd9 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,30 @@ +run: + timeout: 10m + skip-files: + - ".*\\.pb\\.go$" + + modules-download-mode: vendor + + build-tags: + +linters: + enable: + - gofmt + - govet + - deadcode + - goimports + - ineffassign + - misspell + - unused + - varcheck + - golint + - staticcheck + - typecheck + - structcheck + disable-all: true + +issues: + exclude-rules: + - linters: + - golint + text: "stutters" diff --git a/bake/compose.go b/bake/compose.go index d79cd6a6..a9b86a52 100644 --- a/bake/compose.go +++ b/bake/compose.go @@ -56,7 +56,7 @@ func ParseCompose(dt []byte) (*Config, error) { if reflect.DeepEqual(s.Build, zeroBuildConfig) { // if not make sure they're setting an image or it's invalid d-c.yml if s.Image == "" { - return nil, fmt.Errorf("compose file invalid: service %s has neither an image nor a build context specified. At least one must be provided.", s.Name) + return nil, fmt.Errorf("compose file invalid: service %s has neither an image nor a build context specified. At least one must be provided", s.Name) } continue } diff --git a/bake/hcl.go b/bake/hcl.go index dbca9ce7..af7787a7 100644 --- a/bake/hcl.go +++ b/bake/hcl.go @@ -161,9 +161,8 @@ func parseHCL(dt []byte, fn string) (_ *Config, err error) { fnl := strings.ToLower(fn) if strings.HasSuffix(fnl, ".json") { return nil, jsondiags - } else { - return nil, hcldiags } + return nil, hcldiags } } diff --git a/bake/remote.go b/bake/remote.go index ff50a7c2..10c5d165 100644 --- a/bake/remote.go +++ b/bake/remote.go @@ -21,7 +21,7 @@ type Input struct { } func ReadRemoteFiles(ctx context.Context, dis []build.DriverInfo, url string, names []string, pw progress.Writer) ([]File, *Input, error) { - st, filename, ok := detectHttpContext(url) + st, filename, ok := detectHTTPContext(url) if !ok { st, ok = detectGitContext(url) if !ok { @@ -83,7 +83,7 @@ func ReadRemoteFiles(ctx context.Context, dis []build.DriverInfo, url string, na } func IsRemoteURL(url string) bool { - if _, _, ok := detectHttpContext(url); ok { + if _, _, ok := detectHTTPContext(url); ok { return true } if _, ok := detectGitContext(url); ok { @@ -92,7 +92,7 @@ func IsRemoteURL(url string) bool { return false } -func detectHttpContext(url string) (*llb.State, string, bool) { +func detectHTTPContext(url string) (*llb.State, string, bool) { if httpPrefix.MatchString(url) { httpContext := llb.HTTP(url, llb.Filename("context"), llb.WithCustomName("[internal] load remote build context")) return &httpContext, "context", true diff --git a/commands/build.go b/commands/build.go index 8fc68267..9a470d17 100644 --- a/commands/build.go +++ b/commands/build.go @@ -63,11 +63,14 @@ type buildOptions struct { } type commonOptions struct { - builder string - noCache *bool - progress string - pull *bool + builder string + noCache *bool + progress string + pull *bool + // golangci-lint#826 + // nolint:structcheck exportPush bool + // nolint:structcheck exportLoad bool } diff --git a/commands/diskusage.go b/commands/diskusage.go index 404a9b80..223cd93b 100644 --- a/commands/diskusage.go +++ b/commands/diskusage.go @@ -185,8 +185,6 @@ func printSummary(tw *tabwriter.Writer, dus [][]*client.UsageInfo) { } } - tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, '\t', 0) - if shared > 0 { fmt.Fprintf(tw, "Shared:\t%.2f\n", units.Bytes(shared)) fmt.Fprintf(tw, "Private:\t%.2f\n", units.Bytes(total-shared)) diff --git a/commands/imagetools/create.go b/commands/imagetools/create.go index 479cd1cc..0246d615 100644 --- a/commands/imagetools/create.go +++ b/commands/imagetools/create.go @@ -168,7 +168,7 @@ func parseSources(in []string) ([]*src, error) { for i, in := range in { s, err := parseSource(in) if err != nil { - return nil, errors.Wrapf(err, "failed to parse source %q, valid sources are digests, refereces and descriptors", in) + return nil, errors.Wrapf(err, "failed to parse source %q, valid sources are digests, references and descriptors", in) } out[i] = s } diff --git a/gometalinter.json b/gometalinter.json deleted file mode 100644 index e79b3f10..00000000 --- a/gometalinter.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "Vendor": true, - "Deadline": "8m", - "Exclude": [".*.pb.go"], - "DisableAll": true, - "Enable": [ - "gofmt", - "goimports", - "ineffassign", - "vet", - "deadcode" - ] -} diff --git a/hack/dockerfiles/lint.Dockerfile b/hack/dockerfiles/lint.Dockerfile index f76437dc..6ff56a73 100644 --- a/hack/dockerfiles/lint.Dockerfile +++ b/hack/dockerfiles/lint.Dockerfile @@ -1,12 +1,10 @@ -# syntax=docker/dockerfile:1.0-experimental +# syntax=docker/dockerfile:1.2 FROM golang:1.16-alpine -RUN apk add --no-cache git yamllint -RUN go get -u gopkg.in/alecthomas/gometalinter.v1 \ - && mv /go/bin/gometalinter.v1 /go/bin/gometalinter \ - && gometalinter --install +RUN apk add --no-cache gcc musl-dev yamllint +RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.36.0 WORKDIR /go/src/github.com/docker/buildx -RUN --mount=target=/go/src/github.com/docker/buildx \ - gometalinter --config=gometalinter.json ./... -RUN --mount=target=/go/src/github.com/docker/buildx \ - yamllint -c .yamllint.yml --strict . +RUN --mount=target=/go/src/github.com/docker/buildx --mount=target=/root/.cache,type=cache \ + golangci-lint run +RUN --mount=target=/go/src/github.com/docker/buildx --mount=target=/root/.cache,type=cache \ + yamllint -c .yamllint.yml --strict . \ No newline at end of file diff --git a/util/progress/reset.go b/util/progress/reset.go index f8ce39b6..2f275215 100644 --- a/util/progress/reset.go +++ b/util/progress/reset.go @@ -55,6 +55,6 @@ type pw struct { status chan *client.SolveStatus } -func (p *pw) Status() chan *client.SolveStatus { - return p.status +func (w *pw) Status() chan *client.SolveStatus { + return w.status }