chore: enable staticcheck linter

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
pull/1842/head
Matthieu MOREL 2 months ago
parent 3ba33b4651
commit cefed48244

@ -29,13 +29,13 @@ linters:
- perfsprint - perfsprint
- predeclared - predeclared
- revive - revive
- staticcheck
- testifylint - testifylint
- thelper - thelper
- unparam - unparam
- usetesting - usetesting
disable: disable:
- errcheck - errcheck
- staticcheck
- unused - unused
settings: settings:
gocritic: gocritic:
@ -112,6 +112,18 @@ linters:
- ["ID"] # AllowList - ["ID"] # AllowList
- ["VM"] # DenyList - ["VM"] # DenyList
- - upperCaseConst: true # Extra parameter (upperCaseConst|skipPackageNameChecks) - - upperCaseConst: true # Extra parameter (upperCaseConst|skipPackageNameChecks)
staticcheck:
checks:
- all
- -SA1019 # Using a deprecated function, variable, constant or field
- -SA2002 # Called testing.T.FailNow or SkipNow in a goroutine, which isnt allowed
- -SA4003 # Comparing unsigned values against negative values is pointless
- -SA4004 # The loop exits unconditionally after one iteration
- -SA4008 # The variable in the loop condition never changes, are you incrementing the wrong variable?
- -SA5003 # Defers in infinite loops will never execute
- -SA9003 # Empty body in an if or else branch
- -ST1003 # Poorly chosen identifier
- -ST1005 # Incorrectly formatted error string
testifylint: testifylint:
enable-all: true enable-all: true
usetesting: usetesting:

@ -51,7 +51,7 @@ func getFrequency() (float64, error) {
var pCoreHz uint32 var pCoreHz uint32
for { for {
service := ioIteratorNext(iterator) service := ioIteratorNext(iterator)
if !(service > 0) { if service <= 0 {
break break
} }

@ -159,10 +159,7 @@ func parseISAInfo(cmdOutput string) ([]string, error) {
return nil, errors.New("attempted to parse invalid isainfo output") return nil, errors.New("attempted to parse invalid isainfo output")
} }
flags := make([]string, len(words)-4) flags := words[4:]
for i, val := range words[4:] { //nolint:gosimple //FIXME
flags[i] = val
}
sort.Strings(flags) sort.Strings(flags)
return flags, nil return flags, nil

@ -201,7 +201,7 @@ func IOCountersWithContext(_ context.Context, names ...string) (map[string]IOCou
stats := make([]IOCountersStat, 0, 16) stats := make([]IOCountersStat, 0, 16)
for { for {
d := ioIteratorNext(drives) d := ioIteratorNext(drives)
if !(d > 0) { if d <= 0 {
break break
} }

@ -67,8 +67,8 @@ func parseUptime(uptime string) uint64 {
var days, hours, mins uint64 var days, hours, mins uint64
var err error var err error
switch { switch ut[3] {
case ut[3] == "day," || ut[3] == "days,": case "day,", "days,":
days, err = strconv.ParseUint(ut[2], 10, 64) days, err = strconv.ParseUint(ut[2], 10, 64)
if err != nil { if err != nil {
return 0 return 0
@ -105,12 +105,12 @@ func parseUptime(uptime string) uint64 {
return 0 return 0
} }
} }
case ut[3] == "hr," || ut[3] == "hrs,": case "hr,", "hrs,":
hours, err = strconv.ParseUint(ut[2], 10, 64) hours, err = strconv.ParseUint(ut[2], 10, 64)
if err != nil { if err != nil {
return 0 return 0
} }
case ut[3] == "min," || ut[3] == "mins,": case "min,", "mins,":
mins, err = strconv.ParseUint(ut[2], 10, 64) mins, err = strconv.ParseUint(ut[2], 10, 64)
if err != nil { if err != nil {
return 0 return 0

@ -67,8 +67,7 @@ func UsersWithContext(_ context.Context) ([]UserStat, error) {
// Skip macOS utmpx header part // Skip macOS utmpx header part
buf = buf[604:] buf = buf[604:]
u := Utmpx{} entrySize := int(unsafe.Sizeof(Utmpx{}))
entrySize := int(unsafe.Sizeof(u))
count := len(buf) / entrySize count := len(buf) / entrySize
for i := 0; i < count; i++ { for i := 0; i < count; i++ {

@ -117,8 +117,7 @@ func getUsersFromUtmp(utmpfile string) ([]UserStat, error) {
return ret, err return ret, err
} }
u := Utmp{} entrySize := int(unsafe.Sizeof(Utmp{}))
entrySize := int(unsafe.Sizeof(u))
count := len(buf) / entrySize count := len(buf) / entrySize
for i := 0; i < count; i++ { for i := 0; i < count; i++ {

@ -71,8 +71,7 @@ func UsersWithContext(_ context.Context) ([]UserStat, error) {
return ret, err return ret, err
} }
u := Utmp{} entrySize := int(unsafe.Sizeof(Utmp{}))
entrySize := int(unsafe.Sizeof(u))
count := len(buf) / entrySize count := len(buf) / entrySize
for i := 0; i < count; i++ { for i := 0; i < count; i++ {

@ -393,10 +393,7 @@ func GoString(cStr *byte) string {
return "" return ""
} }
var length int var length int
for { for *(*byte)(unsafe.Add(unsafe.Pointer(cStr), uintptr(length))) != '\x00' {
if *(*byte)(unsafe.Add(unsafe.Pointer(cStr), uintptr(length))) == '\x00' {
break
}
length++ length++
} }
return string(unsafe.Slice(cStr, length)) return string(unsafe.Slice(cStr, length))

@ -296,7 +296,7 @@ func ConnectionsWithContext(ctx context.Context, kind string) ([]ConnectionStat,
} }
lines := strings.Split(string(out), "\n") lines := strings.Split(string(out), "\n")
for _, line := range lines { for _, line := range lines {
if !(strings.HasPrefix(line, "tcp") || strings.HasPrefix(line, "udp")) { if !strings.HasPrefix(line, "tcp") && !strings.HasPrefix(line, "udp") {
continue continue
} }
n, err := parseNetstatLine(line) n, err := parseNetstatLine(line)

@ -594,7 +594,7 @@ func (p *Process) NumThreadsWithContext(_ context.Context) (int32, error) {
// if no errors and not cached already, cache ppid // if no errors and not cached already, cache ppid
p.parent = ppid p.parent = ppid
if 0 == p.getPpid() { if p.getPpid() == 0 {
p.setPpid(ppid) p.setPpid(ppid)
} }

Loading…
Cancel
Save