From 7374c0a15296142f6495dd989ddca4324c645695 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 17:27:12 +0200 Subject: [PATCH] Remove now obsolete gometalinter and use golangci-lint instead Signed-off-by: Silvin Lubecki Signed-off-by: Sebastiaan van Stijn (cherry picked from commit b7e06f2845bb4996269a49f2592a735e4cd03e49) Signed-off-by: Sebastiaan van Stijn --- .golangci.yml | 83 +++++++++++++++++++++++++++++++++++++ dockerfiles/Dockerfile.lint | 31 +++++++------- gometalinter.json | 46 -------------------- 3 files changed, 100 insertions(+), 60 deletions(-) create mode 100644 .golangci.yml delete mode 100644 gometalinter.json diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000000..c3add27d17 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,83 @@ +linters: + enable: + - bodyclose + - deadcode + - dogsled + - gocyclo + - goimports + - golint + - gosec + - gosimple + - govet + - ineffassign + - interfacer + - lll + - megacheck + - misspell + - nakedret + - staticcheck + - structcheck + - typecheck + - unconvert + - unparam + - unused + - varcheck + + disable: + - errcheck + +run: + timeout: 5m + skip-dirs: + - cli/command/stack/kubernetes/api/openapi + - cli/command/stack/kubernetes/api/client + skip-files: + - cli/compose/schema/bindata.go + - .*generated.* + +linters-settings: + gocyclo: + min-complexity: 16 + govet: + check-shadowing: false + lll: + line-length: 200 + nakedret: + command: nakedret + pattern: ^(?P.*?\\.go):(?P\\d+)\\s*(?P.*)$ + +issues: + # The default exclusion rules are a bit too permissive, so copying the relevant ones below + exclude-use-default: false + + exclude: + - parameter .* always receives + + exclude-rules: + # These are copied from the default exclude rules, except for "ineffective break statement" + # and GoDoc checks. + # https://github.com/golangci/golangci-lint/blob/0cc87df732aaf1d5ad9ce9ca538d38d916918b36/pkg/config/config.go#L36 + - text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked" + linters: + - errcheck + - text: "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this" + linters: + - golint + - text: "G103: Use of unsafe calls should be audited" + linters: + - gosec + - text: "G104: Errors unhandled" + linters: + - gosec + - text: "G204: Subprocess launch(ed with (variable|function call)|ing should be audited)" + linters: + - gosec + - text: "(G301|G302): (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)" + linters: + - gosec + - text: "G304: Potential file inclusion via variable" + linters: + - gosec + - text: "(G201|G202): SQL string (formatting|concatenation)" + linters: + - gosec diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 1d30d87b3f..be30abec28 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -1,20 +1,23 @@ +# syntax=docker/dockerfile:1.1.3-experimental + ARG GO_VERSION=1.12.12 +ARG GOLANGCI_LINTER_SHA="v1.21.0" -FROM golang:${GO_VERSION}-alpine +FROM golang:${GO_VERSION}-alpine AS build +ENV CGO_ENABLED=0 +RUN apk add --no-cache git +ARG GOLANGCI_LINTER_SHA +ARG GO111MODULE=on +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + go get github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINTER_SHA} -RUN apk add -U git - -ARG GOMETALINTER_SHA=v2.0.6 -RUN go get -d github.com/alecthomas/gometalinter && \ - cd /go/src/github.com/alecthomas/gometalinter && \ - git checkout -q "$GOMETALINTER_SHA" && \ - go build -v -o /usr/local/bin/gometalinter . && \ - gometalinter --install && \ - rm -rf /go/src/* /go/pkg/* - -WORKDIR /go/src/github.com/docker/cli +FROM golang:${GO_VERSION}-alpine AS lint ENV CGO_ENABLED=0 ENV DISABLE_WARN_OUTSIDE_CONTAINER=1 -ENTRYPOINT ["/usr/local/bin/gometalinter"] -CMD ["--config=gometalinter.json", "./..."] +COPY --from=build /go/bin/golangci-lint /usr/local/bin +WORKDIR /go/src/github.com/docker/cli +ENV GOGC=75 +ENTRYPOINT ["/usr/local/bin/golangci-lint"] +CMD ["run", "--config=.golangci.yml"] COPY . . diff --git a/gometalinter.json b/gometalinter.json deleted file mode 100644 index f2b2e8545d..0000000000 --- a/gometalinter.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "Vendor": true, - "Deadline": "3m", - "Sort": ["linter", "severity", "path", "line"], - "Skip": [ - "cli/compose/schema/bindata.go", - "cli/command/stack/kubernetes/api/openapi", - "cli/command/stack/kubernetes/api/client", - ".*generated.*", - "vendor" - ], - "Exclude": [ - "parameter .* always receives", - "_esc(Dir|FS|FSString|FSMustString) is unused" - ], - "EnableGC": true, - "Linters": { - "nakedret": { - "Command": "nakedret", - "Pattern": "^(?P.*?\\.go):(?P\\d+)\\s*(?P.*)$" - } - }, - "WarnUnmatchedDirective": true, - - "DisableAll": true, - "Enable": [ - "deadcode", - "gocyclo", - "gofmt", - "goimports", - "golint", - "gosimple", - "ineffassign", - "interfacer", - "lll", - "misspell", - "nakedret", - "unconvert", - "unparam", - "unused", - "vet" - ], - - "Cyclo": 16, - "LineLength": 200 -}