chore: Upgrade golangci-lint to v2 (#3303)

* chore: Upgrade golangci-lint to v2

- Migrate the configuration file
- Update the tooling version and CI
- Apply auto-fixes

Signed-off-by: Kemal Akkoyun <kemal.akkoyun@datadoghq.com>

* chore: Upgrade golangci-lint to v2

- Migrate the configuration file
- Update the tooling version and CI
- Apply auto-fixes

Signed-off-by: Kemal Akkoyun <kemal.akkoyun@datadoghq.com>

---------

Signed-off-by: Kemal Akkoyun <kemal.akkoyun@datadoghq.com>
pull/3416/head
Kemal Akkoyun 4 months ago committed by GitHub
parent 5fcd80addc
commit 18f95ce16a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      .github/workflows/golangci-lint.yml
  2. 66
      .golangci.yml
  3. 2
      Makefile.common
  4. 3
      collector/boot_time_bsd.go
  5. 2
      collector/cpu_linux.go
  6. 2
      collector/perf_linux_test.go

@ -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

@ -1,32 +1,48 @@
version: "2"
linters:
enable:
- depguard
- goimports
- misspell
- revive
issues:
exclude-rules:
- path: _test.go
linters:
- errcheck
linters-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:
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:
# Used in HTTP handlers, any error is handled by the server itself.
- (net/http.ResponseWriter).Write
revive:
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:
# 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$

@ -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))

@ -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 {

@ -89,7 +89,7 @@ func NewCPUCollector(logger *slog.Logger) (Collector, error) {
if !os.IsNotExist(err) {
return nil, fmt.Errorf("unable to get isolated cpus: %w", err)
}
logger.Debug("Could not open isolated file", "error", err)
logger.Debug("couldn't open isolated file", "error", err)
}
c := &cpuCollector{

@ -36,7 +36,7 @@ func canTestPerf(t *testing.T) {
paranoidStr := strings.ReplaceAll(string(paranoidBytes), "\n", "")
paranoid, err := strconv.Atoi(paranoidStr)
if err != nil {
t.Fatalf("Expected perf_event_paranoid to be an int, got: %s", paranoidStr)
t.Fatalf("expected perf_event_paranoid to be an int, got: %s", paranoidStr)
}
if paranoid >= 1 {
t.Skip("Skipping perf tests, set perf_event_paranoid to 0")

Loading…
Cancel
Save