Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linter): golangci-lint v1.61.0 compatibility #334

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions internal/clierrors/command_failed.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ type CommandFailedError struct {

var _ ClientError = CommandFailedError{}

func min(a, b int) int {
if a < b {
return a
}
return b
}

func (err CommandFailedError) ErrorCode() int {
return min(err.FailedCount, 99)
}
Expand Down
7 changes: 6 additions & 1 deletion internal/commands/storage/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package storage
import (
"fmt"
"io"
"math"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -249,12 +250,16 @@ func (s *importCommand) ExecuteWithoutArguments(exec commands.Executor) (output.
})
} else {
// we have no knowledge of the remote file size, report bytes uploaded
transferred := fmt.Sprintf("%sB", "-1")
if statusUpdate.bytesTransferred <= math.MaxUint32 {
transferred = ui.AbbrevNumBinaryPrefix(uint(statusUpdate.bytesTransferred)) //nolint:gosec // disable G115: false positive because value is checked
}
exec.PushProgressUpdate(messages.Update{
Key: msg,
ProgressMessage: fmt.Sprintf(
"- %sed %sB (%sBps)",
transferType,
ui.AbbrevNumBinaryPrefix(uint(statusUpdate.bytesTransferred)),
transferred,
ui.AbbrevNumBinaryPrefix(uint(bps)),
),
})
Expand Down
8 changes: 4 additions & 4 deletions internal/format/stringslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func toIfaceSlice(val interface{}) ([]interface{}, bool) {
}

func maxStringLen(strings []string) int {
max := 0
maxLen := 0
for _, str := range strings {
if strLen := len(str); strLen > max {
max = strLen
if strLen := len(str); strLen > maxLen {
maxLen = strLen
}
}
return max
return maxLen
}

func stringSliceString(values []interface{}, andOrOr string, singleLine bool) string {
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/list_layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (s *ListLayout) appendSection(title, note string, sectionBody []string) {
if s.style.NoteSeparator {
s.appendLine()
}
s.l.AppendItem(DefaultNoteColours.Sprintf(note))
s.l.AppendItem(DefaultNoteColours.Sprintf("%s", note))
}
if s.style.MarginBottom {
s.appendLine()
Expand Down
4 changes: 4 additions & 0 deletions internal/ui/numeric.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func AbbrevNumBinaryPrefix(raw uint) string {

// FormatBytes returns a string with the given number interpreted as bytes and abbreviated with binary formatting (eg 1024 = 1KiB)
func FormatBytes(n int) string {
if n < 0 || n > math.MaxUint32 {
return fmt.Sprintf("%sB", "-1")
}

return fmt.Sprintf("%sB", AbbrevNumBinaryPrefix(uint(n)))
}

Expand Down
6 changes: 5 additions & 1 deletion internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ func FormatRange(start, end string) string {

// ConcatStrings like join but handles well the empty strings
func ConcatStrings(strs ...string) string {
ret := fmt.Sprintf(strs[0])
if len(strs) == 0 {
return ""
}

ret := strs[0]

if len(strs) <= 1 {
return ret
Expand Down
45 changes: 45 additions & 0 deletions internal/ui/ui_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ui

import (
"testing"
)

func TestConcatStringsSingleString(t *testing.T) {
result := ConcatStrings("hello")
expected := "hello"
if result != expected {
t.Errorf("expected %s, got %s", expected, result)
}
}

func TestConcatStringsMultipleStrings(t *testing.T) {
result := ConcatStrings("hello", "world", "foo", "bar")
expected := "hello/world/foo/bar"
if result != expected {
t.Errorf("expected %s, got %s", expected, result)
}
}

func TestConcatStringsWithEmptyStrings(t *testing.T) {
result := ConcatStrings("hello", "", "world", "", "foo", "bar")
expected := "hello/world/foo/bar"
if result != expected {
t.Errorf("expected %s, got %s", expected, result)
}
}

func TestConcatStringsAllEmptyStrings(t *testing.T) {
result := ConcatStrings("", "", "")
expected := ""
if result != expected {
t.Errorf("expected %s, got %s", expected, result)
}
}

func TestConcatStringsEmptyInput(t *testing.T) {
result := ConcatStrings()
expected := ""
if result != expected {
t.Errorf("expected %s, got %s", expected, result)
}
}