a86bda490b
The golangci-lint being used was quite dated. This change upgrades to the latest version. Adds and updates exclusions based on new failures. Note on revive: I've included an opt-out for unused parameters for revive because turning `newThing(required bool)` to `newThing(_ bool)` is a loss of useful information. The changes to the Go files are to fix the following issues: ``` camelcase.go:16: File is not `gofmt`-ed with `-s` (gofmt) config_test.go:50:18: directive `//nolint: gosec` is unused for linter "gosec" (nolintlint) defaults_test.go:28:25: G601: Implicit memory aliasing in for loop. (gosec) doc.go:5: File is not `gofmt`-ed with `-s` (gofmt) kong.go:446:18: directive `//nolint: gosec` is unused for linter "gosec" (nolintlint) kong_test.go:503:20: G601: Implicit memory aliasing in for loop. (gosec) model.go:493:10: composites: reflect.ValueError struct literal uses unkeyed fields (govet) scanner.go:112: File is not `gofmt`-ed with `-s` (gofmt) ``` And to address broken nolint directives reported as follows by golangci-lint. ``` [.. skipped .. ] tag.go:65:1: directive `// nolint:gocyclo` should be written without leading space as `//nolint:gocyclo` (nolintlint) tag.go:206:51: directive `// nolint: gocyclo` should be written without leading space as `//nolint: gocyclo` (nolintlint) util_test.go:23:43: directive `// nolint: errcheck` should be written without leading space as `//nolint: errcheck` (nolintlint) util_test.go:51:22: directive `// nolint: errcheck` should be written without leading space as `//nolint: errcheck` (nolintlint) ```
43 lines
893 B
Go
43 lines
893 B
Go
//go:build (!appengine && linux) || freebsd || darwin || dragonfly || netbsd || openbsd
|
|
// +build !appengine,linux freebsd darwin dragonfly netbsd openbsd
|
|
|
|
package kong
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"strconv"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
func guessWidth(w io.Writer) int {
|
|
// check if COLUMNS env is set to comply with
|
|
// http://pubs.opengroup.org/onlinepubs/009604499/basedefs/xbd_chap08.html
|
|
colsStr := os.Getenv("COLUMNS")
|
|
if colsStr != "" {
|
|
if cols, err := strconv.Atoi(colsStr); err == nil {
|
|
return cols
|
|
}
|
|
}
|
|
|
|
if t, ok := w.(*os.File); ok {
|
|
fd := t.Fd()
|
|
var dimensions [4]uint16
|
|
|
|
if _, _, err := syscall.Syscall6(
|
|
syscall.SYS_IOCTL,
|
|
uintptr(fd), //nolint: unconvert
|
|
uintptr(syscall.TIOCGWINSZ),
|
|
uintptr(unsafe.Pointer(&dimensions)), //nolint: gas
|
|
0, 0, 0,
|
|
); err == 0 {
|
|
if dimensions[1] == 0 {
|
|
return 80
|
|
}
|
|
return int(dimensions[1])
|
|
}
|
|
}
|
|
return 80
|
|
}
|