make lint: enable mirror

Helpful reports to avoid unnecessary allocations.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2023-06-19 14:08:04 +02:00
parent a35da3ad87
commit 60a5a59475
7 changed files with 8 additions and 9 deletions

View File

@ -21,7 +21,6 @@ linters:
# useful hints that should be addressed # useful hints that should be addressed
- ginkgolinter - ginkgolinter
- nakedret - nakedret
- mirror
- wastedassign - wastedassign
- gosmopolitan # usage of time.Local in pkg/k8s.io - gosmopolitan # usage of time.Local in pkg/k8s.io
- tagliatelle # too many JSON keys cannot be changed due to compat - tagliatelle # too many JSON keys cannot be changed due to compat

View File

@ -106,7 +106,7 @@ func add(cmd *cobra.Command, args []string) error {
Default: cOpts.Default, Default: cOpts.Default,
} }
dest := args[1] dest := args[1]
if match, err := regexp.Match("^[A-Za-z][A-Za-z0-9+.-]*://", []byte(dest)); err != nil { if match, err := regexp.MatchString("^[A-Za-z][A-Za-z0-9+.-]*://", dest); err != nil {
return fmt.Errorf("invalid destination: %w", err) return fmt.Errorf("invalid destination: %w", err)
} else if !match { } else if !match {
dest = "ssh://" + dest dest = "ssh://" + dest
@ -203,7 +203,7 @@ func create(cmd *cobra.Command, args []string) error {
if err != nil { if err != nil {
return err return err
} }
if match, err := regexp.Match("^[A-Za-z][A-Za-z0-9+.-]*://", []byte(dest)); err != nil { if match, err := regexp.MatchString("^[A-Za-z][A-Za-z0-9+.-]*://", dest); err != nil {
return fmt.Errorf("invalid destination: %w", err) return fmt.Errorf("invalid destination: %w", err)
} else if !match { } else if !match {
dest = "ssh://" + dest dest = "ssh://" + dest

View File

@ -64,7 +64,7 @@ func logToKmsg(s string) bool {
kmsgFile = f kmsgFile = f
} }
if _, err := kmsgFile.Write([]byte(s)); err != nil { if _, err := kmsgFile.WriteString(s); err != nil {
kmsgFile.Close() kmsgFile.Close()
kmsgFile = nil kmsgFile = nil
return false return false

View File

@ -343,7 +343,7 @@ func generateResourceFile(res *spec.LinuxResources) (string, []string, error) {
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }
_, err = f.WriteString(string(j)) _, err = f.Write(j)
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }

View File

@ -374,7 +374,7 @@ func becomeRootInUserNS(pausePid, fileToRead string, fileOutput *os.File) (_ boo
} }
} }
_, err = w.Write([]byte("0")) _, err = w.WriteString("0")
if err != nil { if err != nil {
return false, -1, fmt.Errorf("write to sync pipe: %w", err) return false, -1, fmt.Errorf("write to sync pipe: %w", err)
} }

View File

@ -1739,7 +1739,7 @@ func createSourceTarFile(fileName, fileContent, tarFilePath string) error {
return err return err
} }
_, err = file.Write([]byte(fileContent)) _, err = file.WriteString(fileContent)
if err != nil { if err != nil {
return err return err
} }
@ -4996,7 +4996,7 @@ spec:
file, err := os.Create(filepath.Join(hostPathLocation, "testing", "onlythis", "123.txt")) file, err := os.Create(filepath.Join(hostPathLocation, "testing", "onlythis", "123.txt"))
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
_, err = file.Write([]byte("hi")) _, err = file.WriteString("hi")
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
err = file.Close() err = file.Close()

View File

@ -175,7 +175,7 @@ func moveUnderCgroup(cgroup, subtree string, processes []uint32) error {
if len(processes) > 0 { if len(processes) > 0 {
for _, pid := range processes { for _, pid := range processes {
if _, err := f.Write([]byte(fmt.Sprintf("%d\n", pid))); err != nil { if _, err := f.WriteString(fmt.Sprintf("%d\n", pid)); err != nil {
logrus.Debugf("Cannot move process %d to cgroup %q: %v", pid, newCgroup, err) logrus.Debugf("Cannot move process %d to cgroup %q: %v", pid, newCgroup, err)
} }
} }