Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6b5a0b5

Browse files
authored
Upgrade golangci-lint to v2 (#1789)
- Migrate the configuration file- Update the tooling version and CI- Apply auto-fixesSigned-off-by: Kemal Akkoyun <kemal.akkoyun@datadoghq.com>
1 parent0162a5b commit6b5a0b5

File tree

10 files changed

+102
-97
lines changed

10 files changed

+102
-97
lines changed

‎.github/workflows/golangci-lint.yml‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 73 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,90 @@
1-
---
2-
run:
3-
timeout:5m
4-
5-
output:
6-
sort-results:true
1+
version:"2"
2+
issues:
3+
max-same-issues:0
74

85
linters:
96
enable:
107
-copyloopvar
118
-depguard
129
-durationcheck
1310
-errorlint
14-
# The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar.
15-
# - exportloopref
16-
-gofmt
17-
-gofumpt
18-
-goimports
19-
-gosimple
20-
-ineffassign
2111
-misspell
2212
-nolintlint
2313
-perfsprint
2414
-predeclared
2515
-revive
26-
-staticcheck
2716
-unconvert
28-
-unused
2917
-usestdlibvars
3018
-wastedassign
19+
exclusions:
20+
generated:lax
21+
presets:
22+
-comments
23+
-common-false-positives
24+
-legacy
25+
-std-error-handling
26+
rules:
27+
-linters:
28+
-errcheck
29+
-govet
30+
-structcheck
31+
-nolintlint
32+
path:_test.go
33+
paths:
34+
-^.*\.(pb|y)\.go$
35+
-third_party$
36+
-builtin$
37+
-examples$
38+
settings:
39+
depguard:
40+
rules:
41+
main:
42+
deny:
43+
-pkg:github.com/stretchr/testify/assert
44+
desc:Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert
45+
-pkg:github.com/go-kit/kit/log
46+
desc:Use github.com/go-kit/log instead of github.com/go-kit/kit/log
47+
-pkg:io/ioutil
48+
desc:Use corresponding 'os' or 'io' functions instead.
49+
errcheck:
50+
exclude-functions:
51+
# The following 2 methods always return nil as the error
52+
-(*github.com/cespare/xxhash/v2.Digest).Write
53+
-(*github.com/cespare/xxhash/v2.Digest).WriteString
54+
-(*bufio.Writer).WriteRune
55+
perfsprint:
56+
# Optimizes even if it requires an int or uint type cast.
57+
int-conversion:true
58+
# Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
59+
err-error:true
60+
# Optimizes `fmt.Errorf`.
61+
errorf:true
62+
# Optimizes `fmt.Sprintf` with only one argument.
63+
sprintf1:true
64+
# Optimizes into strings concatenation.
65+
strconcat:true
66+
revive:
67+
rules:
3168

32-
issues:
33-
max-same-issues:0
34-
exclude-rules:
35-
-path:_test.go
36-
linters:
37-
-errcheck
38-
-govet
39-
-structcheck
40-
# The configuration option `run.skip-files` is deprecated, please use `issues.exclude-files`.
41-
exclude-files:
42-
# Skip autogenerated files.
43-
-^.*\.(pb|y)\.go$
69+
-name:unused-parameter
70+
severity:warning
71+
disabled:true
4472

45-
linters-settings:
46-
depguard:
47-
rules:
48-
main:
49-
deny:
50-
#- pkg: "sync/atomic"
51-
# desc: "Use go.uber.org/atomic instead of sync/atomic"
52-
-pkg:"github.com/stretchr/testify/assert"
53-
desc:"Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert"
54-
-pkg:"github.com/go-kit/kit/log"
55-
desc:"Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
56-
-pkg:"io/ioutil"
57-
desc:"Use corresponding 'os' or 'io' functions instead."
58-
#- pkg: "regexp"
59-
# desc: "Use github.com/grafana/regexp instead of regexp"
60-
errcheck:
61-
exclude-functions:
62-
# The following 2 methods always return nil as the error
63-
-(*github.com/cespare/xxhash/v2.Digest).Write
64-
-(*github.com/cespare/xxhash/v2.Digest).WriteString
65-
-(*bufio.Writer).WriteRune
66-
goimports:
67-
local-prefixes:github.com/prometheus/client_golang
68-
gofumpt:
69-
extra-rules:true
70-
perfsprint:
71-
# Optimizes even if it requires an int or uint type cast.
72-
int-conversion:true
73-
# Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
74-
err-error:true
75-
# Optimizes `fmt.Errorf`.
76-
errorf:true
77-
# Optimizes `fmt.Sprintf` with only one argument.
78-
sprintf1:true
79-
# Optimizes into strings concatenation.
80-
strconcat:true
81-
revive:
82-
rules:
83-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
84-
-name:unused-parameter
85-
severity:warning
86-
disabled:true
73+
formatters:
74+
enable:
75+
-gofmt
76+
-gofumpt
77+
-goimports
78+
settings:
79+
gofumpt:
80+
extra-rules:true
81+
goimports:
82+
local-prefixes:
83+
-github.com/prometheus/client_golang
84+
exclusions:
85+
generated:lax
86+
paths:
87+
-^.*\.(pb|y)\.go$
88+
-third_party$
89+
-builtin$
90+
-examples$

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

‎prometheus/graphite/bridge.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ func replaceInvalidRune(c rune) rune {
307307
ifc==' ' {
308308
return'.'
309309
}
310-
if!((c>='a'&&c<='z')|| (c>='A'&&c<='Z')||c=='_'||c==':'||c=='-'|| (c>='0'&&c<='9')) {
310+
// TODO: Apply De Morgan's law to the condition. Make sure to test the condition first.
311+
if!((c>='a'&&c<='z')|| (c>='A'&&c<='Z')||c=='_'||c==':'||c=='-'|| (c>='0'&&c<='9')) {//nolint:staticcheck
311312
return'_'
312313
}
313314
returnc

‎prometheus/internal/difflib.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode {
453453
}
454454
group=append(group,OpCode{c.Tag,i1,i2,j1,j2})
455455
}
456-
iflen(group)>0&&!(len(group)==1&&group[0].Tag=='e') {
456+
iflen(group)>0&& (len(group)!=1||group[0].Tag!='e') {
457457
groups=append(groups,group)
458458
}
459459
returngroups
@@ -568,7 +568,7 @@ func WriteUnifiedDiff(writer io.Writer, diff UnifiedDiff) error {
568568
buf:=bufio.NewWriter(writer)
569569
deferbuf.Flush()
570570
wf:=func(formatstring,args...interface{})error {
571-
_,err:=buf.WriteString(fmt.Sprintf(format,args...))
571+
_,err:=fmt.Fprintf(buf,format,args...)
572572
returnerr
573573
}
574574
ws:=func(sstring)error {

‎prometheus/process_collector_darwin.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
"golang.org/x/sys/unix"
2626
)
2727

28-
//notImplementedErr is returned by stub functions that replace cgo functions, when cgo
28+
//errNotImplemented is returned by stub functions that replace cgo functions, when cgo
2929
// isn't available.
30-
varnotImplementedErr=errors.New("not implemented")
30+
varerrNotImplemented=errors.New("not implemented")
3131

3232
typememoryInfostruct {
3333
vsizeuint64// Virtual memory size in bytes
@@ -101,7 +101,7 @@ func (c *processCollector) processCollect(ch chan<- Metric) {
101101
ifmemInfo,err:=getMemory();err==nil {
102102
ch<-MustNewConstMetric(c.rss,GaugeValue,float64(memInfo.rss))
103103
ch<-MustNewConstMetric(c.vsize,GaugeValue,float64(memInfo.vsize))
104-
}elseif!errors.Is(err,notImplementedErr) {
104+
}elseif!errors.Is(err,errNotImplemented) {
105105
// Don't report an error when support is not compiled in.
106106
c.reportError(ch,c.rss,err)
107107
c.reportError(ch,c.vsize,err)

‎prometheus/process_collector_procfsenabled.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ func (c *processCollector) processCollect(ch chan<- Metric) {
6666

6767
ifnetstat,err:=p.Netstat();err==nil {
6868
varinOctets,outOctetsfloat64
69-
ifnetstat.IpExt.InOctets!=nil {
70-
inOctets=*netstat.IpExt.InOctets
69+
ifnetstat.InOctets!=nil {
70+
inOctets=*netstat.InOctets
7171
}
72-
ifnetstat.IpExt.OutOctets!=nil {
73-
outOctets=*netstat.IpExt.OutOctets
72+
ifnetstat.OutOctets!=nil {
73+
outOctets=*netstat.OutOctets
7474
}
7575
ch<-MustNewConstMetric(c.inBytes,CounterValue,inOctets)
7676
ch<-MustNewConstMetric(c.outBytes,CounterValue,outOctets)

‎prometheus/promhttp/instrument_server.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ func isLabelCurried(c prometheus.Collector, label string) bool {
392392
funclabels(code,methodbool,reqMethodstring,statusint,extraMethods...string) prometheus.Labels {
393393
labels:= prometheus.Labels{}
394394

395-
if!(code||method) {
395+
if!code&&!method {
396396
returnlabels
397397
}
398398

‎prometheus/vec.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (m *MetricVec) DeleteLabelValues(lvs ...string) bool {
7979
returnfalse
8080
}
8181

82-
returnm.metricMap.deleteByHashWithLabelValues(h,lvs,m.curry)
82+
returnm.deleteByHashWithLabelValues(h,lvs,m.curry)
8383
}
8484

8585
// Delete deletes the metric where the variable labels are the same as those
@@ -101,7 +101,7 @@ func (m *MetricVec) Delete(labels Labels) bool {
101101
returnfalse
102102
}
103103

104-
returnm.metricMap.deleteByHashWithLabels(h,labels,m.curry)
104+
returnm.deleteByHashWithLabels(h,labels,m.curry)
105105
}
106106

107107
// DeletePartialMatch deletes all metrics where the variable labels contain all of those
@@ -114,7 +114,7 @@ func (m *MetricVec) DeletePartialMatch(labels Labels) int {
114114
labels,closer:=constrainLabels(m.desc,labels)
115115
defercloser()
116116

117-
returnm.metricMap.deleteByLabels(labels,m.curry)
117+
returnm.deleteByLabels(labels,m.curry)
118118
}
119119

120120
// Without explicit forwarding of Describe, Collect, Reset, those methods won't
@@ -216,7 +216,7 @@ func (m *MetricVec) GetMetricWithLabelValues(lvs ...string) (Metric, error) {
216216
returnnil,err
217217
}
218218

219-
returnm.metricMap.getOrCreateMetricWithLabelValues(h,lvs,m.curry),nil
219+
returnm.getOrCreateMetricWithLabelValues(h,lvs,m.curry),nil
220220
}
221221

222222
// GetMetricWith returns the Metric for the given Labels map (the label names
@@ -244,7 +244,7 @@ func (m *MetricVec) GetMetricWith(labels Labels) (Metric, error) {
244244
returnnil,err
245245
}
246246

247-
returnm.metricMap.getOrCreateMetricWithLabels(h,labels,m.curry),nil
247+
returnm.getOrCreateMetricWithLabels(h,labels,m.curry),nil
248248
}
249249

250250
func (m*MetricVec)hashLabelValues(vals []string) (uint64,error) {

‎prometheus/vec_test.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func TestDeletePartialMatchWithConstraints(t *testing.T) {
183183

184184
functestDeletePartialMatch(t*testing.T,baseVec*GaugeVec) {
185185
assertNoMetric:=func(t*testing.T) {
186-
ifn:=len(baseVec.metricMap.metrics);n!=0 {
186+
ifn:=len(baseVec.metrics);n!=0 {
187187
t.Error("expected no metrics, got",n)
188188
}
189189
}
@@ -301,7 +301,7 @@ func testMetricVec(t *testing.T, vec *GaugeVec) {
301301
}
302302

303303
vartotalint
304-
for_,metrics:=rangevec.metricMap.metrics {
304+
for_,metrics:=rangevec.metrics {
305305
for_,metric:=rangemetrics {
306306
total++
307307
copy(pair[:],metric.values)
@@ -336,7 +336,7 @@ func testMetricVec(t *testing.T, vec *GaugeVec) {
336336

337337
vec.Reset()
338338

339-
iflen(vec.metricMap.metrics)>0 {
339+
iflen(vec.metrics)>0 {
340340
t.Fatalf("reset failed")
341341
}
342342
}
@@ -373,7 +373,7 @@ func testConstrainedMetricVec(t *testing.T, vec *GaugeVec, constrain func(string
373373
}
374374

375375
vartotalint
376-
for_,metrics:=rangevec.metricMap.metrics {
376+
for_,metrics:=rangevec.metrics {
377377
for_,metric:=rangemetrics {
378378
total++
379379
copy(pair[:],metric.values)
@@ -408,7 +408,7 @@ func testConstrainedMetricVec(t *testing.T, vec *GaugeVec, constrain func(string
408408

409409
vec.Reset()
410410

411-
iflen(vec.metricMap.metrics)>0 {
411+
iflen(vec.metrics)>0 {
412412
t.Fatalf("reset failed")
413413
}
414414
}
@@ -506,7 +506,7 @@ func TestCurryVecWithConstraints(t *testing.T) {
506506
functestCurryVec(t*testing.T,vec*CounterVec) {
507507
assertMetrics:=func(t*testing.T) {
508508
n:=0
509-
for_,m:=rangevec.metricMap.metrics {
509+
for_,m:=rangevec.metrics {
510510
n+=len(m)
511511
}
512512
ifn!=2 {
@@ -533,7 +533,7 @@ func testCurryVec(t *testing.T, vec *CounterVec) {
533533
}
534534

535535
assertNoMetric:=func(t*testing.T) {
536-
ifn:=len(vec.metricMap.metrics);n!=0 {
536+
ifn:=len(vec.metrics);n!=0 {
537537
t.Error("expected no metrics, got",n)
538538
}
539539
}
@@ -703,7 +703,7 @@ func testCurryVec(t *testing.T, vec *CounterVec) {
703703
functestConstrainedCurryVec(t*testing.T,vec*CounterVec,constraintfunc(string)string) {
704704
assertMetrics:=func(t*testing.T) {
705705
n:=0
706-
for_,m:=rangevec.metricMap.metrics {
706+
for_,m:=rangevec.metrics {
707707
n+=len(m)
708708
}
709709
ifn!=2 {
@@ -744,7 +744,7 @@ func testConstrainedCurryVec(t *testing.T, vec *CounterVec, constraint func(stri
744744
}
745745

746746
assertNoMetric:=func(t*testing.T) {
747-
ifn:=len(vec.metricMap.metrics);n!=0 {
747+
ifn:=len(vec.metrics);n!=0 {
748748
t.Error("expected no metrics, got",n)
749749
}
750750
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp