From 1888df8bdcb7c20c1b078e4c14f38df53c3980c0 Mon Sep 17 00:00:00 2001 From: Rory <16801068+Rory-Z@users.noreply.github.com> Date: Tue, 17 Oct 2023 14:40:01 +0800 Subject: [PATCH] ci: more better golang lint check (#62) Signed-off-by: Rory Z <16801068+Rory-Z@users.noreply.github.com> --- .golangci.yml | 24 +++++++++--------- collector/collector.go | 46 ----------------------------------- config/example/config.yaml | 2 +- main_test.go | 2 +- scripts/errcheck_excludes.txt | 4 --- 5 files changed, 14 insertions(+), 64 deletions(-) delete mode 100644 scripts/errcheck_excludes.txt diff --git a/.golangci.yml b/.golangci.yml index d0cf039..5981280 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,18 +1,18 @@ linters: enable: + - misspell - revive - disable: - - deadcode - - unused - - structcheck - - varcheck - -issues: - exclude-rules: - - path: _test.go - linters: - - errcheck linters-settings: errcheck: - exclude: scripts/errcheck_excludes.txt + exclude-functions: + # Used in HTTP handlers, any error is handled by the server itself. + - (net/http.ResponseWriter).Write + # Never check for logger errors. + - (github.com/go-kit/log.Logger).Log + revive: + rules: + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter + - name: unused-parameter + severity: warning + disabled: true diff --git a/collector/collector.go b/collector/collector.go index 11a5a26..967f4cc 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -121,49 +121,3 @@ var ErrNoData = errors.New("collector returned no data") func IsNoDataError(err error) bool { return err == ErrNoData } - -// pushMetric helps construct and convert a variety of value types into Prometheus float64 metrics. -func pushMetric(ch chan<- prometheus.Metric, fieldDesc *prometheus.Desc, name string, value interface{}, valueType prometheus.ValueType, labelValues ...string) { - var fVal float64 - switch val := value.(type) { - case uint8: - fVal = float64(val) - case uint16: - fVal = float64(val) - case uint32: - fVal = float64(val) - case uint64: - fVal = float64(val) - case int64: - fVal = float64(val) - case *uint8: - if val == nil { - return - } - fVal = float64(*val) - case *uint16: - if val == nil { - return - } - fVal = float64(*val) - case *uint32: - if val == nil { - return - } - fVal = float64(*val) - case *uint64: - if val == nil { - return - } - fVal = float64(*val) - case *int64: - if val == nil { - return - } - fVal = float64(*val) - default: - return - } - - ch <- prometheus.MustNewConstMetric(fieldDesc, valueType, fVal, labelValues...) -} diff --git a/config/example/config.yaml b/config/example/config.yaml index c338c1d..6ee2cf6 100644 --- a/config/example/config.yaml +++ b/config/example/config.yaml @@ -12,4 +12,4 @@ probes: username: password: topic: - qos: \ No newline at end of file + qos: diff --git a/main_test.go b/main_test.go index d0fb216..400f39b 100644 --- a/main_test.go +++ b/main_test.go @@ -148,7 +148,7 @@ func runCommandAndTests(cmd *exec.Cmd, address string, fn func(pid int) error) e err := <-errc if cmd.Process != nil { - cmd.Process.Kill() + _ = cmd.Process.Kill() } return err } diff --git a/scripts/errcheck_excludes.txt b/scripts/errcheck_excludes.txt deleted file mode 100644 index 14b824f..0000000 --- a/scripts/errcheck_excludes.txt +++ /dev/null @@ -1,4 +0,0 @@ -// Used in HTTP handlers, any error is handled by the server itself. -(net/http.ResponseWriter).Write -// Never check for logger errors. -(github.com/go-kit/log.Logger).Log