Skip to content

Commit 9495b2a

Browse files
committed
linters: enable perfsrpint linter
Checks that fmt.Sprintf can be replaced with a faster alternative. Signed-off-by: Mahe Tardy <[email protected]>
1 parent 8cd2a1b commit 9495b2a

File tree

115 files changed

+472
-442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+472
-442
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ linters:
1818
- makezero
1919
- misspell
2020
- mirror
21+
- perfsprint
2122
- revive
2223
- staticcheck
2324
- unused

api/vendor/github.com/cilium/tetragon/pkg/matchers/timestampmatcher/timestampmatcher.go

Lines changed: 29 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dump-syscalls-info/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ func (c *SyscallsIDsCmd) Run() error {
364364
"git", "archive",
365365
"--remote=git://sourceware.org/git/glibc.git",
366366
//"HEAD:sysdeps/unix/sysv/linux/aarch64",
367-
fmt.Sprintf("HEAD:%s", glibcLoc),
367+
"HEAD:" + glibcLoc,
368368
"--", "arch-syscall.h",
369369
"|",
370370
"tar", "xv", "-C", abiTmpDir},

cmd/tetra/common/utils_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package common
55

66
import (
7-
"fmt"
7+
"strconv"
88
"testing"
99
)
1010

@@ -25,7 +25,7 @@ func TestHumanizeByteCount(t *testing.T) {
2525
{12970000000000, "12.97 TB"},
2626
}
2727
for _, tt := range tests {
28-
t.Run(fmt.Sprintf("%d", tt.input), func(t *testing.T) {
28+
t.Run(strconv.Itoa(tt.input), func(t *testing.T) {
2929
if got := HumanizeByteCount(tt.input); got != tt.want {
3030
t.Errorf("HumanizeByteCount(%d) = %v, want %v", tt.input, got, tt.want)
3131
}

cmd/tetra/debug/progs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func detectBpffs() (string, error) {
9595
}
9696
return path, nil
9797
}
98-
return "", fmt.Errorf("bpffs mount not found")
98+
return "", errors.New("bpffs mount not found")
9999
}
100100

101101
func detectLib() (string, error) {
@@ -107,7 +107,7 @@ func detectLib() (string, error) {
107107
}
108108
return path, nil
109109
}
110-
return "", fmt.Errorf("lib directory mount not found")
110+
return "", errors.New("lib directory mount not found")
111111
}
112112

113113
func NewProgsCmd() *cobra.Command {
@@ -329,7 +329,7 @@ func getAllProgs(lib string) ([]*prog, error) {
329329

330330
prog, ok := coll.Programs["iter"]
331331
if !ok {
332-
initErr = fmt.Errorf("can't file iter program")
332+
initErr = errors.New("can't file iter program")
333333
return
334334
}
335335
initProg, initErr = prog.Clone()

cmd/tetra/loglevel/loglevel.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package loglevel
55

66
import (
7+
"errors"
78
"fmt"
89

910
"github.com/cilium/tetragon/api/v1/tetragon"
@@ -54,7 +55,7 @@ func New() *cobra.Command {
5455
tetra loglevel set info`,
5556
RunE: func(cmd *cobra.Command, args []string) error {
5657
if len(args) != 1 {
57-
return fmt.Errorf("usage: tetra loglevel set [trace|debug|info|warning|error|fatal|panic]")
58+
return errors.New("usage: tetra loglevel set [trace|debug|info|warning|error|fatal|panic]")
5859
}
5960
levelStr := args[0]
6061
levelParsed, err := logrus.ParseLevel(levelStr)

cmd/tetragon-vmtests-run/conf.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package main
55

66
import (
7-
"fmt"
87
"path/filepath"
98

109
"github.com/cilium/little-vm-helper/pkg/runner"
@@ -32,7 +31,7 @@ type RunConf struct {
3231

3332
func (rc RunConf) testImageFilename() string {
3433
if ext := filepath.Ext(rc.vmName); ext == "" {
35-
return fmt.Sprintf("%s.qcow2", rc.vmName)
34+
return rc.vmName + ".qcow2"
3635
}
3736
return rc.vmName
3837
}

cmd/tetragon-vmtests-run/filesystems.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ func (fs *virtIOFilesystem) vmMountpoint() string {
2222
}
2323

2424
func (fs *virtIOFilesystem) qemuArgs() []string {
25-
fsId := fmt.Sprintf("%s_id", fs.id)
26-
tag := fmt.Sprintf("%s_tag", fs.id)
25+
fsId := fs.id + "_id"
26+
tag := fs.id + "_tag"
2727
return []string{
2828
"-fsdev", fmt.Sprintf("local,id=%s,path=%s,security_model=none", fsId, fs.hostdir),
2929
"-device", fmt.Sprintf("virtio-9p-pci,fsdev=%s,mount_tag=%s", fsId, tag),
3030
}
3131
}
3232

3333
func (fs *virtIOFilesystem) fstabEntry() string {
34-
tag := fmt.Sprintf("%s_tag", fs.id)
34+
tag := fs.id + "_tag"
3535
return fmt.Sprintf("%s\t%s\t9p\ttrans=virtio,rw\t0\t0\n", tag, fs.vmdir)
3636
}

cmd/tetragon-vmtests-run/qemu.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package main
55

66
import (
7-
"fmt"
87
"path/filepath"
98

109
"github.com/cilium/little-vm-helper/pkg/runner"
@@ -19,7 +18,7 @@ func buildQemuArgs(log *logrus.Logger, rcnf RunConf) ([]string, error) {
1918
rcnf.KernelAppendArgs = append(rcnf.KernelAppendArgs, "systemd.unified_cgroup_hierarchy=0")
2019
}
2120
if rcnf.useTetragonTesterInit {
22-
rcnf.KernelAppendArgs = append(rcnf.KernelAppendArgs, fmt.Sprintf("init=%s", TetragonTesterBin))
21+
rcnf.KernelAppendArgs = append(rcnf.KernelAppendArgs, "init="+TetragonTesterBin)
2322
}
2423
}
2524

cmd/tetragon/main_linux.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package main
55

66
import (
77
"context"
8+
"errors"
89
"fmt"
910
"io/fs"
1011
"net"
@@ -746,7 +747,7 @@ func startExporter(ctx context.Context, server *server.Server) error {
746747
finfo, err := os.Stat(filepath.Clean(option.Config.ExportFilename))
747748
if err == nil && finfo.IsDir() {
748749
// Error if exportFilename points to a directory
749-
return fmt.Errorf("passed export JSON logs file point to a directory")
750+
return errors.New("passed export JSON logs file point to a directory")
750751
}
751752
logFile := filepath.Base(option.Config.ExportFilename)
752753
logsDir, err := filepath.Abs(filepath.Dir(filepath.Clean(option.Config.ExportFilename)))

0 commit comments

Comments
 (0)