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

golangci-lint: enable int-conversion and fiximports rule of perfsprint #8385

Open
wants to merge 1 commit 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: 7 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ linters-settings:
require-explanation: true
# Enable to require nolint directives to mention the specific linter being suppressed. Default is false.
require-specific: true
perfsprint:
strconcat: false
sprintf1: false
errorf: false
int-conversion: true
fiximports: true
revive:
rules:
- name: unexported-return
Expand Down Expand Up @@ -310,6 +316,7 @@ linters:
- nilerr
- noctx
- nolintlint
- perfsprint
- revive
- staticcheck
- stylecheck
Expand Down
5 changes: 2 additions & 3 deletions pkg/backup/actions/csi/pvc_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import (
"context"
"fmt"
"strconv"

snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
"github.com/pkg/errors"
Expand Down Expand Up @@ -484,9 +485,7 @@
if backup.Spec.UploaderConfig != nil &&
backup.Spec.UploaderConfig.ParallelFilesUpload > 0 {
dataUpload.Spec.DataMoverConfig = make(map[string]string)
dataUpload.Spec.DataMoverConfig[uploaderUtil.ParallelFilesUpload] = fmt.Sprintf(
"%d", backup.Spec.UploaderConfig.ParallelFilesUpload,
)
dataUpload.Spec.DataMoverConfig[uploaderUtil.ParallelFilesUpload] = strconv.Itoa(backup.Spec.UploaderConfig.ParallelFilesUpload)

Check warning on line 488 in pkg/backup/actions/csi/pvc_action.go

View check run for this annotation

Codecov / codecov/patch

pkg/backup/actions/csi/pvc_action.go#L488

Added line #L488 was not covered by tests
}

return dataUpload
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/cli/backup/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package backup
import (
"context"
"fmt"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -222,7 +223,7 @@ func TestCreateCommand(t *testing.T) {
flags.Parse([]string{"--default-volumes-to-fs-backup", defaultVolumesToFsBackup})
flags.Parse([]string{"--resource-policies-configmap", resPoliciesConfigmap})
flags.Parse([]string{"--data-mover", dataMover})
flags.Parse([]string{"--parallel-files-upload", fmt.Sprintf("%d", parallelFilesUpload)})
flags.Parse([]string{"--parallel-files-upload", strconv.Itoa(parallelFilesUpload)})
//flags.Parse([]string{"--wait"})

client := velerotest.NewFakeControllerRuntimeClient(t).(kbclient.WithWatch)
Expand Down
3 changes: 2 additions & 1 deletion pkg/label/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package label

import (
"crypto/sha256"
"encoding/hex"
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -38,7 +39,7 @@ func GetValidName(label string) string {
}

sha := sha256.Sum256([]byte(label))
strSha := fmt.Sprintf("%x", sha)
strSha := hex.EncodeToString(sha[:])
charsFromLabel := validation.DNS1035LabelMaxLength - 6
if charsFromLabel < 0 {
// Derive the label name from sha hash in case the DNS1035LabelMaxLength is less than 6
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/schedule/schedule-backup-creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/rand"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -56,7 +57,7 @@ func (s *ScheduleBackupCreation) Init() error {
s.pvcName = "pvc-1"
s.ScheduleArgs = []string{
"--include-namespaces", s.namespace,
"--schedule=*/" + fmt.Sprintf("%v", s.Period) + " * * * *",
"--schedule=*/" + strconv.Itoa(s.Period) + " * * * *",
}
Expect(s.Period).To(BeNumerically("<", 30))
return nil
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/schedule/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/rand"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -41,7 +42,7 @@ func (n *ScheduleBackup) Init() error {
}
n.ScheduleArgs = []string{
"--include-namespaces", strings.Join(*n.NSIncluded, ","),
"--schedule=*/" + fmt.Sprintf("%v", n.Period) + " * * * *",
"--schedule=*/" + strconv.Itoa(n.Period) + " * * * *",
}

Expect(n.Period).To(BeNumerically("<", 30))
Expand Down
Loading