Skip to content

Commit

Permalink
Update golangci-lint to v1.61.0 (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Sep 10, 2024
1 parent fb5bfe8 commit 362333b
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions cmd/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"os"
"regexp"
"strconv"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions config/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"io"
"io/ioutil"
stdlog "log"
"log/syslog"

Expand All @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"path"
"strings"
"time"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions export/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"path"
"strings"

Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 5 additions & 6 deletions registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/url"
"os"
"strings"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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()
Expand All @@ -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)

Expand Down Expand Up @@ -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()

Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions registry/virtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions storage/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions storage/storage_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package storage

import (
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions web/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -519,5 +519,5 @@ func assetDecompress(asset string) (b []byte, err error) {
if err != nil {
return
}
return ioutil.ReadAll(gr)
return io.ReadAll(gr)
}
10 changes: 5 additions & 5 deletions web/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package web
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 362333b

Please sign in to comment.