From 66809646d94148c864ca6be883c63665fd259e12 Mon Sep 17 00:00:00 2001 From: sayboras Date: Wed, 9 Oct 2019 23:02:21 +1100 Subject: [PATCH] Migrate to golangci-lint Signed-off-by: Tam Mach --- .golangci.yml | 20 +++++++++++++++++++ .gometalinter.json | 16 --------------- Makefile | 2 +- blobs.go | 2 +- cmd/registry-api-descriptor-template/main.go | 2 +- manifest/manifestlist/manifestlist.go | 2 +- manifest/manifestlist/manifestlist_test.go | 2 +- manifest/ocischema/builder.go | 2 +- manifest/ocischema/builder_test.go | 2 +- manifest/ocischema/manifest.go | 2 +- manifest/ocischema/manifest_test.go | 2 +- notifications/bridge_test.go | 2 +- reference/reference_test.go | 2 +- registry/client/repository.go | 2 +- registry/handlers/api_test.go | 4 ++-- registry/handlers/app.go | 2 +- registry/handlers/app_test.go | 2 +- registry/handlers/blob.go | 2 +- registry/handlers/context.go | 2 +- registry/handlers/manifests.go | 4 ++-- registry/handlers/tags.go | 2 +- registry/registry.go | 3 ++- registry/storage/blob_test.go | 6 +++--- registry/storage/cache/cachecheck/suite.go | 3 +-- .../storage/driver/filesystem/driver_test.go | 2 +- .../middleware/cloudfront/middleware.go | 2 +- registry/storage/driver/s3-aws/s3.go | 2 +- registry/storage/manifeststore.go | 2 +- registry/storage/manifeststore_test.go | 2 +- registry/storage/ocimanifesthandler.go | 2 +- registry/storage/ocimanifesthandler_test.go | 2 +- registry/storage/schema2manifesthandler.go | 2 +- script/setup/install-dev-tools | 3 +-- tags.go | 4 ++-- 34 files changed, 58 insertions(+), 55 deletions(-) create mode 100644 .golangci.yml delete mode 100644 .gometalinter.json diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..1ba6cb91 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,20 @@ +linters: + enable: + - structcheck + - varcheck + - staticcheck + - unconvert + - gofmt + - goimports + - golint + - ineffassign + - vet + - unused + - misspell + disable: + - errcheck + +run: + deadline: 2m + skip-dirs: + - vendor diff --git a/.gometalinter.json b/.gometalinter.json deleted file mode 100644 index 9df5b14b..00000000 --- a/.gometalinter.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "Vendor": true, - "Deadline": "2m", - "Sort": ["linter", "severity", "path", "line"], - "EnableGC": true, - "Enable": [ - "structcheck", - "staticcheck", - "unconvert", - - "gofmt", - "goimports", - "golint", - "vet" - ] -} diff --git a/Makefile b/Makefile index fbaffa66..84aef5f4 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,7 @@ version/version.go: check: ## run all linters (TODO: enable "unused", "varcheck", "ineffassign", "unconvert", "staticheck", "goimports", "structcheck") @echo "$(WHALE) $@" - gometalinter --config .gometalinter.json ./... + @GO111MODULE=off golangci-lint run test: ## run tests, except integration test with test.short @echo "$(WHALE) $@" diff --git a/blobs.go b/blobs.go index c0e9261b..2a659eaa 100644 --- a/blobs.go +++ b/blobs.go @@ -10,7 +10,7 @@ import ( "github.com/docker/distribution/reference" "github.com/opencontainers/go-digest" - "github.com/opencontainers/image-spec/specs-go/v1" + v1 "github.com/opencontainers/image-spec/specs-go/v1" ) var ( diff --git a/cmd/registry-api-descriptor-template/main.go b/cmd/registry-api-descriptor-template/main.go index e9cbc42a..e69e6b2c 100644 --- a/cmd/registry-api-descriptor-template/main.go +++ b/cmd/registry-api-descriptor-template/main.go @@ -21,7 +21,7 @@ import ( "text/template" "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/distribution/registry/api/v2" + v2 "github.com/docker/distribution/registry/api/v2" ) var spaceRegex = regexp.MustCompile(`\n\s*`) diff --git a/manifest/manifestlist/manifestlist.go b/manifest/manifestlist/manifestlist.go index 54c8f3c9..3a1d73e8 100644 --- a/manifest/manifestlist/manifestlist.go +++ b/manifest/manifestlist/manifestlist.go @@ -8,7 +8,7 @@ import ( "github.com/docker/distribution" "github.com/docker/distribution/manifest" "github.com/opencontainers/go-digest" - "github.com/opencontainers/image-spec/specs-go/v1" + v1 "github.com/opencontainers/image-spec/specs-go/v1" ) const ( diff --git a/manifest/manifestlist/manifestlist_test.go b/manifest/manifestlist/manifestlist_test.go index e72292f0..6d0d952c 100644 --- a/manifest/manifestlist/manifestlist_test.go +++ b/manifest/manifestlist/manifestlist_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/docker/distribution" - "github.com/opencontainers/image-spec/specs-go/v1" + v1 "github.com/opencontainers/image-spec/specs-go/v1" ) var expectedManifestListSerialization = []byte(`{ diff --git a/manifest/ocischema/builder.go b/manifest/ocischema/builder.go index d90453bc..b89bf5b7 100644 --- a/manifest/ocischema/builder.go +++ b/manifest/ocischema/builder.go @@ -7,7 +7,7 @@ import ( "github.com/docker/distribution" "github.com/docker/distribution/manifest" "github.com/opencontainers/go-digest" - "github.com/opencontainers/image-spec/specs-go/v1" + v1 "github.com/opencontainers/image-spec/specs-go/v1" ) // Builder is a type for constructing manifests. diff --git a/manifest/ocischema/builder_test.go b/manifest/ocischema/builder_test.go index 8e751279..7332f3a4 100644 --- a/manifest/ocischema/builder_test.go +++ b/manifest/ocischema/builder_test.go @@ -7,7 +7,7 @@ import ( "github.com/docker/distribution" "github.com/opencontainers/go-digest" - "github.com/opencontainers/image-spec/specs-go/v1" + v1 "github.com/opencontainers/image-spec/specs-go/v1" ) type mockBlobService struct { diff --git a/manifest/ocischema/manifest.go b/manifest/ocischema/manifest.go index b8c4bab5..c5e85f28 100644 --- a/manifest/ocischema/manifest.go +++ b/manifest/ocischema/manifest.go @@ -8,7 +8,7 @@ import ( "github.com/docker/distribution" "github.com/docker/distribution/manifest" "github.com/opencontainers/go-digest" - "github.com/opencontainers/image-spec/specs-go/v1" + v1 "github.com/opencontainers/image-spec/specs-go/v1" ) var ( diff --git a/manifest/ocischema/manifest_test.go b/manifest/ocischema/manifest_test.go index c39d1c9f..b211fd09 100644 --- a/manifest/ocischema/manifest_test.go +++ b/manifest/ocischema/manifest_test.go @@ -8,7 +8,7 @@ import ( "github.com/docker/distribution" "github.com/docker/distribution/manifest" - "github.com/opencontainers/image-spec/specs-go/v1" + v1 "github.com/opencontainers/image-spec/specs-go/v1" ) var expectedManifestSerialization = []byte(`{ diff --git a/notifications/bridge_test.go b/notifications/bridge_test.go index b97bb4c5..7fab4271 100644 --- a/notifications/bridge_test.go +++ b/notifications/bridge_test.go @@ -6,7 +6,7 @@ import ( "github.com/docker/distribution" "github.com/docker/distribution/manifest/schema1" "github.com/docker/distribution/reference" - "github.com/docker/distribution/registry/api/v2" + v2 "github.com/docker/distribution/registry/api/v2" "github.com/docker/distribution/uuid" "github.com/docker/libtrust" "github.com/opencontainers/go-digest" diff --git a/reference/reference_test.go b/reference/reference_test.go index 16b871f9..e077aa16 100644 --- a/reference/reference_test.go +++ b/reference/reference_test.go @@ -639,7 +639,7 @@ func TestParseNamed(t *testing.T) { failf("error parsing name: %s", err) continue } else if err == nil && testcase.err != nil { - failf("parsing succeded: expected error %v", testcase.err) + failf("parsing succeeded: expected error %v", testcase.err) continue } else if err != testcase.err { failf("unexpected error %v, expected %v", err, testcase.err) diff --git a/registry/client/repository.go b/registry/client/repository.go index c88e335c..793a662d 100644 --- a/registry/client/repository.go +++ b/registry/client/repository.go @@ -16,7 +16,7 @@ import ( "github.com/docker/distribution" "github.com/docker/distribution/reference" - "github.com/docker/distribution/registry/api/v2" + v2 "github.com/docker/distribution/registry/api/v2" "github.com/docker/distribution/registry/client/transport" "github.com/docker/distribution/registry/storage/cache" "github.com/docker/distribution/registry/storage/cache/memory" diff --git a/registry/handlers/api_test.go b/registry/handlers/api_test.go index e0a9e746..66aa06d6 100644 --- a/registry/handlers/api_test.go +++ b/registry/handlers/api_test.go @@ -28,7 +28,7 @@ import ( "github.com/docker/distribution/manifest/schema2" "github.com/docker/distribution/reference" "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/distribution/registry/api/v2" + v2 "github.com/docker/distribution/registry/api/v2" storagedriver "github.com/docker/distribution/registry/storage/driver" "github.com/docker/distribution/registry/storage/driver/factory" _ "github.com/docker/distribution/registry/storage/driver/testdriver" @@ -2355,7 +2355,7 @@ func checkBodyHasErrorCodes(t *testing.T, msg string, resp *http.Response, error // Ensure that counts of expected errors were all non-zero for code := range expected { if counts[code] == 0 { - t.Fatalf("expected error code %v not encounterd during %s: %s", code, msg, string(p)) + t.Fatalf("expected error code %v not encountered during %s: %s", code, msg, string(p)) } } diff --git a/registry/handlers/app.go b/registry/handlers/app.go index f879eaee..3ab507d2 100644 --- a/registry/handlers/app.go +++ b/registry/handlers/app.go @@ -24,7 +24,7 @@ import ( "github.com/docker/distribution/notifications" "github.com/docker/distribution/reference" "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/distribution/registry/api/v2" + v2 "github.com/docker/distribution/registry/api/v2" "github.com/docker/distribution/registry/auth" registrymiddleware "github.com/docker/distribution/registry/middleware/registry" repositorymiddleware "github.com/docker/distribution/registry/middleware/repository" diff --git a/registry/handlers/app_test.go b/registry/handlers/app_test.go index f95b441f..1135740d 100644 --- a/registry/handlers/app_test.go +++ b/registry/handlers/app_test.go @@ -11,7 +11,7 @@ import ( "github.com/docker/distribution/configuration" "github.com/docker/distribution/context" "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/distribution/registry/api/v2" + v2 "github.com/docker/distribution/registry/api/v2" "github.com/docker/distribution/registry/auth" _ "github.com/docker/distribution/registry/auth/silly" "github.com/docker/distribution/registry/storage" diff --git a/registry/handlers/blob.go b/registry/handlers/blob.go index 5c31cc76..515fdad0 100644 --- a/registry/handlers/blob.go +++ b/registry/handlers/blob.go @@ -6,7 +6,7 @@ import ( "github.com/docker/distribution" "github.com/docker/distribution/context" "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/distribution/registry/api/v2" + v2 "github.com/docker/distribution/registry/api/v2" "github.com/gorilla/handlers" "github.com/opencontainers/go-digest" ) diff --git a/registry/handlers/context.go b/registry/handlers/context.go index 7a67b604..b1b7a13d 100644 --- a/registry/handlers/context.go +++ b/registry/handlers/context.go @@ -8,7 +8,7 @@ import ( "github.com/docker/distribution" dcontext "github.com/docker/distribution/context" "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/distribution/registry/api/v2" + v2 "github.com/docker/distribution/registry/api/v2" "github.com/docker/distribution/registry/auth" "github.com/opencontainers/go-digest" ) diff --git a/registry/handlers/manifests.go b/registry/handlers/manifests.go index 6f2f5178..e71fe2c3 100644 --- a/registry/handlers/manifests.go +++ b/registry/handlers/manifests.go @@ -15,11 +15,11 @@ import ( "github.com/docker/distribution/manifest/schema2" "github.com/docker/distribution/reference" "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/distribution/registry/api/v2" + v2 "github.com/docker/distribution/registry/api/v2" "github.com/docker/distribution/registry/auth" "github.com/gorilla/handlers" "github.com/opencontainers/go-digest" - "github.com/opencontainers/image-spec/specs-go/v1" + v1 "github.com/opencontainers/image-spec/specs-go/v1" ) // These constants determine which architecture and OS to choose from a diff --git a/registry/handlers/tags.go b/registry/handlers/tags.go index ea6ecc4a..1e90642d 100644 --- a/registry/handlers/tags.go +++ b/registry/handlers/tags.go @@ -6,7 +6,7 @@ import ( "github.com/docker/distribution" "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/distribution/registry/api/v2" + v2 "github.com/docker/distribution/registry/api/v2" "github.com/gorilla/handlers" ) diff --git a/registry/registry.go b/registry/registry.go index e4fe36cb..20190c11 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -12,7 +12,8 @@ import ( "syscall" "time" - "github.com/Shopify/logrus-bugsnag" + logrus_bugsnag "github.com/Shopify/logrus-bugsnag" + logstash "github.com/bshuster-repo/logrus-logstash-hook" "github.com/bugsnag/bugsnag-go" "github.com/docker/go-metrics" diff --git a/registry/storage/blob_test.go b/registry/storage/blob_test.go index cce232a7..f5c1416d 100644 --- a/registry/storage/blob_test.go +++ b/registry/storage/blob_test.go @@ -418,7 +418,7 @@ func TestBlobMount(t *testing.T) { bs := repository.Blobs(ctx) // Test destination for existence. - statDesc, err = bs.Stat(ctx, desc.Digest) + _, err = bs.Stat(ctx, desc.Digest) if err == nil { t.Fatalf("unexpected non-error stating unmounted blob: %v", desc) } @@ -478,12 +478,12 @@ func TestBlobMount(t *testing.T) { t.Fatalf("Unexpected error deleting blob") } - d, err := bs.Stat(ctx, desc.Digest) + _, err = bs.Stat(ctx, desc.Digest) if err != nil { t.Fatalf("unexpected error stating blob deleted from source repository: %v", err) } - d, err = sbs.Stat(ctx, desc.Digest) + d, err := sbs.Stat(ctx, desc.Digest) if err == nil { t.Fatalf("unexpected non-error stating deleted blob: %v", d) } diff --git a/registry/storage/cache/cachecheck/suite.go b/registry/storage/cache/cachecheck/suite.go index 0b8b1e9e..d241bd04 100644 --- a/registry/storage/cache/cachecheck/suite.go +++ b/registry/storage/cache/cachecheck/suite.go @@ -173,8 +173,7 @@ func checkBlobDescriptorCacheClear(ctx context.Context, t *testing.T, provider c t.Error(err) } - desc, err = cache.Stat(ctx, localDigest) - if err == nil { + if _, err = cache.Stat(ctx, localDigest); err == nil { t.Fatalf("expected error statting deleted blob: %v", err) } } diff --git a/registry/storage/driver/filesystem/driver_test.go b/registry/storage/driver/filesystem/driver_test.go index 3be85923..2bf5b2d1 100644 --- a/registry/storage/driver/filesystem/driver_test.go +++ b/registry/storage/driver/filesystem/driver_test.go @@ -36,7 +36,7 @@ func init() { func TestFromParametersImpl(t *testing.T) { tests := []struct { - params map[string]interface{} // techincally the yaml can contain anything + params map[string]interface{} // technically the yaml can contain anything expected DriverParameters pass bool }{ diff --git a/registry/storage/driver/middleware/cloudfront/middleware.go b/registry/storage/driver/middleware/cloudfront/middleware.go index bd9031a9..ab3b2ca4 100644 --- a/registry/storage/driver/middleware/cloudfront/middleware.go +++ b/registry/storage/driver/middleware/cloudfront/middleware.go @@ -16,7 +16,7 @@ import ( "github.com/aws/aws-sdk-go/service/cloudfront/sign" dcontext "github.com/docker/distribution/context" storagedriver "github.com/docker/distribution/registry/storage/driver" - "github.com/docker/distribution/registry/storage/driver/middleware" + storagemiddleware "github.com/docker/distribution/registry/storage/driver/middleware" ) // cloudFrontStorageMiddleware provides a simple implementation of layerHandler that diff --git a/registry/storage/driver/s3-aws/s3.go b/registry/storage/driver/s3-aws/s3.go index 4b6c50d7..d9c1a826 100644 --- a/registry/storage/driver/s3-aws/s3.go +++ b/registry/storage/driver/s3-aws/s3.go @@ -366,7 +366,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { return New(params) } -// getParameterAsInt64 converts paramaters[name] to an int64 value (using +// getParameterAsInt64 converts parameters[name] to an int64 value (using // defaultt if nil), verifies it is no smaller than min, and returns it. func getParameterAsInt64(parameters map[string]interface{}, name string, defaultt int64, min int64, max int64) (int64, error) { rv := defaultt diff --git a/registry/storage/manifeststore.go b/registry/storage/manifeststore.go index 73bff573..7daa9a72 100644 --- a/registry/storage/manifeststore.go +++ b/registry/storage/manifeststore.go @@ -13,7 +13,7 @@ import ( "github.com/docker/distribution/manifest/schema1" "github.com/docker/distribution/manifest/schema2" "github.com/opencontainers/go-digest" - "github.com/opencontainers/image-spec/specs-go/v1" + v1 "github.com/opencontainers/image-spec/specs-go/v1" ) // A ManifestHandler gets and puts manifests of a particular type. diff --git a/registry/storage/manifeststore_test.go b/registry/storage/manifeststore_test.go index cfe18c12..54b58ae1 100644 --- a/registry/storage/manifeststore_test.go +++ b/registry/storage/manifeststore_test.go @@ -19,7 +19,7 @@ import ( "github.com/docker/distribution/testutil" "github.com/docker/libtrust" "github.com/opencontainers/go-digest" - "github.com/opencontainers/image-spec/specs-go/v1" + v1 "github.com/opencontainers/image-spec/specs-go/v1" ) type manifestStoreTestEnv struct { diff --git a/registry/storage/ocimanifesthandler.go b/registry/storage/ocimanifesthandler.go index 91a037a0..e06ecb11 100644 --- a/registry/storage/ocimanifesthandler.go +++ b/registry/storage/ocimanifesthandler.go @@ -9,7 +9,7 @@ import ( dcontext "github.com/docker/distribution/context" "github.com/docker/distribution/manifest/ocischema" "github.com/opencontainers/go-digest" - "github.com/opencontainers/image-spec/specs-go/v1" + v1 "github.com/opencontainers/image-spec/specs-go/v1" ) //ocischemaManifestHandler is a ManifestHandler that covers ocischema manifests. diff --git a/registry/storage/ocimanifesthandler_test.go b/registry/storage/ocimanifesthandler_test.go index 3983a9f7..ed019efd 100644 --- a/registry/storage/ocimanifesthandler_test.go +++ b/registry/storage/ocimanifesthandler_test.go @@ -9,7 +9,7 @@ import ( "github.com/docker/distribution/manifest" "github.com/docker/distribution/manifest/ocischema" "github.com/docker/distribution/registry/storage/driver/inmemory" - "github.com/opencontainers/image-spec/specs-go/v1" + v1 "github.com/opencontainers/image-spec/specs-go/v1" ) func TestVerifyOCIManifestNonDistributableLayer(t *testing.T) { diff --git a/registry/storage/schema2manifesthandler.go b/registry/storage/schema2manifesthandler.go index 25d9d84f..3e32e9f4 100644 --- a/registry/storage/schema2manifesthandler.go +++ b/registry/storage/schema2manifesthandler.go @@ -92,7 +92,7 @@ func (ms *schema2ManifestHandler) verifyManifest(ctx context.Context, mnfst sche switch descriptor.MediaType { case schema2.MediaTypeForeignLayer: // Clients download this layer from an external URL, so do not check for - // its presense. + // its presence. if len(descriptor.URLs) == 0 { err = errMissingURL } diff --git a/script/setup/install-dev-tools b/script/setup/install-dev-tools index e7f82d16..1695621a 100755 --- a/script/setup/install-dev-tools +++ b/script/setup/install-dev-tools @@ -5,6 +5,5 @@ # set -eu -o pipefail -go get -u github.com/alecthomas/gometalinter -gometalinter --install >/dev/null +go get -u github.com/golangci/golangci-lint/cmd/golangci-lint go get -u github.com/cpuguy83/go-md2man diff --git a/tags.go b/tags.go index f0e0bea3..6033575c 100644 --- a/tags.go +++ b/tags.go @@ -3,7 +3,7 @@ package distribution import ( "context" - digest "github.com/opencontainers/go-digest" + "github.com/opencontainers/go-digest" ) // TagService provides access to information about tagged objects. @@ -28,7 +28,7 @@ type TagService interface { Lookup(ctx context.Context, digest Descriptor) ([]string, error) } -// TagManifestsProvider provides method to retreive the digests of manifests that a tag historically +// TagManifestsProvider provides method to retrieve the digests of manifests that a tag historically // pointed to type TagManifestsProvider interface { // ManifestDigests returns set of digests that this tag historically pointed to. This also