diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml index 631bcd7d..6e278a56 100644 --- a/.github/workflows/golangci-lint.yaml +++ b/.github/workflows/golangci-lint.yaml @@ -24,7 +24,7 @@ jobs: uses: golangci/golangci-lint-action@v3 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.52.2 + version: v1.54.2 # Optional: working directory, useful for monorepos # working-directory: somedir diff --git a/Makefile b/Makefile index bac013ab..c0e51a9a 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ TOOLSDIR := $(shell pwd)/hack/tools PATH := bin:$(TOOLSDIR)/bin:$(PATH) STACKER := $(shell which stacker) GOLINTER := $(TOOLSDIR)/bin/golangci-lint -GOLINTER_VERSION := v1.52.2 +GOLINTER_VERSION := v1.54.2 NOTATION := $(TOOLSDIR)/bin/notation NOTATION_VERSION := 1.0.0 COSIGN := $(TOOLSDIR)/bin/cosign diff --git a/golangcilint.yaml b/golangcilint.yaml index 862c6318..c8ff69cf 100644 --- a/golangcilint.yaml +++ b/golangcilint.yaml @@ -5,7 +5,7 @@ run: linters: enable-all: true - disable: funlen,gocognit,exhaustivestruct,paralleltest,forbidigo,ireturn,wrapcheck,exhaustive,maintidx,exhaustruct,nosnakecase,interfacer,structcheck,varcheck,deadcode,ifshort,golint,scopelint,maligned,rowserrcheck,sqlclosecheck,revive,musttag + disable: funlen,gocognit,exhaustivestruct,paralleltest,forbidigo,ireturn,wrapcheck,exhaustive,maintidx,exhaustruct,nosnakecase,interfacer,structcheck,varcheck,deadcode,ifshort,golint,scopelint,maligned,rowserrcheck,sqlclosecheck,revive,musttag,depguard linters-settings: dupl: diff --git a/pkg/api/controller.go b/pkg/api/controller.go index aa362229..e958048d 100644 --- a/pkg/api/controller.go +++ b/pkg/api/controller.go @@ -71,7 +71,7 @@ func NewController(config *config.Config) *Controller { func DumpRuntimeParams(log log.Logger) { var rLimit syscall.Rlimit - evt := log.Info().Int("cpus", runtime.NumCPU()) + evt := log.Info().Int("cpus", runtime.NumCPU()) //nolint: zerologlint err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit) if err == nil { diff --git a/pkg/api/routes.go b/pkg/api/routes.go index 9272da45..ec93ffdc 100644 --- a/pkg/api/routes.go +++ b/pkg/api/routes.go @@ -2111,6 +2111,7 @@ func (rh *RouteHandler) CreateAPIKey(resp http.ResponseWriter, req *http.Request expirationDate := time.Time{} if payload.ExpirationDate != "" { + //nolint: gosmopolitan expirationDate, err = time.ParseInLocation(constants.APIKeyTimeFormat, payload.ExpirationDate, time.Local) if err != nil { resp.WriteHeader(http.StatusBadRequest) diff --git a/pkg/api/routes_test.go b/pkg/api/routes_test.go index 554aff19..4d050dd3 100644 --- a/pkg/api/routes_test.go +++ b/pkg/api/routes_test.go @@ -546,7 +546,7 @@ func TestRoutes(t *testing.T) { }, &mocks.MockedImageStore{ GetBlobFn: func(repo string, digest godigest.Digest, mediaType string) (io.ReadCloser, int64, error) { - return io.NopCloser(bytes.NewBuffer([]byte(""))), 0, zerr.ErrRepoNotFound + return io.NopCloser(bytes.NewBufferString("")), 0, zerr.ErrRepoNotFound }, }) So(statusCode, ShouldEqual, http.StatusNotFound) @@ -559,7 +559,7 @@ func TestRoutes(t *testing.T) { }, &mocks.MockedImageStore{ GetBlobFn: func(repo string, digest godigest.Digest, mediaType string) (io.ReadCloser, int64, error) { - return io.NopCloser(bytes.NewBuffer([]byte(""))), 0, zerr.ErrBadBlobDigest + return io.NopCloser(bytes.NewBufferString("")), 0, zerr.ErrBadBlobDigest }, }) So(statusCode, ShouldEqual, http.StatusBadRequest) diff --git a/pkg/cli/client/search_functions_internal_test.go b/pkg/cli/client/search_functions_internal_test.go index 582665e5..f8880e7e 100644 --- a/pkg/cli/client/search_functions_internal_test.go +++ b/pkg/cli/client/search_functions_internal_test.go @@ -654,7 +654,7 @@ func getMockImageSummary() common.ImageSummary { func TestUtils(t *testing.T) { Convey("Utils", t, func() { ok := haveSameArgs(field{"query", []struct { - Name string "json:\"name\"" + Name string `json:"name"` }{ {Name: "arg1"}, {Name: "arg2"}, }}, GQLQuery{ @@ -663,7 +663,7 @@ func TestUtils(t *testing.T) { So(ok, ShouldBeFalse) ok = haveSameArgs(field{"query", []struct { - Name string "json:\"name\"" + Name string `json:"name"` }{ {Name: "arg1"}, {Name: "arg2"}, }}, GQLQuery{ diff --git a/pkg/cli/server/config_reloader_test.go b/pkg/cli/server/config_reloader_test.go index f22781f1..eb8fdcf7 100644 --- a/pkg/cli/server/config_reloader_test.go +++ b/pkg/cli/server/config_reloader_test.go @@ -88,7 +88,7 @@ func TestConfigReloader(t *testing.T) { defer os.Remove(cfgfile.Name()) // clean up - _, err = cfgfile.Write([]byte(content)) + _, err = cfgfile.WriteString(content) So(err, ShouldBeNil) // err = cfgfile.Close() @@ -216,7 +216,7 @@ func TestConfigReloader(t *testing.T) { defer os.Remove(cfgfile.Name()) // clean up - _, err = cfgfile.Write([]byte(content)) + _, err = cfgfile.WriteString(content) So(err, ShouldBeNil) // err = cfgfile.Close() @@ -341,7 +341,7 @@ func TestConfigReloader(t *testing.T) { defer os.Remove(cfgfile.Name()) // clean up - _, err = cfgfile.Write([]byte(content)) + _, err = cfgfile.WriteString(content) So(err, ShouldBeNil) os.Args = []string{"cli_test", "serve", cfgfile.Name()} @@ -463,7 +463,7 @@ func TestConfigReloader(t *testing.T) { defer os.Remove(cfgfile.Name()) // clean up - _, err = cfgfile.Write([]byte(content)) + _, err = cfgfile.WriteString(content) So(err, ShouldBeNil) // err = cfgfile.Close() diff --git a/pkg/cli/server/extensions_test.go b/pkg/cli/server/extensions_test.go index bf2c6a61..c27c9948 100644 --- a/pkg/cli/server/extensions_test.go +++ b/pkg/cli/server/extensions_test.go @@ -392,7 +392,7 @@ func TestServeExtensions(t *testing.T) { cfgfile, err := os.CreateTemp("", "zot-test*.json") So(err, ShouldBeNil) defer os.Remove(cfgfile.Name()) // clean up - _, err = cfgfile.Write([]byte(content)) + _, err = cfgfile.WriteString(content) So(err, ShouldBeNil) err = cfgfile.Close() So(err, ShouldBeNil) @@ -435,7 +435,7 @@ func TestServeExtensions(t *testing.T) { cfgfile, err := os.CreateTemp("", "zot-test*.json") So(err, ShouldBeNil) defer os.Remove(cfgfile.Name()) // clean up - _, err = cfgfile.Write([]byte(content)) + _, err = cfgfile.WriteString(content) So(err, ShouldBeNil) err = cfgfile.Close() So(err, ShouldBeNil) @@ -467,7 +467,7 @@ func testWithMetricsEnabled(cfgContentFormat string) { So(err, ShouldBeNil) defer os.Remove(cfgfile.Name()) // clean up - _, err = cfgfile.Write([]byte(content)) + _, err = cfgfile.WriteString(content) So(err, ShouldBeNil) err = cfgfile.Close() So(err, ShouldBeNil) @@ -595,7 +595,7 @@ func TestServeMetricsExtension(t *testing.T) { cfgfile, err := os.CreateTemp("", "zot-test*.json") So(err, ShouldBeNil) defer os.Remove(cfgfile.Name()) // clean up - _, err = cfgfile.Write([]byte(content)) + _, err = cfgfile.WriteString(content) So(err, ShouldBeNil) err = cfgfile.Close() So(err, ShouldBeNil) diff --git a/pkg/cli/server/root_test.go b/pkg/cli/server/root_test.go index 390e4bfb..c97c0277 100644 --- a/pkg/cli/server/root_test.go +++ b/pkg/cli/server/root_test.go @@ -1376,7 +1376,7 @@ func runCLIWithConfig(tempDir string, config string) (string, error) { config = fmt.Sprintf(config, tempDir, port, logFile.Name()) - _, err = cfgfile.Write([]byte(config)) + _, err = cfgfile.WriteString(config) if err != nil { return "", err } diff --git a/pkg/cli/server/stress_test.go b/pkg/cli/server/stress_test.go index a12113ca..28fe8d3f 100644 --- a/pkg/cli/server/stress_test.go +++ b/pkg/cli/server/stress_test.go @@ -95,7 +95,7 @@ func TestSressTooManyOpenFiles(t *testing.T) { cfgfile, err := os.CreateTemp("", "zot-test*.json") So(err, ShouldBeNil) defer os.Remove(cfgfile.Name()) // clean up - _, err = cfgfile.Write([]byte(content)) + _, err = cfgfile.WriteString(content) So(err, ShouldBeNil) err = cfgfile.Close() So(err, ShouldBeNil) diff --git a/pkg/debug/gqlplayground/gqlplayground.go b/pkg/debug/gqlplayground/gqlplayground.go index 16e69680..e6425252 100644 --- a/pkg/debug/gqlplayground/gqlplayground.go +++ b/pkg/debug/gqlplayground/gqlplayground.go @@ -27,7 +27,7 @@ func SetupGQLPlaygroundRoutes(router *mux.Router, templ, err := template.ParseFS(playgroundHTML, "index.html.tmpl") if err != nil { - log.Fatal().Err(err) + log.Fatal().Err(err).Msg("") } //nolint:lll diff --git a/pkg/extensions/extension_mgmt.go b/pkg/extensions/extension_mgmt.go index 0e41e429..e86cdc21 100644 --- a/pkg/extensions/extension_mgmt.go +++ b/pkg/extensions/extension_mgmt.go @@ -34,16 +34,16 @@ type OpenIDConfig struct { type Auth struct { HTPasswd *HTPasswd `json:"htpasswd,omitempty" mapstructure:"htpasswd"` - Bearer *BearerConfig `json:"bearer,omitempty" mapstructure:"bearer"` + Bearer *BearerConfig `json:"bearer,omitempty" mapstructure:"bearer"` LDAP *struct { Address string `json:"address,omitempty" mapstructure:"address"` - } `json:"ldap,omitempty" mapstructure:"ldap"` + } `json:"ldap,omitempty" mapstructure:"ldap"` OpenID *OpenIDConfig `json:"openid,omitempty" mapstructure:"openid"` } type StrippedConfig struct { DistSpecVersion string `json:"distSpecVersion" mapstructure:"distSpecVersion"` - BinaryType string `json:"binaryType" mapstructure:"binaryType"` + BinaryType string `json:"binaryType" mapstructure:"binaryType"` HTTP struct { Auth *Auth `json:"auth,omitempty" mapstructure:"auth"` } `json:"http" mapstructure:"http"` diff --git a/pkg/extensions/sync/sync_test.go b/pkg/extensions/sync/sync_test.go index 52b5dcd7..b0519c55 100644 --- a/pkg/extensions/sync/sync_test.go +++ b/pkg/extensions/sync/sync_test.go @@ -1898,7 +1898,7 @@ func TestConfigReloader(t *testing.T) { defer os.Remove(cfgfile.Name()) // clean up - _, err = cfgfile.Write([]byte(content)) + _, err = cfgfile.WriteString(content) So(err, ShouldBeNil) hotReloader, err := cli.NewHotReloader(dctlr, cfgfile.Name()) @@ -2046,7 +2046,7 @@ func TestConfigReloader(t *testing.T) { defer os.Remove(cfgfile.Name()) // clean up - _, err = cfgfile.Write([]byte(content)) + _, err = cfgfile.WriteString(content) So(err, ShouldBeNil) hotReloader, err := cli.NewHotReloader(dctlr, cfgfile.Name()) diff --git a/pkg/storage/cache/boltdb.go b/pkg/storage/cache/boltdb.go index f146e0dd..7a816361 100644 --- a/pkg/storage/cache/boltdb.go +++ b/pkg/storage/cache/boltdb.go @@ -177,7 +177,7 @@ func (d *BoltDBDriver) GetBlob(digest godigest.Digest) (string, error) { bucket := root.Bucket([]byte(digest.String())) if bucket != nil { origin := bucket.Bucket([]byte(constants.OriginalBucket)) - blobPath.WriteString(string(d.getOne(origin))) + blobPath.Write(d.getOne(origin)) return nil } diff --git a/pkg/storage/local/driver.go b/pkg/storage/local/driver.go index faef6588..bcc46c12 100644 --- a/pkg/storage/local/driver.go +++ b/pkg/storage/local/driver.go @@ -293,7 +293,7 @@ func (driver *Driver) Link(src, dest string) error { /* also update the modtime, so that gc won't remove recently linked blobs otherwise ifBlobOlderThan(gcDelay) will return the modtime of the inode */ - currentTime := time.Now().Local() + currentTime := time.Now().Local() //nolint: gosmopolitan if err := os.Chtimes(dest, currentTime, currentTime); err != nil { return driver.formatErr(err) } diff --git a/pkg/storage/local/local_test.go b/pkg/storage/local/local_test.go index 571475be..5ee8c301 100644 --- a/pkg/storage/local/local_test.go +++ b/pkg/storage/local/local_test.go @@ -303,7 +303,7 @@ func FuzzPutBlobChunk(f *testing.F) { t.Error(err) } - buf := bytes.NewBuffer([]byte(data)) + buf := bytes.NewBufferString(data) buflen := buf.Len() _, err = imgStore.PutBlobChunk(repoName, uuid, 0, int64(buflen), buf) if err != nil { @@ -337,7 +337,7 @@ func FuzzPutBlobChunkStreamed(f *testing.F) { t.Error(err) } - buf := bytes.NewBuffer([]byte(data)) + buf := bytes.NewBufferString(data) _, err = imgStore.PutBlobChunkStreamed(repoName, uuid, buf) if err != nil { t.Error(err) @@ -1073,7 +1073,7 @@ func FuzzGetOrasReferrers(f *testing.F) { t.Error(err) } digest := godigest.FromBytes([]byte(data)) - buf := bytes.NewBuffer([]byte(data)) + buf := bytes.NewBufferString(data) buflen := buf.Len() err = os.WriteFile(path.Join(imgStore.RootDir(), //nolint: gosec "zot-test", "blobs", digest.Algorithm().String(), digest.Encoded()), diff --git a/pkg/storage/s3/s3_test.go b/pkg/storage/s3/s3_test.go index a96486dd..381e5098 100644 --- a/pkg/storage/s3/s3_test.go +++ b/pkg/storage/s3/s3_test.go @@ -870,7 +870,7 @@ func TestNegativeCasesObjectsStorage(t *testing.T) { _, _, err = imgStore.PutImageManifest(testImage, "1.0", "application/json", []byte{}) So(err, ShouldNotBeNil) - _, err = imgStore.PutBlobChunkStreamed(testImage, upload, bytes.NewBuffer([]byte(testImage))) + _, err = imgStore.PutBlobChunkStreamed(testImage, upload, bytes.NewBufferString(testImage)) So(err, ShouldNotBeNil) _, _, err = imgStore.FullBlobUpload(testImage, bytes.NewBuffer([]byte{}), "inexistent") @@ -3848,7 +3848,7 @@ func TestS3DedupeErr(t *testing.T) { Convey("Test DeleteBlob() - error on store.Move()", t, func(c C) { tdir := t.TempDir() - hash := "7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc" + hash := "7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc" // #nosec G101 digest := godigest.NewDigestFromEncoded(godigest.SHA256, hash) diff --git a/pkg/test/common/fs_test.go b/pkg/test/common/fs_test.go index 01a0e4fe..5165cf01 100644 --- a/pkg/test/common/fs_test.go +++ b/pkg/test/common/fs_test.go @@ -148,7 +148,7 @@ func TestReadLogFileAndCountStringOccurence(t *testing.T) { panic(err) } - _, err = logFile.Write([]byte("line1\n line2\n line3 line1 line2\n line1")) + _, err = logFile.WriteString("line1\n line2\n line3 line1 line2\n line1") if err != nil { panic(err) }