Skip to content

Commit 030b850

Browse files
committed
permanently enable the linters
Signed-off-by: Christoph Mewes <[email protected]>
1 parent 1a79d53 commit 030b850

File tree

8 files changed

+37
-16
lines changed

8 files changed

+37
-16
lines changed

.golangci.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
# Run only staticcheck for now. Additional linters will be enabled one-by-one.
21
linters:
32
enable:
4-
- staticcheck
3+
- deadcode
4+
- depguard
5+
- durationcheck
6+
- errorlint
7+
- exportloopref
8+
- gofmt
9+
- gosimple
10+
- ineffassign
11+
- misspell
12+
- nolintlint
13+
- predeclared
14+
- staticcheck
15+
- structcheck
16+
- unconvert
17+
- unused
18+
- varcheck
19+
- wastedassign
520
disable-all: true

api/prometheus/v1/api_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ func TestAPIs(t *testing.T) {
10241024
reqMethod: "GET",
10251025
reqPath: "/api/v1/metadata",
10261026
res: map[string][]Metadata{
1027-
"go_goroutines": []Metadata{
1027+
"go_goroutines": {
10281028
{
10291029
Type: "gauge",
10301030
Help: "Number of goroutines that currently exist.",
@@ -1455,9 +1455,13 @@ func TestAPIClientDo(t *testing.T) {
14551455
}
14561456

14571457
if test.expectedErr.Detail != "" {
1458-
apiErr := err.(*Error)
1459-
if apiErr.Detail != test.expectedErr.Detail {
1460-
t.Fatalf("expected error detail :%v, but got:%v", apiErr.Detail, test.expectedErr.Detail)
1458+
apiErr := &Error{}
1459+
if errors.As(err, &apiErr) {
1460+
if apiErr.Detail != test.expectedErr.Detail {
1461+
t.Fatalf("expected error detail :%v, but got:%v", apiErr.Detail, test.expectedErr.Detail)
1462+
}
1463+
} else {
1464+
t.Fatalf("expected v1.Error instance, but got:%T", err)
14611465
}
14621466
}
14631467

prometheus/counter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func TestCounterExemplar(t *testing.T) {
231231
}
232232
expectedExemplar := &dto.Exemplar{
233233
Label: []*dto.LabelPair{
234-
&dto.LabelPair{Name: proto.String("foo"), Value: proto.String("bar")},
234+
{Name: proto.String("foo"), Value: proto.String("bar")},
235235
},
236236
Value: proto.Float64(42),
237237
Timestamp: ts,

prometheus/internal/difflib.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ func (m *SequenceMatcher) chainB() {
163163
m.bJunk = map[string]struct{}{}
164164
if m.IsJunk != nil {
165165
junk := m.bJunk
166-
for s, _ := range b2j {
166+
for s := range b2j {
167167
if m.IsJunk(s) {
168168
junk[s] = struct{}{}
169169
}
170170
}
171-
for s, _ := range junk {
171+
for s := range junk {
172172
delete(b2j, s)
173173
}
174174
}
@@ -183,7 +183,7 @@ func (m *SequenceMatcher) chainB() {
183183
popular[s] = struct{}{}
184184
}
185185
}
186-
for s, _ := range popular {
186+
for s := range popular {
187187
delete(b2j, s)
188188
}
189189
}

prometheus/internal/difflib_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ func TestWithAsciiBJunk(t *testing.T) {
185185

186186
sm = NewMatcherWithJunk(splitChars(rep("a", 40)+rep("b", 40)),
187187
splitChars(rep("a", 44)+rep("b", 40)+rep(" ", 20)), false, isJunk)
188-
assertEqual(t, sm.bJunk, map[string]struct{}{" ": struct{}{}})
188+
assertEqual(t, sm.bJunk, map[string]struct{}{" ": {}})
189189

190190
isJunk = func(s string) bool {
191191
return s == " " || s == "b"
192192
}
193193
sm = NewMatcherWithJunk(splitChars(rep("a", 40)+rep("b", 40)),
194194
splitChars(rep("a", 44)+rep("b", 40)+rep(" ", 20)), false, isJunk)
195-
assertEqual(t, sm.bJunk, map[string]struct{}{" ": struct{}{}, "b": struct{}{}})
195+
assertEqual(t, sm.bJunk, map[string]struct{}{" ": {}, "b": {}})
196196
}
197197

198198
func TestSFBugsRatioForNullSeqn(t *testing.T) {

prometheus/process_collector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ func NewPidFileFn(pidFilePath string) func() (int, error) {
154154
return func() (int, error) {
155155
content, err := ioutil.ReadFile(pidFilePath)
156156
if err != nil {
157-
return 0, fmt.Errorf("can't read pid file %q: %+v", pidFilePath, err)
157+
return 0, fmt.Errorf("can't read pid file %q: %w", pidFilePath, err)
158158
}
159159
pid, err := strconv.Atoi(strings.TrimSpace(string(content)))
160160
if err != nil {
161-
return 0, fmt.Errorf("can't parse pid file %q: %+v", pidFilePath, err)
161+
return 0, fmt.Errorf("can't parse pid file %q: %w", pidFilePath, err)
162162
}
163163

164164
return pid, nil

prometheus/registry.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package prometheus
1515

1616
import (
1717
"bytes"
18+
"errors"
1819
"fmt"
1920
"io/ioutil"
2021
"os"
@@ -725,7 +726,8 @@ func (gs Gatherers) Gather() ([]*dto.MetricFamily, error) {
725726
for i, g := range gs {
726727
mfs, err := g.Gather()
727728
if err != nil {
728-
if multiErr, ok := err.(MultiError); ok {
729+
multiErr := MultiError{}
730+
if errors.As(err, &multiErr) {
729731
for _, err := range multiErr {
730732
errs = append(errs, fmt.Errorf("[from Gatherer #%d] %w", i+1, err))
731733
}

prometheus/registry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ func TestNewMultiTRegistry(t *testing.T) {
12431243
t.Run("two registries, one with error", func(t *testing.T) {
12441244
m := prometheus.NewMultiTRegistry(prometheus.ToTransactionalGatherer(reg), treg)
12451245
ret, done, err := m.Gather()
1246-
if err != treg.err {
1246+
if !errors.Is(err, treg.err) {
12471247
t.Error("unexpected error:", err)
12481248
}
12491249
done()

0 commit comments

Comments
 (0)