Skip to content

Commit

Permalink
Update to golangci-lint 1.59.1 (open-telemetry#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
rockdaboot authored Aug 1, 2024
1 parent a0b8ba4 commit 800e249
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 54 deletions.
1 change: 0 additions & 1 deletion .github/workflows/unit-test-on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 12 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -53,27 +54,24 @@ 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
- nlreturn
- noctx # might be worth fixing
- nolintlint
- nonamedreturns
- nosnakecase
- paralleltest
- protogetter
- scopelint # might be worth fixing
- sqlclosecheck # might be worth fixing
- tagalign
- tagliatelle
Expand All @@ -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:
Expand Down Expand Up @@ -127,7 +118,6 @@ linters-settings:
min-complexity: 15
govet:
enable-all: true
check-shadowing: true
disable:
- fieldalignment
settings:
Expand All @@ -143,7 +133,7 @@ linters-settings:
lll:
line-length: 100
tab-width: 4
maligned:
suggest-new: true
misspell:
locale: US
ignore-words:
- rela
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) ./...
Expand Down
4 changes: 2 additions & 2 deletions interpreter/perl/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 10 additions & 10 deletions libpf/basehash/hash128.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions libpf/convenience.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
23 changes: 8 additions & 15 deletions libpf/pfelf/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion processmanager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion testsupport/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tracer/probe_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 800e249

Please sign in to comment.