diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 5342cbe0..3893ef86 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -33,7 +33,7 @@ jobs: run: sudo apt-get update && sudo apt-get -y install libsnmp-dev if: github.repository == 'prometheus/snmp_exporter' - name: Lint - uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2 + uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0 with: args: --verbose - version: v1.64.6 + version: v2.0.2 diff --git a/.golangci.yml b/.golangci.yml index 8731aefd..0df1b35a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,32 +1,47 @@ +version: "2" linters: enable: - depguard - - goimports - misspell - revive - -issues: - exclude-rules: - - path: _test.go - linters: - - errcheck - -linters-settings: - depguard: + settings: + depguard: + rules: + no_exec_policy: + files: + - '!$test' + deny: + - pkg: os/exec + desc: Using os/exec to run sub processes it not allowed by policy + errcheck: + exclude-functions: + - (net/http.ResponseWriter).Write + revive: + rules: + - name: unused-parameter + severity: warning + disabled: true + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling rules: - no_exec_policy: - files: - - "!$test" - deny: - - pkg: "os/exec" - desc: "Using os/exec to run sub processes it not allowed by policy" - errcheck: - exclude-functions: - # Used in HTTP handlers, any error is handled by the server itself. - - (net/http.ResponseWriter).Write - revive: - rules: - # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter - - name: unused-parameter - severity: warning - disabled: true + - linters: + - errcheck + path: _test.go + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile.common b/Makefile.common index 8cb38385..81bad5f4 100644 --- a/Makefile.common +++ b/Makefile.common @@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_ SKIP_GOLANGCI_LINT := GOLANGCI_LINT := GOLANGCI_LINT_OPTS ?= -GOLANGCI_LINT_VERSION ?= v1.64.6 +GOLANGCI_LINT_VERSION ?= v2.0.2 # golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64. # windows isn't included here because of the path separator being different. ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin)) diff --git a/collector/boot_time_bsd.go b/collector/boot_time_bsd.go index d632fef0..49b4145c 100644 --- a/collector/boot_time_bsd.go +++ b/collector/boot_time_bsd.go @@ -18,9 +18,10 @@ package collector import ( + "log/slog" + "github.com/prometheus/client_golang/prometheus" "golang.org/x/sys/unix" - "log/slog" ) type bootTimeCollector struct { diff --git a/collector/meminfo_darwin.go b/collector/meminfo_darwin.go index b5b10b4b..26a6a1ac 100644 --- a/collector/meminfo_darwin.go +++ b/collector/meminfo_darwin.go @@ -52,7 +52,7 @@ func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { &infoCount, ) if ret != C.KERN_SUCCESS { - return nil, fmt.Errorf("Couldn't get memory statistics, host_statistics returned %d", ret) + return nil, fmt.Errorf("couldn't get memory statistics, host_statistics returned %d", ret) } totalb, err := unix.Sysctl("hw.memsize") if err != nil { diff --git a/node_exporter.go b/node_exporter.go index 88441e1e..22939cbc 100644 --- a/node_exporter.go +++ b/node_exporter.go @@ -112,7 +112,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if err != nil { h.logger.Warn("Couldn't create filtered metrics handler:", "err", err) w.WriteHeader(http.StatusBadRequest) - w.Write([]byte(fmt.Sprintf("Couldn't create filtered metrics handler: %s", err))) + fmt.Fprintf(w, "Couldn't create filtered metrics handler: %s", err) return } filteredHandler.ServeHTTP(w, r)