Skip to content

Commit f7a7883

Browse files
committed
chore: bump golangci-lint to v2.0.2
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 7980594 commit f7a7883

29 files changed

+155
-157
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ jobs:
2626
- name: Checkout repository
2727
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2828
- name: Install Go
29-
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
29+
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
3030
with:
3131
go-version: 1.24.x
3232
- name: Install snmp_exporter/generator dependencies
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

Lines changed: 87 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,97 @@
1-
output:
2-
sort-results: true
3-
1+
formatters:
2+
enable:
3+
- gofumpt
4+
- goimports
5+
settings:
6+
gofumpt:
7+
extra-rules: true
8+
goimports:
9+
local-prefixes:
10+
- github.com/prometheus/alertmanager
11+
issues:
12+
max-issues-per-linter: 0
13+
max-same-issues: 0
414
linters:
515
enable:
616
- depguard
717
- errorlint
818
- godot
9-
- gofumpt
10-
- goimports
1119
- misspell
1220
- revive
13-
- testifylint
1421
- sloglint
15-
16-
issues:
17-
max-issues-per-linter: 0
18-
max-same-issues: 0
19-
exclude-rules:
20-
- path: _test.go
21-
linters:
22-
- errcheck
23-
exclude-files:
24-
# Skip autogenerated files.
25-
- ^.*\.(pb|y)\.go$
26-
22+
- testifylint
23+
exclusions:
24+
generated: strict
25+
presets:
26+
- comments
27+
- common-false-positives
28+
- legacy
29+
- std-error-handling
30+
paths:
31+
# Skip autogenerated files.
32+
- ^.*\.(pb|y)\.go$
33+
rules:
34+
- linters:
35+
- errcheck
36+
path: _test.go
37+
warn-unused: true
38+
settings:
39+
depguard:
40+
rules:
41+
main:
42+
deny:
43+
- pkg: github.com/go-kit/kit/log
44+
desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
45+
- pkg: github.com/pkg/errors
46+
desc: "Use errors or fmt instead of github.com/pkg/errors"
47+
- pkg: github.com/stretchr/testify/assert
48+
desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert"
49+
- pkg: sync/atomic
50+
desc: "Use go.uber.org/atomic instead of sync/atomic"
51+
errcheck:
52+
exclude-functions:
53+
# Don't flag lines such as "io.Copy(io.Discard, resp.Body)".
54+
- io.Copy
55+
# The next two are used in HTTP handlers, any error is handled by the server itself.
56+
- io.WriteString
57+
- (net/http.ResponseWriter).Write
58+
# No need to check for errors on server's shutdown.
59+
- (*net/http.Server).Shutdown
60+
# Never check for rollback errors as Rollback() is called when a previous error was detected.
61+
- (github.com/prometheus/prometheus/storage.Appender).Rollback
62+
godot:
63+
capital: true
64+
exclude:
65+
- "^ ?This file is safe to edit"
66+
- "^ ?scheme value"
67+
period: true
68+
scope: toplevel
69+
revive:
70+
rules:
71+
- name: blank-imports
72+
- name: context-as-argument
73+
- name: error-naming
74+
- name: error-return
75+
- name: error-strings
76+
- name: errorf
77+
- name: exported
78+
arguments:
79+
- disableStutteringCheck
80+
- name: if-return
81+
- name: increment-decrement
82+
- name: indent-error-flow
83+
- name: package-comments
84+
- name: range
85+
- name: receiver-naming
86+
- name: time-naming
87+
- name: unexported-return
88+
- name: var-declaration
89+
- name: var-naming
90+
testifylint:
91+
disable:
92+
- float-compare
93+
- go-require
94+
enable-all: true
2795
run:
2896
timeout: 5m
29-
30-
linters-settings:
31-
depguard:
32-
rules:
33-
main:
34-
deny:
35-
- pkg: sync/atomic
36-
desc: "Use go.uber.org/atomic instead of sync/atomic"
37-
- pkg: github.com/stretchr/testify/assert
38-
desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert"
39-
- pkg: github.com/go-kit/kit/log
40-
desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
41-
- pkg: github.com/pkg/errors
42-
desc: "Use errors or fmt instead of github.com/pkg/errors"
43-
errcheck:
44-
exclude-functions:
45-
# Don't flag lines such as "io.Copy(io.Discard, resp.Body)".
46-
- io.Copy
47-
# The next two are used in HTTP handlers, any error is handled by the server itself.
48-
- io.WriteString
49-
- (net/http.ResponseWriter).Write
50-
# No need to check for errors on server's shutdown.
51-
- (*net/http.Server).Shutdown
52-
# Never check for rollback errors as Rollback() is called when a previous error was detected.
53-
- (github.com/prometheus/prometheus/storage.Appender).Rollback
54-
godot:
55-
scope: toplevel
56-
exclude:
57-
- "^ ?This file is safe to edit"
58-
- "^ ?scheme value"
59-
period: true
60-
capital: true
61-
goimports:
62-
local-prefixes: github.com/prometheus/alertmanager
63-
gofumpt:
64-
extra-rules: true
65-
revive:
66-
rules:
67-
- name: exported
68-
arguments: ["disableStutteringCheck"]
69-
- name: blank-imports
70-
- name: context-as-argument
71-
- name: error-return
72-
- name: error-strings
73-
- name: error-naming
74-
- name: if-return
75-
- name: increment-decrement
76-
- name: var-naming
77-
- name: var-declaration
78-
- name: package-comments
79-
- name: range
80-
- name: receiver-naming
81-
- name: time-naming
82-
- name: unexported-return
83-
- name: indent-error-flow
84-
- name: errorf
85-
testifylint:
86-
disable:
87-
- float-compare
88-
- go-require
89-
enable:
90-
- bool-compare
91-
- compares
92-
- empty
93-
- error-is-as
94-
- error-nil
95-
- expected-actual
96-
- len
97-
- require-error
98-
- suite-dont-use-pkg
99-
- suite-extra-assert-call
97+
version: "2"

Makefile.common

Lines changed: 1 addition & 1 deletion
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))

api/v2/api.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,16 +565,16 @@ func SortSilences(sils open_api_models.GettableSilences) {
565565
}
566566
switch state1 {
567567
case types.SilenceStateActive:
568-
endsAt1 := time.Time(*sils[i].Silence.EndsAt)
569-
endsAt2 := time.Time(*sils[j].Silence.EndsAt)
568+
endsAt1 := time.Time(*sils[i].EndsAt)
569+
endsAt2 := time.Time(*sils[j].EndsAt)
570570
return endsAt1.Before(endsAt2)
571571
case types.SilenceStatePending:
572-
startsAt1 := time.Time(*sils[i].Silence.StartsAt)
573-
startsAt2 := time.Time(*sils[j].Silence.StartsAt)
572+
startsAt1 := time.Time(*sils[i].StartsAt)
573+
startsAt2 := time.Time(*sils[j].StartsAt)
574574
return startsAt1.Before(startsAt2)
575575
case types.SilenceStateExpired:
576-
endsAt1 := time.Time(*sils[i].Silence.EndsAt)
577-
endsAt2 := time.Time(*sils[j].Silence.EndsAt)
576+
endsAt1 := time.Time(*sils[i].EndsAt)
577+
endsAt2 := time.Time(*sils[j].EndsAt)
578578
return endsAt1.After(endsAt2)
579579
}
580580
return false

cli/format/format_extended.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ func (formatter *ExtendedFormatter) FormatSilences(silences []models.GettableSil
4848
"%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n",
4949
*silence.ID,
5050
extendedFormatMatchers(silence.Matchers),
51-
FormatDate(*silence.Silence.StartsAt),
52-
FormatDate(*silence.Silence.EndsAt),
51+
FormatDate(*silence.StartsAt),
52+
FormatDate(*silence.EndsAt),
5353
FormatDate(*silence.UpdatedAt),
5454
*silence.CreatedBy,
5555
*silence.Comment,

cli/format/sort.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type ByEndAt []models.GettableSilence
2727
func (s ByEndAt) Len() int { return len(s) }
2828
func (s ByEndAt) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
2929
func (s ByEndAt) Less(i, j int) bool {
30-
return time.Time(*s[i].Silence.EndsAt).Before(time.Time(*s[j].Silence.EndsAt))
30+
return time.Time(*s[i].Silence.EndsAt).Before(time.Time(*s[j].EndsAt))
3131
}
3232

3333
type ByStartsAt []*models.GettableAlert

cluster/cluster_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func testJoinLeave(t *testing.T) {
105105
p2.Leave(0 * time.Second)
106106
require.Equal(t, 1, p.ClusterSize())
107107
require.Len(t, p.failedPeers, 1)
108-
require.Equal(t, p2.Self().Address(), p.peers[p2.Self().Address()].Node.Address())
108+
require.Equal(t, p2.Self().Address(), p.peers[p2.Self().Address()].Address())
109109
require.Equal(t, p2.Name(), p.failedPeers[0].Name)
110110
}
111111

@@ -341,6 +341,6 @@ func testTLSConnection(t *testing.T) {
341341
p2.Leave(0 * time.Second)
342342
require.Equal(t, 1, p1.ClusterSize())
343343
require.Len(t, p1.failedPeers, 1)
344-
require.Equal(t, p2.Self().Address(), p1.peers[p2.Self().Address()].Node.Address())
344+
require.Equal(t, p2.Self().Address(), p1.peers[p2.Self().Address()].Address())
345345
require.Equal(t, p2.Name(), p1.failedPeers[0].Name)
346346
}

cluster/delegate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,19 +236,19 @@ func (d *delegate) MergeRemoteState(buf []byte, _ bool) {
236236
// NotifyJoin is called if a peer joins the cluster.
237237
func (d *delegate) NotifyJoin(n *memberlist.Node) {
238238
d.logger.Debug("NotifyJoin", "node", n.Name, "addr", n.Address())
239-
d.Peer.peerJoin(n)
239+
d.peerJoin(n)
240240
}
241241

242242
// NotifyLeave is called if a peer leaves the cluster.
243243
func (d *delegate) NotifyLeave(n *memberlist.Node) {
244244
d.logger.Debug("NotifyLeave", "node", n.Name, "addr", n.Address())
245-
d.Peer.peerLeave(n)
245+
d.peerLeave(n)
246246
}
247247

248248
// NotifyUpdate is called if a cluster peer gets updated.
249249
func (d *delegate) NotifyUpdate(n *memberlist.Node) {
250250
d.logger.Debug("NotifyUpdate", "node", n.Name, "addr", n.Address())
251-
d.Peer.peerUpdate(n)
251+
d.peerUpdate(n)
252252
}
253253

254254
// NotifyAlive implements the memberlist.AliveDelegate interface.

config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (u *URL) Copy() *URL {
9797
// MarshalYAML implements the yaml.Marshaler interface for URL.
9898
func (u URL) MarshalYAML() (interface{}, error) {
9999
if u.URL != nil {
100-
return u.URL.String(), nil
100+
return u.String(), nil
101101
}
102102
return nil, nil
103103
}
@@ -119,7 +119,7 @@ func (u *URL) UnmarshalYAML(unmarshal func(interface{}) error) error {
119119
// MarshalJSON implements the json.Marshaler interface for URL.
120120
func (u URL) MarshalJSON() ([]byte, error) {
121121
if u.URL != nil {
122-
return json.Marshal(u.URL.String())
122+
return json.Marshal(u.String())
123123
}
124124
return []byte("null"), nil
125125
}
@@ -145,7 +145,7 @@ type SecretURL URL
145145
func (s SecretURL) MarshalYAML() (interface{}, error) {
146146
if s.URL != nil {
147147
if MarshalSecretValue {
148-
return s.URL.String(), nil
148+
return s.String(), nil
149149
}
150150
return secretToken, nil
151151
}
@@ -174,7 +174,7 @@ func (s SecretURL) MarshalJSON() ([]byte, error) {
174174
return json.Marshal("")
175175
}
176176
if MarshalSecretValue {
177-
return json.Marshal(s.URL.String())
177+
return json.Marshal(s.String())
178178
}
179179
return json.Marshal(secretToken)
180180
}

config/config_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,15 +818,15 @@ func TestUnmarshalEmptyRegexp(t *testing.T) {
818818
err := json.Unmarshal(b, &re)
819819
require.NoError(t, err)
820820
require.Equal(t, regexp.MustCompile("^(?:)$"), re.Regexp)
821-
require.Equal(t, "", re.original)
821+
require.Empty(t, re.original)
822822
}
823823

824824
{
825825
var re Regexp
826826
err := yaml.Unmarshal(b, &re)
827827
require.NoError(t, err)
828828
require.Equal(t, regexp.MustCompile("^(?:)$"), re.Regexp)
829-
require.Equal(t, "", re.original)
829+
require.Empty(t, re.original)
830830
}
831831
}
832832

@@ -837,15 +837,15 @@ func TestUnmarshalNullRegexp(t *testing.T) {
837837
var re Regexp
838838
err := json.Unmarshal(input, &re)
839839
require.NoError(t, err)
840-
require.Equal(t, "", re.original)
840+
require.Empty(t, re.original)
841841
}
842842

843843
{
844844
var re Regexp
845845
err := yaml.Unmarshal(input, &re) // Interestingly enough, unmarshalling `null` in YAML doesn't even call UnmarshalYAML.
846846
require.NoError(t, err)
847847
require.Nil(t, re.Regexp)
848-
require.Equal(t, "", re.original)
848+
require.Empty(t, re.original)
849849
}
850850
}
851851

featurecontrol/featurecontrol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func NewFlags(logger *slog.Logger, features string) (Flagger, error) {
131131
opts = append(opts, enableAutoGOMAXPROCS())
132132
logger.Warn("Automatically set GOMAXPROCS to match Linux container CPU quota")
133133
default:
134-
return nil, fmt.Errorf("Unknown option '%s' for --enable-feature", feature)
134+
return nil, fmt.Errorf("unknown option '%s' for --enable-feature", feature)
135135
}
136136
}
137137

featurecontrol/featurecontrol_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ func TestFlags(t *testing.T) {
3535
{
3636
name: "with only invalid feature flags",
3737
featureFlags: "somethingsomething",
38-
err: errors.New("Unknown option 'somethingsomething' for --enable-feature"),
38+
err: errors.New("unknown option 'somethingsomething' for --enable-feature"),
3939
},
4040
{
4141
name: "with both, valid and invalid feature flags",
4242
featureFlags: strings.Join([]string{FeatureReceiverNameInMetrics, "somethingbad"}, ","),
43-
err: errors.New("Unknown option 'somethingbad' for --enable-feature"),
43+
err: errors.New("unknown option 'somethingbad' for --enable-feature"),
4444
},
4545
}
4646

0 commit comments

Comments
 (0)