Skip to content

Commit b6f046b

Browse files
committed
chore: Upgrade golangci-lint to v2
- Migrate the configuration file - Update the tooling version and CI - Apply auto-fixes Signed-off-by: Kemal Akkoyun <[email protected]>
1 parent 3874acf commit b6f046b

File tree

7 files changed

+69
-54
lines changed

7 files changed

+69
-54
lines changed

.github/workflows/golangci-lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
3434
if: github.repository == 'prometheus/snmp_exporter'
3535
- name: Lint
36-
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
36+
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
3737
with:
3838
args: --verbose
39-
version: v1.64.6
39+
version: v2.0.2

.golangci.yml

+53-39
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,60 @@
1-
issues:
2-
max-issues-per-linter: 0
3-
max-same-issues: 0
1+
version: "2"
42
linters:
53
enable:
6-
- errcheck
74
- errorlint
8-
- gofumpt
9-
- goimports
10-
- gosimple
11-
- govet
12-
- ineffassign
135
- misspell
146
- perfsprint
157
- revive
16-
- staticcheck
178
- testifylint
18-
- unused
19-
linters-settings:
20-
goimports:
21-
local-prefixes: github.com/prometheus/common
22-
perfsprint:
23-
# Optimizes even if it requires an int or uint type cast.
24-
int-conversion: true
25-
# Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
26-
err-error: true
27-
# Optimizes `fmt.Errorf`.
28-
errorf: true
29-
# Optimizes `fmt.Sprintf` with only one argument.
30-
sprintf1: true
31-
# Optimizes into strings concatenation.
32-
strconcat: false
33-
revive:
34-
rules:
35-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
36-
- name: unused-parameter
37-
severity: warning
38-
disabled: true
39-
testifylint:
40-
disable:
41-
- go-require
42-
enable-all: true
43-
formatter:
44-
require-f-funcs: true
45-
run:
46-
timeout: 5m
9+
settings:
10+
perfsprint:
11+
# Optimizes even if it requires an int or uint type cast.
12+
int-conversion: true
13+
# Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
14+
err-error: true
15+
# Optimizes `fmt.Errorf`.
16+
errorf: true
17+
# Optimizes `fmt.Sprintf` with only one argument.
18+
sprintf1: true
19+
# Optimizes into strings concatenation.
20+
strconcat: false
21+
revive:
22+
rules:
23+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
24+
- name: unused-parameter
25+
severity: warning
26+
disabled: true
27+
testifylint:
28+
enable-all: true
29+
disable:
30+
- go-require
31+
formatter:
32+
require-f-funcs: true
33+
exclusions:
34+
generated: lax
35+
presets:
36+
- comments
37+
- common-false-positives
38+
- legacy
39+
- std-error-handling
40+
paths:
41+
- third_party$
42+
- builtin$
43+
- examples$
44+
issues:
45+
max-issues-per-linter: 0
46+
max-same-issues: 0
47+
formatters:
48+
enable:
49+
- gofumpt
50+
- goimports
51+
settings:
52+
goimports:
53+
local-prefixes:
54+
- github.com/prometheus/common
55+
exclusions:
56+
generated: lax
57+
paths:
58+
- third_party$
59+
- builtin$
60+
- examples$

Makefile.common

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
6161
SKIP_GOLANGCI_LINT :=
6262
GOLANGCI_LINT :=
6363
GOLANGCI_LINT_OPTS ?=
64-
GOLANGCI_LINT_VERSION ?= v1.64.6
64+
GOLANGCI_LINT_VERSION ?= v2.0.2
6565
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
6666
# windows isn't included here because of the path separator being different.
6767
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))

config/http_config.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func (u *URL) UnmarshalJSON(data []byte) error {
225225
// MarshalJSON implements the json.Marshaler interface for URL.
226226
func (u URL) MarshalJSON() ([]byte, error) {
227227
if u.URL != nil {
228-
return json.Marshal(u.URL.String())
228+
return json.Marshal(u.String())
229229
}
230230
return []byte("null"), nil
231231
}
@@ -251,7 +251,7 @@ func (o *OAuth2) UnmarshalYAML(unmarshal func(interface{}) error) error {
251251
if err := unmarshal((*plain)(o)); err != nil {
252252
return err
253253
}
254-
return o.ProxyConfig.Validate()
254+
return o.Validate()
255255
}
256256

257257
// UnmarshalJSON implements the json.Marshaler interface for URL.
@@ -260,7 +260,7 @@ func (o *OAuth2) UnmarshalJSON(data []byte) error {
260260
if err := json.Unmarshal(data, (*plain)(o)); err != nil {
261261
return err
262262
}
263-
return o.ProxyConfig.Validate()
263+
return o.Validate()
264264
}
265265

266266
// SetDirectory joins any relative file paths with dir.
@@ -604,8 +604,8 @@ func NewRoundTripperFromConfigWithContext(ctx context.Context, cfg HTTPClientCon
604604
// The only timeout we care about is the configured scrape timeout.
605605
// It is applied on request. So we leave out any timings here.
606606
var rt http.RoundTripper = &http.Transport{
607-
Proxy: cfg.ProxyConfig.Proxy(),
608-
ProxyConnectHeader: cfg.ProxyConfig.GetProxyConnectHeader(),
607+
Proxy: cfg.Proxy(),
608+
ProxyConnectHeader: cfg.GetProxyConnectHeader(),
609609
MaxIdleConns: 20000,
610610
MaxIdleConnsPerHost: 1000, // see https://github.com/golang/go/issues/13801
611611
DisableKeepAlives: !opts.keepAlivesEnabled,
@@ -914,8 +914,8 @@ func (rt *oauth2RoundTripper) newOauth2TokenSource(req *http.Request, secret str
914914
tlsTransport := func(tlsConfig *tls.Config) (http.RoundTripper, error) {
915915
return &http.Transport{
916916
TLSClientConfig: tlsConfig,
917-
Proxy: rt.config.ProxyConfig.Proxy(),
918-
ProxyConnectHeader: rt.config.ProxyConfig.GetProxyConnectHeader(),
917+
Proxy: rt.config.Proxy(),
918+
ProxyConnectHeader: rt.config.GetProxyConnectHeader(),
919919
DisableKeepAlives: !rt.opts.keepAlivesEnabled,
920920
MaxIdleConns: 20,
921921
MaxIdleConnsPerHost: 1, // see https://github.com/golang/go/issues/13801
@@ -1508,7 +1508,7 @@ func (c *ProxyConfig) Proxy() (fn func(*http.Request) (*url.URL, error)) {
15081508
}
15091509
return
15101510
}
1511-
if c.ProxyURL.URL != nil && c.ProxyURL.URL.String() != "" {
1511+
if c.ProxyURL.URL != nil && c.ProxyURL.String() != "" {
15121512
if c.NoProxy == "" {
15131513
c.proxyFunc = http.ProxyURL(c.ProxyURL.URL)
15141514
return

expfmt/text_parse.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ func (p *TextParser) startLabelName() stateFn {
345345
}
346346
// Special summary/histogram treatment. Don't add 'quantile' and 'le'
347347
// labels to 'real' labels.
348-
if !(p.currentMF.GetType() == dto.MetricType_SUMMARY && p.currentLabelPair.GetName() == model.QuantileLabel) &&
349-
!(p.currentMF.GetType() == dto.MetricType_HISTOGRAM && p.currentLabelPair.GetName() == model.BucketLabel) {
348+
if (p.currentMF.GetType() != dto.MetricType_SUMMARY || p.currentLabelPair.GetName() != model.QuantileLabel) &&
349+
(p.currentMF.GetType() != dto.MetricType_HISTOGRAM || p.currentLabelPair.GetName() != model.BucketLabel) {
350350
p.currentLabelPairs = append(p.currentLabelPairs, p.currentLabelPair)
351351
}
352352
// Check for duplicate label names.

model/labels.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ func (ln LabelName) IsValidLegacy() bool {
122122
return false
123123
}
124124
for i, b := range ln {
125-
if !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || (b >= '0' && b <= '9' && i > 0)) {
125+
// TODO: Apply De Morgan's law. Make sure there are tests for this.
126+
if !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || (b >= '0' && b <= '9' && i > 0)) { //nolint:staticcheck
126127
return false
127128
}
128129
}

route/route_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func TestInstrumentations(t *testing.T) {
154154
r, err := http.NewRequest("GET", "http://localhost:9090/foo", nil)
155155
require.NoErrorf(t, err, "Error building test request: %s", err)
156156
c.router.ServeHTTP(nil, r)
157-
require.Equalf(t, len(c.want), len(got), "Unexpected value: want %q, got %q", c.want, got)
157+
require.Lenf(t, got, len(c.want), "Unexpected value: want %q, got %q", c.want, got)
158158
for i, v := range c.want {
159159
require.Equalf(t, v, got[i], "Unexpected value: want %q, got %q", c.want, got)
160160
}

0 commit comments

Comments
 (0)