From d41d69e38d26ec09999f588e345b6a049b794086 Mon Sep 17 00:00:00 2001 From: Bastian de Byl Date: Fri, 15 Jul 2022 10:59:55 -0400 Subject: [PATCH] dependabot-1 Linting fixes, removed varnamelen from lint checks --- .golangci.yml | 1 + archive/tar/tar.go | 2 +- cache/rebuilder.go | 2 +- cache/restorer.go | 2 +- cache/util.go | 2 +- go.mod | 5 ++--- go.sum | 6 ++---- internal/io.go | 12 ++++++------ internal/logger.go | 4 ++-- test/helpers.go | 28 ++++++++++++++-------------- 10 files changed, 31 insertions(+), 33 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 3cfac980..31a4a3b3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,6 +11,7 @@ linters: enable-all: true disable: - goerr113 + - varnamelen linters-settings: errcheck: diff --git a/archive/tar/tar.go b/archive/tar/tar.go index 3272b1e2..1896b1ef 100644 --- a/archive/tar/tar.go +++ b/archive/tar/tar.go @@ -9,7 +9,7 @@ import ( "path/filepath" "strings" - "github.com/go-kit/kit/log" + "github.com/go-kit/log" "github.com/meltwater/drone-cache/internal" ) diff --git a/cache/rebuilder.go b/cache/rebuilder.go index e8449cbd..d87589f0 100644 --- a/cache/rebuilder.go +++ b/cache/rebuilder.go @@ -96,7 +96,7 @@ func (r rebuilder) Rebuild(srcs []string) error { } // rebuild pushes the archived file to the cache. -func (r rebuilder) rebuild(src, dst string) (err error) { +func (r rebuilder) rebuild(src, dst string) error { src, err = filepath.Abs(filepath.Clean(src)) if err != nil { return fmt.Errorf("clean source path, %w", err) diff --git a/cache/restorer.go b/cache/restorer.go index df6f8720..c68f3ef5 100644 --- a/cache/restorer.go +++ b/cache/restorer.go @@ -77,7 +77,7 @@ func (r restorer) Restore(dsts []string) error { } // restore fetches the archived file from the cache and restores to the host machine's file system. -func (r restorer) restore(src, dst string) (err error) { +func (r restorer) restore(src, dst string) error { pr, pw := io.Pipe() defer internal.CloseWithErrCapturef(&err, pr, "rebuild, pr close <%s>", dst) diff --git a/cache/util.go b/cache/util.go index 064b4052..2542d99a 100644 --- a/cache/util.go +++ b/cache/util.go @@ -5,7 +5,7 @@ type statWriter struct { written int64 } -func (s *statWriter) Write(p []byte) (n int, err error) { +func (s *statWriter) Write(p []byte) (int, error) { size := len(p) s.written += int64(size) diff --git a/go.mod b/go.mod index 7cbe01d0..a0407a44 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/aws/aws-sdk-go v1.44.55 github.com/dustin/go-humanize v1.0.0 github.com/go-kit/kit v0.12.0 + github.com/go-kit/log v0.2.1 github.com/google/go-cmp v0.5.8 github.com/klauspost/compress v1.15.8 github.com/pkg/sftp v1.13.5 @@ -24,11 +25,9 @@ require ( github.com/Azure/azure-pipeline-go v0.2.3 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.2 // indirect - github.com/golangci/golangci-lint v1.46.2 // indirect github.com/google/uuid v1.3.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect github.com/googleapis/gax-go/v2 v2.4.0 // indirect @@ -45,7 +44,7 @@ require ( golang.org/x/text v0.3.7 // indirect golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto v0.0.0-20220714152414-ccd2914cffd4 // indirect + google.golang.org/genproto v0.0.0-20220714211235-042d03aeabc9 // indirect google.golang.org/grpc v1.48.0 // indirect google.golang.org/protobuf v1.28.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 02fdc5e6..c30d8f39 100644 --- a/go.sum +++ b/go.sum @@ -161,8 +161,6 @@ github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golangci/golangci-lint v1.46.2 h1:o90t/Xa6dhJbvy8Bz2RpzUXqrkigp19DLStMolTZbyo= -github.com/golangci/golangci-lint v1.46.2/go.mod h1:3DkdHnxn9eoTTrpT2gB0TEv8KSziuoqe9FitgQLHvAY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -688,8 +686,8 @@ google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90/go.mod h1:KEWEmljW google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220628213854-d9e0b6570c03/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= -google.golang.org/genproto v0.0.0-20220714152414-ccd2914cffd4 h1:y2IEhgO0Rmt0axD3Se6N7D5e8yhTG9dUiFCyMbaaN7U= -google.golang.org/genproto v0.0.0-20220714152414-ccd2914cffd4/go.mod h1:GkXuJDJ6aQ7lnJcRF+SJVgFdQhypqgl3LB1C9vabdRE= +google.golang.org/genproto v0.0.0-20220714211235-042d03aeabc9 h1:zfXhTgBfGlIh3jMXN06W8qbhFGsh6MJNJiYEuhTddOI= +google.golang.org/genproto v0.0.0-20220714211235-042d03aeabc9/go.mod h1:GkXuJDJ6aQ7lnJcRF+SJVgFdQhypqgl3LB1C9vabdRE= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= diff --git a/internal/io.go b/internal/io.go index 85d60707..8c4e6b8e 100644 --- a/internal/io.go +++ b/internal/io.go @@ -6,13 +6,13 @@ import ( "io" "os" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" ) // CloseWithErrLogf is making sure we log every error, even those from best effort tiny closers. func CloseWithErrLogf(logger log.Logger, closer io.Closer, format string, a ...interface{}) { - err := close(closer) + err := closeIo(closer) if err == nil { return } @@ -27,7 +27,7 @@ func CloseWithErrLogf(logger log.Logger, closer io.Closer, format string, a ...i // CloseWithErrCapturef runs function and on error return error by argument including the given error.. func CloseWithErrCapturef(err *error, closer io.Closer, format string, a ...interface{}) { if err != nil { - cErr := close(closer) + cErr := closeIo(closer) if cErr == nil { return } @@ -40,7 +40,7 @@ func CloseWithErrCapturef(err *error, closer io.Closer, format string, a ...inte return } - cErr := close(closer) + cErr := closeIo(closer) if cErr == nil { return } @@ -48,7 +48,7 @@ func CloseWithErrCapturef(err *error, closer io.Closer, format string, a ...inte *err = cErr } -func close(closer io.Closer) error { +func closeIo(closer io.Closer) error { err := closer.Close() if err == nil { return nil diff --git a/internal/logger.go b/internal/logger.go index 13235a8e..daeab819 100644 --- a/internal/logger.go +++ b/internal/logger.go @@ -3,8 +3,8 @@ package internal import ( "os" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" ) const ( diff --git a/test/helpers.go b/test/helpers.go index d6067262..61f670ae 100644 --- a/test/helpers.go +++ b/test/helpers.go @@ -7,8 +7,8 @@ import ( ) // CreateTempFile is a test helper to create a temporary file with given name and content, in given directory. -func CreateTempFile(t testing.TB, name string, content []byte, in ...string) (string, func()) { - t.Helper() +func CreateTempFile(tb testing.TB, name string, content []byte, in ...string) (string, func()) { + tb.Helper() parent := "" if len(in) > 0 { @@ -17,23 +17,23 @@ func CreateTempFile(t testing.TB, name string, content []byte, in ...string) (st tmpfile, err := ioutil.TempFile(parent, name+"_*.testfile") if err != nil { - t.Fatalf("unexpectedly failed creating the temp file: %v", err) + tb.Fatalf("unexpectedly failed creating the temp file: %v", err) } if _, err := tmpfile.Write(content); err != nil { - t.Fatalf("unexpectedly failed writing to the temp file: %v", err) + tb.Fatalf("unexpectedly failed writing to the temp file: %v", err) } if err := tmpfile.Close(); err != nil { - t.Fatalf("unexpectedly failed closing the temp file: %v", err) + tb.Fatalf("unexpectedly failed closing the temp file: %v", err) } return tmpfile.Name(), func() { os.Remove(tmpfile.Name()) } } // CreateTempFilesInDir is a test helper to create temporary files using name as prefix and content, in given directory. -func CreateTempFilesInDir(t testing.TB, name string, content []byte, in ...string) (string, func()) { - t.Helper() +func CreateTempFilesInDir(tb testing.TB, name string, content []byte, in ...string) (string, func()) { + tb.Helper() parent := "" if len(in) > 0 { @@ -42,21 +42,21 @@ func CreateTempFilesInDir(t testing.TB, name string, content []byte, in ...strin tmpDir, err := ioutil.TempDir(parent, name+"-testdir-*") if err != nil { - t.Fatalf("unexpectedly failed creating the temp dir: %v", err) + tb.Fatalf("unexpectedly failed creating the temp dir: %v", err) } for i := 0; i < 3; i++ { tmpfile, err := ioutil.TempFile(tmpDir, name+"_*.testfile") if err != nil { - t.Fatalf("unexpectedly failed creating the temp file: %v", err) + tb.Fatalf("unexpectedly failed creating the temp file: %v", err) } if _, err := tmpfile.Write(content); err != nil { - t.Fatalf("unexpectedly failed writing to the temp file: %v", err) + tb.Fatalf("unexpectedly failed writing to the temp file: %v", err) } if err := tmpfile.Close(); err != nil { - t.Fatalf("unexpectedly failed closing the temp file: %v", err) + tb.Fatalf("unexpectedly failed closing the temp file: %v", err) } } @@ -64,8 +64,8 @@ func CreateTempFilesInDir(t testing.TB, name string, content []byte, in ...strin } // CreateTempDir is a test helper to create a temporary directory, in given directory. -func CreateTempDir(t testing.TB, name string, in ...string) (string, func()) { - t.Helper() +func CreateTempDir(tb testing.TB, name string, in ...string) (string, func()) { + tb.Helper() parent := "" if len(in) > 0 { @@ -74,7 +74,7 @@ func CreateTempDir(t testing.TB, name string, in ...string) (string, func()) { tmpDir, err := ioutil.TempDir(parent, name+"-testdir-*") if err != nil { - t.Fatalf("unexpectedly failed creating the temp dir: %v", err) + tb.Fatalf("unexpectedly failed creating the temp dir: %v", err) } return tmpDir, func() { os.RemoveAll(tmpDir) }