From 800e249977c4dddff78e42b4e771f5436bb6dd1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= Date: Thu, 1 Aug 2024 08:30:57 +0200 Subject: [PATCH] Update to golangci-lint 1.59.1 (#100) --- .../workflows/unit-test-on-pull-request.yml | 1 - .golangci.yml | 34 +++++++------------ Makefile | 4 ++- interpreter/perl/instance.go | 4 +-- libpf/basehash/hash128.go | 20 +++++------ libpf/convenience.go | 1 + libpf/pfelf/file.go | 23 +++++-------- processmanager/manager_test.go | 2 +- testsupport/io.go | 2 +- tracer/probe_linux.go | 2 +- 10 files changed, 39 insertions(+), 54 deletions(-) diff --git a/.github/workflows/unit-test-on-pull-request.yml b/.github/workflows/unit-test-on-pull-request.yml index e75faff2..0efb3826 100644 --- a/.github/workflows/unit-test-on-pull-request.yml +++ b/.github/workflows/unit-test-on-pull-request.yml @@ -23,7 +23,6 @@ jobs: - name: Linter run: | go version - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.56.2 make lint test: diff --git a/.golangci.yml b/.golangci.yml index 8019559a..0eb09330 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,8 +1,8 @@ service: - golangci-lint-version: 1.54.x + golangci-lint-version: 1.59.x -run: - skip-dirs: +issues: + exclude-dirs: - artifacts - build-targets - design @@ -39,10 +39,11 @@ linters: - depguard - dupword - durationcheck # might be worth fixing + - err113 - errorlint # might be worth fixing - exhaustive - - exhaustivestruct - exhaustruct + - forbidigo - forcetypeassert # might be worth fixing - funlen - gci # might be worth fixing @@ -53,16 +54,15 @@ linters: - gocyclo - godot - godox # complains about TODO etc - - goerr113 - gofumpt - gomnd - gomoddirectives - - ifshort - inamedparam - interfacebloat - ireturn - maintidx - makezero + - mnd - nestif - nilerr # might be worth fixing - nilnil @@ -70,10 +70,8 @@ linters: - noctx # might be worth fixing - nolintlint - nonamedreturns - - nosnakecase - paralleltest - protogetter - - scopelint # might be worth fixing - sqlclosecheck # might be worth fixing - tagalign - tagliatelle @@ -85,18 +83,11 @@ linters: - wastedassign - wsl - wrapcheck - - forbidigo # the following linters are deprecated - - exhaustivestruct - - scopelint - - nosnakecase - - interfacer - - maligned - - ifshort - - structcheck # might be worth fixing - - deadcode - - golint - - varcheck + - execinquery + # we don't want to change code to Go 1.22+ yet + - intrange + - copyloopvar linters-settings: goconst: @@ -127,7 +118,6 @@ linters-settings: min-complexity: 15 govet: enable-all: true - check-shadowing: true disable: - fieldalignment settings: @@ -143,7 +133,7 @@ linters-settings: lll: line-length: 100 tab-width: 4 - maligned: - suggest-new: true misspell: locale: US + ignore-words: + - rela diff --git a/Makefile b/Makefile index 423d431f..634412f6 100644 --- a/Makefile +++ b/Makefile @@ -65,10 +65,12 @@ binary: ebpf: $(MAKE) -j$(shell nproc) -C support/ebpf +GOLANGCI_LINT_VERSION = "v1.59.1" lint: generate # We don't want to build the tracers here, so we stub them for linting touch support/ebpf/tracer.ebpf.x86 - golangci-lint run --timeout 10m + go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) version + go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run --build-tags integration,linux --timeout 10m test: generate ebpf test-deps go test $(GO_FLAGS) ./... diff --git a/interpreter/perl/instance.go b/interpreter/perl/instance.go index 180beaeb..fbad4966 100644 --- a/interpreter/perl/instance.go +++ b/interpreter/perl/instance.go @@ -285,13 +285,13 @@ func (i *perlInstance) getHVName(hvAddr libpf.Address) (string, error) { } xpvhvAddr := npsr.Ptr(hv, vms.sv.sv_any) - max := i.rm.Uint64(xpvhvAddr + libpf.Address(vms.xpvhv.xhv_max)) + end := i.rm.Uint64(xpvhvAddr + libpf.Address(vms.xpvhv.xhv_max)) xpvhvAux := make([]byte, vms.xpvhv_aux.sizeof) if i.d.version < perlVersion(5, 35, 0) { // The aux structure is at the end of the array. Calculate its address. arrayAddr := npsr.Ptr(hv, vms.sv.svu_hash) - xpvhvAuxAddr := arrayAddr + libpf.Address((max+1)*8) + xpvhvAuxAddr := arrayAddr + libpf.Address((end+1)*8) if err := i.rm.Read(xpvhvAuxAddr, xpvhvAux); err != nil { return "", err } diff --git a/libpf/basehash/hash128.go b/libpf/basehash/hash128.go index 0e722755..5b60dce1 100644 --- a/libpf/basehash/hash128.go +++ b/libpf/basehash/hash128.go @@ -133,37 +133,37 @@ func (h Hash128) Bytes() []byte { func (h Hash128) Format(s fmt.State, ch rune) { if s.Flag('#') { if ch == 'x' || ch == 'v' { - s.Write([]byte("0x")) - s.Write([]byte(uint64ToLowerHex(h.hi))) + _, _ = s.Write([]byte("0x")) + _, _ = s.Write([]byte(uint64ToLowerHex(h.hi))) buf := make([]byte, 16) putUint64AsLowerHex(h.lo, buf) - s.Write(buf) + _, _ = s.Write(buf) return } if ch == 'X' { - s.Write([]byte("0x")) - s.Write([]byte(uint64ToUpperHex(h.hi))) + _, _ = s.Write([]byte("0x")) + _, _ = s.Write([]byte(uint64ToUpperHex(h.hi))) buf := make([]byte, 16) putUint64AsUpperHex(h.lo, buf) - s.Write(buf) + _, _ = s.Write(buf) return } } if ch == 'x' { - s.Write([]byte(uint64ToLowerHex(h.hi))) + _, _ = s.Write([]byte(uint64ToLowerHex(h.hi))) buf := make([]byte, 16) putUint64AsLowerHex(h.lo, buf) - s.Write(buf) + _, _ = s.Write(buf) return } if ch == 'X' { - s.Write([]byte(uint64ToUpperHex(h.hi))) + _, _ = s.Write([]byte(uint64ToUpperHex(h.hi))) buf := make([]byte, 16) putUint64AsUpperHex(h.lo, buf) - s.Write(buf) + _, _ = s.Write(buf) return } diff --git a/libpf/convenience.go b/libpf/convenience.go index e183dc96..db7daa7f 100644 --- a/libpf/convenience.go +++ b/libpf/convenience.go @@ -60,6 +60,7 @@ func AddJitter(baseDuration time.Duration, jitter float64) time.Duration { log.Errorf("Jitter (%f) out of range [0..1].", jitter) return baseDuration } + //nolint:gosec return time.Duration((1 + jitter - 2*jitter*rand.Float64()) * float64(baseDuration)) } diff --git a/libpf/pfelf/file.go b/libpf/pfelf/file.go index 659a354e..9b0a9289 100644 --- a/libpf/pfelf/file.go +++ b/libpf/pfelf/file.go @@ -636,20 +636,16 @@ func (f *File) CRC32() (int32, error) { func (ph *Prog) ReadAt(p []byte, off int64) (n int, err error) { // First load as much as possible from the disk if uint64(off) < ph.Filesz { - max := len(p) - if int64(max) > int64(ph.Filesz)-off { - max = int(int64(ph.Filesz) - off) - } - - n, err = ph.elfReader.ReadAt(p[0:max], int64(ph.Off)+off) + end := int(min(int64(len(p)), int64(ph.Filesz)-off)) + n, err = ph.elfReader.ReadAt(p[0:end], int64(ph.Off)+off) if n == 0 && errors.Is(err, syscall.EFAULT) { // Read zeroes from sparse file holes - for i := range p[0:max] { + for i := range p[0:end] { p[i] = 0 } - n = max + n = end } - if n != max || err != nil { + if n != end || err != nil { return n, err } off += int64(n) @@ -658,14 +654,11 @@ func (ph *Prog) ReadAt(p []byte, off int64) (n int, err error) { // The gap between Filesz and Memsz is allocated by dynamic loader as // anonymous pages, and zero initialized. Read zeroes from this area. if n < len(p) && uint64(off) < ph.Memsz { - max := len(p) - n - if int64(max) > int64(ph.Memsz)-off { - max = int(int64(ph.Memsz) - off) - } - for i := range p[n : n+max] { + end := int(min(int64(len(p)-n), int64(ph.Memsz)-off)) + for i := range p[n : n+end] { p[i] = 0 } - n += max + n += end } if n != len(p) { diff --git a/processmanager/manager_test.go b/processmanager/manager_test.go index 885045e0..5d84c990 100644 --- a/processmanager/manager_test.go +++ b/processmanager/manager_test.go @@ -94,7 +94,7 @@ type dummyStackDeltaProvider struct{} // GetIntervalStructuresForFile fills in the expected data structure with semi random data. func (d *dummyStackDeltaProvider) GetIntervalStructuresForFile(_ host.FileID, _ *pfelf.Reference, result *sdtypes.IntervalData) error { - r := rand.New(rand.NewPCG(42, 42)) + r := rand.New(rand.NewPCG(42, 42)) //nolint:gosec addr := 0x10 for i := 0; i < r.IntN(42); i++ { addr += r.IntN(42 * 42) diff --git a/testsupport/io.go b/testsupport/io.go index 4bee06c3..9482a0d6 100644 --- a/testsupport/io.go +++ b/testsupport/io.go @@ -20,7 +20,7 @@ func ValidateReadAtWrapperTransparency( bufferSize := uint64(len(reference)) // Samples random slices to validate within the file. - r := rand.New(rand.NewPCG(0, 0)) + r := rand.New(rand.NewPCG(0, 0)) //nolint:gosec for i := uint(0); i < iterations; i++ { // Intentionally allow slices that over-read the file to test this case. length := r.Uint64() % bufferSize diff --git a/tracer/probe_linux.go b/tracer/probe_linux.go index afd96cf6..e10b39f5 100644 --- a/tracer/probe_linux.go +++ b/tracer/probe_linux.go @@ -52,7 +52,7 @@ func GetCurrentKernelVersion() (major, minor, patch uint32, err error) { if err := unix.Uname(&uname); err != nil { return 0, 0, 0, fmt.Errorf("could not get Kernel Version: %v", err) } - fmt.Fscanf(bytes.NewReader(uname.Release[:]), "%d.%d.%d", &major, &minor, &patch) + _, _ = fmt.Fscanf(bytes.NewReader(uname.Release[:]), "%d.%d.%d", &major, &minor, &patch) return major, minor, patch, nil }