From 362333b96b45bc044abd773a88c6c7a3c42c83f3 Mon Sep 17 00:00:00 2001 From: Bruno Michel Date: Tue, 10 Sep 2024 09:27:16 +0200 Subject: [PATCH] Update golangci-lint to v1.61.0 (#454) --- Makefile | 4 ++-- cmd/token.go | 3 +-- config/logger.go | 3 +-- export/export.go | 3 +-- export/import.go | 3 +-- registry/registry.go | 11 +++++------ registry/registry_test.go | 14 +++++++------- registry/virtual.go | 3 +-- storage/fs.go | 3 +-- storage/storage_test.go | 3 +-- web/router.go | 4 ++-- web/web_test.go | 10 +++++----- 12 files changed, 28 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 0d90a4e0..9c85036c 100644 --- a/Makefile +++ b/Makefile @@ -26,11 +26,11 @@ sessionsecret.key: ## lint: enforce a consistent code style and detect code smells lint: bin/golangci-lint - @bin/golangci-lint run -E gofmt -E unconvert -E misspell -E whitespace -E exportloopref -E bidichk + @bin/golangci-lint run -E gofmt -E unconvert -E misspell -E whitespace -E bidichk .PHONY: lint bin/golangci-lint: Makefile - @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- v1.60.1 + @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- v1.61.0 ## tests: run the tests tests: diff --git a/cmd/token.go b/cmd/token.go index 2fb3a84a..aed11059 100644 --- a/cmd/token.go +++ b/cmd/token.go @@ -4,7 +4,6 @@ import ( "encoding/base64" "fmt" "io" - "io/ioutil" "os" "regexp" "strconv" @@ -112,7 +111,7 @@ var verifyTokenCmd = &cobra.Command{ token = []byte(rest[0]) } else { fmt.Fprintf(os.Stderr, "Waiting for token on stdin...") - token, err = ioutil.ReadAll(io.LimitReader(os.Stdin, 10*1024)) + token, err = io.ReadAll(io.LimitReader(os.Stdin, 10*1024)) if err != nil { return fmt.Errorf("Error reading token on stdin: %s", err) } diff --git a/config/logger.go b/config/logger.go index d30650ea..bf012c14 100644 --- a/config/logger.go +++ b/config/logger.go @@ -2,7 +2,6 @@ package config import ( "io" - "io/ioutil" stdlog "log" "log/syslog" @@ -25,7 +24,7 @@ func SetupLogger(opts LoggerOptions) { hook, err := logrus_syslog.NewSyslogHook("", "", syslog.LOG_INFO, "cozy-apps-registry") if err == nil { logrus.AddHook(hook) - logrus.SetOutput(ioutil.Discard) + logrus.SetOutput(io.Discard) } w = logrus.WithField("nspace", "go-redis").Writer() } else { diff --git a/export/export.go b/export/export.go index 27238b42..4c6a06b0 100644 --- a/export/export.go +++ b/export/export.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "path" "strings" "time" @@ -154,7 +153,7 @@ func exportSwiftContainer(writer *tar.Writer, prefix string, container base.Pref if err != nil { return err } - content, err := ioutil.ReadAll(reader) + content, err := io.ReadAll(reader) if err != nil { return err } diff --git a/export/import.go b/export/import.go index 882a8555..ea4ac4da 100644 --- a/export/import.go +++ b/export/import.go @@ -8,7 +8,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "path" "strings" @@ -188,7 +187,7 @@ func Import(reader io.Reader) (err error) { contentType := header.PAXRecords[contentTypeAttr] container, parts := parts[0], parts[1:] name := path.Join(parts...) - content, err := ioutil.ReadAll(tr) + content, err := io.ReadAll(tr) if err != nil { return err } diff --git a/registry/registry.go b/registry/registry.go index a62879f9..22f23d8f 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -11,7 +11,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -890,13 +889,13 @@ func HandleAssets(tarball *Tarball, opts *VersionOptions) ([]*kivik.Attachment, continue } var data []byte - data, err = ioutil.ReadAll(tr) + data, err = io.ReadAll(tr) if err != nil { return nil, err } mime := getMIMEType(name, data) - body := ioutil.NopCloser(bytes.NewReader(data)) + body := io.NopCloser(bytes.NewReader(data)) attachments = append(attachments, &kivik.Attachment{ Content: body, Size: int64(len(data)), @@ -927,7 +926,7 @@ func ReadTarballVersion(reader io.Reader, contentType, url string) (*Tarball, er hasPrefix := true - content, err := ioutil.ReadAll(reader) + content, err := io.ReadAll(reader) if err != nil { err = errshttp.NewError(http.StatusUnprocessableEntity, "Cannot read tarball for url %s: %s", url, err) @@ -992,7 +991,7 @@ func ReadTarballVersion(reader io.Reader, contentType, url string) (*Tarball, er if basename == "package.json" { var packageContent []byte - packageContent, err = ioutil.ReadAll(tr) + packageContent, err = io.ReadAll(tr) if err != nil { err = errshttp.NewError(http.StatusUnprocessableEntity, "Could not reach version on specified url %s: %s", url, err) @@ -1030,7 +1029,7 @@ func ReadTarballVersion(reader io.Reader, contentType, url string) (*Tarball, er // ReadTarballManifest handles the tarball manifest. It checks if the manifest // exists, is valid JSON and tries to load it to the Manifest struct func ReadTarballManifest(tr io.Reader, url string) (*Manifest, []byte, map[string]interface{}, error) { - manifestContent, err := ioutil.ReadAll(tr) + manifestContent, err := io.ReadAll(tr) if err != nil { err = errshttp.NewError(http.StatusUnprocessableEntity, "Could not reach version on specified url %s: %s", url, err) diff --git a/registry/registry_test.go b/registry/registry_test.go index 626381af..85ba1f8d 100644 --- a/registry/registry_test.go +++ b/registry/registry_test.go @@ -8,7 +8,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/url" "os" "strings" @@ -236,7 +236,7 @@ func TestCreateVersionWithAttachment(t *testing.T) { ver.Version = "2.0.0" ver.Slug = "app-test" ver.ID = getVersionID(ver.Slug, ver.Version) - att1Content := ioutil.NopCloser(strings.NewReader("this is the file content of attachment 1")) + att1Content := io.NopCloser(strings.NewReader("this is the file content of attachment 1")) attachments := []*kivik.Attachment{{ Filename: "myfile1", ContentType: "text/plain", @@ -296,7 +296,7 @@ func TestFindAppAttachment(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "text/plain", att.ContentType) - content, err := ioutil.ReadAll(att.Content) + content, err := io.ReadAll(att.Content) assert.NoError(t, err) assert.Equal(t, "this is the file content of attachment 1", string(content)) } @@ -451,7 +451,7 @@ func TestDeleteVersion(t *testing.T) { // Download version func TestDownloadVersioNoManifest(t *testing.T) { - missingManifestFile, _ := ioutil.TempFile(os.TempDir(), "cozy-registry-test") + missingManifestFile, _ := os.CreateTemp(os.TempDir(), "cozy-registry-test") tarWriter := tar.NewWriter(missingManifestFile) defer func() { tarWriter.Close() @@ -473,7 +473,7 @@ func TestDownloadVersioNoManifest(t *testing.T) { tarWriter.Flush() h := sha256.New() - fileContent, _ := ioutil.ReadFile(missingManifestFile.Name()) + fileContent, _ := os.ReadFile(missingManifestFile.Name()) _, err = h.Write(fileContent) assert.NoError(t, err) @@ -613,7 +613,7 @@ func generateManifestJSON(tw *tar.Writer, manifest *Manifest) error { func generateTarball(manifestContent *Manifest, packageContent map[string]interface{}) (string, string, error) { var err error // Creating a test tarball - tmpFile, _ := ioutil.TempFile(os.TempDir(), "cozy-registry-test") + tmpFile, _ := os.CreateTemp(os.TempDir(), "cozy-registry-test") tarWriter := tar.NewWriter(tmpFile) defer tarWriter.Close() @@ -631,7 +631,7 @@ func generateTarball(manifestContent *Manifest, packageContent map[string]interf // Computes the SHA256 sum of the tarball h := sha256.New() filename := tmpFile.Name() - fileContent, _ := ioutil.ReadFile(filename) + fileContent, _ := os.ReadFile(filename) _, err = h.Write(fileContent) if err != nil { return "", "", err diff --git a/registry/virtual.go b/registry/virtual.go index f2f7bd1f..5210d7c3 100644 --- a/registry/virtual.go +++ b/registry/virtual.go @@ -10,7 +10,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -301,7 +300,7 @@ func RegenerateOverwrittenTarballs(virtualSpaceName string, appSlug string) (err } prefix := fmt.Sprintf("%s_%s_*.tar.gz", lastVersion.Slug, lastVersion.Version) - file, err := ioutil.TempFile("", prefix) + file, err := os.CreateTemp("", prefix) defer func() { cerr := file.Close() if err == nil { diff --git a/storage/fs.go b/storage/fs.go index 5b70a919..23d3c9cc 100644 --- a/storage/fs.go +++ b/storage/fs.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -93,7 +92,7 @@ func (m *localFS) Get(prefix base.Prefix, name string) (*bytes.Buffer, map[strin if err != nil { return nil, nil, err } - content, err := ioutil.ReadFile(path) + content, err := os.ReadFile(path) if err != nil { if os.IsNotExist(err) { return nil, nil, base.NewFileNotFoundError(err) diff --git a/storage/storage_test.go b/storage/storage_test.go index 01247244..4d9bcffa 100644 --- a/storage/storage_test.go +++ b/storage/storage_test.go @@ -1,7 +1,6 @@ package storage import ( - "io/ioutil" "os" "strings" "testing" @@ -31,7 +30,7 @@ func TestSwift(t *testing.T) { } func TestLocal(t *testing.T) { - tmp, err := ioutil.TempDir(os.TempDir(), "local") + tmp, err := os.MkdirTemp(os.TempDir(), "local") assert.NoError(t, err) defer os.RemoveAll(tmp) local := &localFS{tmp} diff --git a/web/router.go b/web/router.go index 0cf59a95..2dd7bcf9 100644 --- a/web/router.go +++ b/web/router.go @@ -6,7 +6,7 @@ import ( "encoding/base64" "errors" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "strings" @@ -519,5 +519,5 @@ func assetDecompress(asset string) (b []byte, err error) { if err != nil { return } - return ioutil.ReadAll(gr) + return io.ReadAll(gr) } diff --git a/web/web_test.go b/web/web_test.go index d6435fb7..ebc1ebf0 100644 --- a/web/web_test.go +++ b/web/web_test.go @@ -3,7 +3,7 @@ package web import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/url" @@ -120,27 +120,27 @@ func TestListKonnsFromVirtualSpace(t *testing.T) { } func TestAppIconFromVirtualSpace(t *testing.T) { - expected, err := ioutil.ReadFile("../scripts/drive-icon.svg") + expected, err := os.ReadFile("../scripts/drive-icon.svg") assert.NoError(t, err) u := fmt.Sprintf("%s/%s/registry/%s/icon", server.URL, myAppsSpace, overwrittenApp) res, err := http.Get(u) assert.NoError(t, err) assert.Equal(t, 200, res.StatusCode) defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) assert.NoError(t, err) assert.Equal(t, expected, body) } func TestVersionIconFromVirtualSpace(t *testing.T) { - expected, err := ioutil.ReadFile("../scripts/drive-icon.svg") + expected, err := os.ReadFile("../scripts/drive-icon.svg") assert.NoError(t, err) u := fmt.Sprintf("%s/%s/registry/%s/1.2.3/icon", server.URL, myAppsSpace, overwrittenApp) res, err := http.Get(u) assert.NoError(t, err) assert.Equal(t, 200, res.StatusCode) defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) assert.NoError(t, err) assert.Equal(t, expected, body) }