From 239846f6883d3ef30e9c69d89dc6a2676cf8395e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=BBak?= Date: Mon, 23 Oct 2023 16:12:08 +0200 Subject: [PATCH] chore(tools): Bump golangci-lint from v1.54.2 to v1.55.0 (#14155) (cherry picked from commit 171dccb7d77938bf061735406e7cf321063a8f71) --- .circleci/config.yml | 2 +- Makefile | 2 +- plugins/inputs/aerospike/aerospike.go | 5 ++--- plugins/inputs/chrony/chrony_test.go | 14 +++++++------- plugins/inputs/csgo/csgo.go | 3 +-- plugins/inputs/dcos/dcos.go | 5 ++--- plugins/inputs/disk/disk.go | 3 +-- plugins/inputs/ipmi_sensor/ipmi_sensor_test.go | 10 ++++------ plugins/inputs/kube_inventory/kube_inventory.go | 4 ++-- plugins/inputs/monit/monit.go | 3 +-- plugins/inputs/procstat/procstat.go | 16 ++++++++-------- plugins/inputs/sensors/sensors_test.go | 6 +++--- plugins/inputs/snmp/snmp.go | 3 +-- plugins/inputs/statsd/running_stats.go | 3 +-- plugins/inputs/win_eventlog/util.go | 2 +- plugins/outputs/opentsdb/opentsdb.go | 3 +-- plugins/parsers/influx/escape.go | 3 +-- 17 files changed, 38 insertions(+), 49 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ac6ee4fe6e482..318e1e8b270f6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -66,7 +66,7 @@ commands: - run: 'sh ./scripts/installgo_windows.sh' - run: choco install mingw --version=12.2.0.03042023 - run: go env - - run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2 + - run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.0 - when: condition: equal: [ linux, << parameters.os >> ] diff --git a/Makefile b/Makefile index bd50f7bb0eb2a..97804e0f26f7c 100644 --- a/Makefile +++ b/Makefile @@ -174,7 +174,7 @@ vet: .PHONY: lint-install lint-install: @echo "Installing golangci-lint" - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.0 @echo "Installing markdownlint" npm install -g markdownlint-cli diff --git a/plugins/inputs/aerospike/aerospike.go b/plugins/inputs/aerospike/aerospike.go index 71342f393404e..35714a3e3c4d2 100644 --- a/plugins/inputs/aerospike/aerospike.go +++ b/plugins/inputs/aerospike/aerospike.go @@ -438,10 +438,9 @@ func parseAerospikeValue(key string, v string) interface{} { return parsed } else if parsed, err := strconv.ParseFloat(v, 32); err == nil { return parsed - } else { - // leave as string - return v } + // leave as string + return v } func createTags(hostPort string, nodeName string, namespace string, set string) map[string]string { diff --git a/plugins/inputs/chrony/chrony_test.go b/plugins/inputs/chrony/chrony_test.go index 6e9b185b2b4b3..050ca9259db1f 100644 --- a/plugins/inputs/chrony/chrony_test.go +++ b/plugins/inputs/chrony/chrony_test.go @@ -96,17 +96,17 @@ Leap status : Not synchronized // /tmp/go-build970079519/…/_test/integration.test -test.run=TestHelperProcess -- cmd, args := args[3], args[4:] - if cmd == "chronyc" { - if args[0] == "tracking" { - fmt.Fprint(os.Stdout, lookup+mockData) - } else { - fmt.Fprint(os.Stdout, noLookup+mockData) - } - } else { + if cmd != "chronyc" { fmt.Fprint(os.Stdout, "command not found") //nolint:revive // error code is important for this "test" os.Exit(1) } + if args[0] == "tracking" { + fmt.Fprint(os.Stdout, lookup+mockData) + } else { + fmt.Fprint(os.Stdout, noLookup+mockData) + } + //nolint:revive // error code is important for this "test" os.Exit(0) } diff --git a/plugins/inputs/csgo/csgo.go b/plugins/inputs/csgo/csgo.go index 99343ca504175..9c37d1f10c791 100644 --- a/plugins/inputs/csgo/csgo.go +++ b/plugins/inputs/csgo/csgo.go @@ -177,7 +177,6 @@ func requestServer(url string, rconPw string) (string, error) { return "", err } else if reqID != respReqID { return "", errors.New("response/request mismatch") - } else { - return resp, nil } + return resp, nil } diff --git a/plugins/inputs/dcos/dcos.go b/plugins/inputs/dcos/dcos.go index 776134bd0e293..97bfbd16bd546 100644 --- a/plugins/inputs/dcos/dcos.go +++ b/plugins/inputs/dcos/dcos.go @@ -349,10 +349,9 @@ func (d *DCOS) createCredentials() (Credentials, error) { Path: d.TokenFile, } return creds, nil - } else { - creds := &NullCreds{} - return creds, nil } + + return &NullCreds{}, nil } func (d *DCOS) createFilters() error { diff --git a/plugins/inputs/disk/disk.go b/plugins/inputs/disk/disk.go index 81251d3f3eee2..71405840d3e75 100644 --- a/plugins/inputs/disk/disk.go +++ b/plugins/inputs/disk/disk.go @@ -97,9 +97,8 @@ func (opts MountOptions) Mode() string { return "rw" } else if opts.exists("ro") { return "ro" - } else { - return "unknown" } + return "unknown" } func (opts MountOptions) exists(opt string) bool { diff --git a/plugins/inputs/ipmi_sensor/ipmi_sensor_test.go b/plugins/inputs/ipmi_sensor/ipmi_sensor_test.go index fcba6bb6b276d..b5662f0c474f2 100644 --- a/plugins/inputs/ipmi_sensor/ipmi_sensor_test.go +++ b/plugins/inputs/ipmi_sensor/ipmi_sensor_test.go @@ -375,13 +375,12 @@ OS RealTime Mod | 0x00 | ok cmd := args[3] // Ignore the returned errors for the mocked interface as tests will fail anyway - if cmd == "ipmitool" { - fmt.Fprint(os.Stdout, mockData) - } else { + if cmd != "ipmitool" { fmt.Fprint(os.Stdout, "command not found") //nolint:revive // error code is important for this "test" os.Exit(1) } + fmt.Fprint(os.Stdout, mockData) //nolint:revive // error code is important for this "test" os.Exit(0) } @@ -573,13 +572,12 @@ Power Supply 1 | 03h | ok | 10.1 | 110 Watts, Presence detected cmd := args[3] // Ignore the returned errors for the mocked interface as tests will fail anyway - if cmd == "ipmitool" { - fmt.Fprint(os.Stdout, mockData) - } else { + if cmd != "ipmitool" { fmt.Fprint(os.Stdout, "command not found") //nolint:revive // error code is important for this "test" os.Exit(1) } + fmt.Fprint(os.Stdout, mockData) //nolint:revive // error code is important for this "test" os.Exit(0) } diff --git a/plugins/inputs/kube_inventory/kube_inventory.go b/plugins/inputs/kube_inventory/kube_inventory.go index d900a7e906ab2..5b4758177c283 100644 --- a/plugins/inputs/kube_inventory/kube_inventory.go +++ b/plugins/inputs/kube_inventory/kube_inventory.go @@ -158,10 +158,10 @@ const ( nodeMeasurement = "kubernetes_node" persistentVolumeMeasurement = "kubernetes_persistentvolume" persistentVolumeClaimMeasurement = "kubernetes_persistentvolumeclaim" - podContainerMeasurement = "kubernetes_pod_container" //nolint:gosec // G101: Potential hardcoded credentials - false positive + podContainerMeasurement = "kubernetes_pod_container" serviceMeasurement = "kubernetes_service" statefulSetMeasurement = "kubernetes_statefulset" - resourcequotaMeasurement = "kubernetes_resourcequota" //nolint:gosec // G101: Potential hardcoded credentials - false positive + resourcequotaMeasurement = "kubernetes_resourcequota" certificateMeasurement = "kubernetes_certificate" ) diff --git a/plugins/inputs/monit/monit.go b/plugins/inputs/monit/monit.go index d4606fd3438a9..0d53151430162 100644 --- a/plugins/inputs/monit/monit.go +++ b/plugins/inputs/monit/monit.go @@ -338,9 +338,8 @@ func linkMode(s Service) string { return "duplex" } else if s.Link.Duplex == 0 { return "simplex" - } else { - return "unknown" } + return "unknown" } func serviceStatus(s Service) string { diff --git a/plugins/inputs/procstat/procstat.go b/plugins/inputs/procstat/procstat.go index 3ee3c1f3a2c08..eb475c7e4c528 100644 --- a/plugins/inputs/procstat/procstat.go +++ b/plugins/inputs/procstat/procstat.go @@ -351,16 +351,16 @@ func (p *Procstat) findPids() []PidsTags { } else if p.CGroup != "" { groups := p.cgroupPIDs() return groups - } else { - f, err := p.getPIDFinder() - if err != nil { - pidTags = append(pidTags, PidsTags{nil, nil, err}) - return pidTags - } - pids, tags, err := p.SimpleFindPids(f) - pidTags = append(pidTags, PidsTags{pids, tags, err}) } + f, err := p.getPIDFinder() + if err != nil { + pidTags = append(pidTags, PidsTags{nil, nil, err}) + return pidTags + } + pids, tags, err := p.SimpleFindPids(f) + pidTags = append(pidTags, PidsTags{pids, tags, err}) + return pidTags } diff --git a/plugins/inputs/sensors/sensors_test.go b/plugins/inputs/sensors/sensors_test.go index 947aa6c11f825..47b8e8cbbce70 100644 --- a/plugins/inputs/sensors/sensors_test.go +++ b/plugins/inputs/sensors/sensors_test.go @@ -370,13 +370,13 @@ Vcore Voltage: // /tmp/go-build970079519/…/_test/integration.test -test.run=TestHelperProcess -- cmd, _ := args[3], args[4:] - if cmd == "sensors" { - fmt.Fprint(os.Stdout, mockData) - } else { + if cmd != "sensors" { fmt.Fprint(os.Stdout, "command not found") //nolint:revive // error code is important for this "test" os.Exit(1) } + + fmt.Fprint(os.Stdout, mockData) //nolint:revive // error code is important for this "test" os.Exit(0) } diff --git a/plugins/inputs/snmp/snmp.go b/plugins/inputs/snmp/snmp.go index 009d65ba86e7c..d037a9f80d2ce 100644 --- a/plugins/inputs/snmp/snmp.go +++ b/plugins/inputs/snmp/snmp.go @@ -425,9 +425,8 @@ func (t Table) Build(gs snmpConnection, walk bool, tr Translator) (*RTable, erro return nil, fmt.Errorf("wrong digest (auth_protocol, auth_password)") } else if errors.Is(err, gosnmp.ErrDecryption) { return nil, fmt.Errorf("decryption error (priv_protocol, priv_password)") - } else { - return nil, fmt.Errorf("performing get on field %s: %w", f.Name, err) } + return nil, fmt.Errorf("performing get on field %s: %w", f.Name, err) } else if pkt != nil && len(pkt.Variables) > 0 && pkt.Variables[0].Type != gosnmp.NoSuchObject && pkt.Variables[0].Type != gosnmp.NoSuchInstance { ent := pkt.Variables[0] fv, err := fieldConvert(tr, f.Conversion, ent) diff --git a/plugins/inputs/statsd/running_stats.go b/plugins/inputs/statsd/running_stats.go index ba49311566599..f5bdeb7d609e5 100644 --- a/plugins/inputs/statsd/running_stats.go +++ b/plugins/inputs/statsd/running_stats.go @@ -107,9 +107,8 @@ func (rs *RunningStats) Median() float64 { return 0 } else if count%2 == 0 { return (values[count/2-1] + values[count/2]) / 2 - } else { - return values[count/2] } + return values[count/2] } func (rs *RunningStats) Variance() float64 { diff --git a/plugins/inputs/win_eventlog/util.go b/plugins/inputs/win_eventlog/util.go index 054592db5cd5f..521502cf900a6 100644 --- a/plugins/inputs/win_eventlog/util.go +++ b/plugins/inputs/win_eventlog/util.go @@ -49,7 +49,7 @@ func GetFromSnapProcess(pid uint32) (string, error) { } defer windows.CloseHandle(snap) var pe32 windows.ProcessEntry32 - pe32.Size = uint32(unsafe.Sizeof(pe32)) //nolint:gosec // G103: Valid use of unsafe call to determine the size of the struct + pe32.Size = uint32(unsafe.Sizeof(pe32)) if err := windows.Process32First(snap, &pe32); err != nil { return "", err } diff --git a/plugins/outputs/opentsdb/opentsdb.go b/plugins/outputs/opentsdb/opentsdb.go index ed1a8b969051c..e4b7842e03f8e 100644 --- a/plugins/outputs/opentsdb/opentsdb.go +++ b/plugins/outputs/opentsdb/opentsdb.go @@ -97,9 +97,8 @@ func (o *OpenTSDB) Write(metrics []telegraf.Metric) error { return o.WriteTelnet(metrics, u) } else if u.Scheme == "http" || u.Scheme == "https" { return o.WriteHTTP(metrics, u) - } else { - return fmt.Errorf("unknown scheme in host parameter") } + return fmt.Errorf("unknown scheme in host parameter") } func (o *OpenTSDB) WriteHTTP(metrics []telegraf.Metric, u *url.URL) error { diff --git a/plugins/parsers/influx/escape.go b/plugins/parsers/influx/escape.go index 671a88955aa6a..8d50dcea5c5b3 100644 --- a/plugins/parsers/influx/escape.go +++ b/plugins/parsers/influx/escape.go @@ -77,8 +77,7 @@ func parseBoolBytes(b []byte) (bool, error) { } // unsafeBytesToString converts a []byte to a string without a heap allocation. -// -// It is unsafe, and is intended to prepare input to short-lived functions that require strings. func unsafeBytesToString(in []byte) string { + //nolint:gosec // G103: It is unsafe, and is intended to prepare input to short-lived functions that require strings. return unsafe.String(&in[0], len(in)) }