Skip to content

Commit

Permalink
permanently enable the linters
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf committed May 3, 2022
1 parent 1a79d53 commit fd42e30
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 16 deletions.
19 changes: 17 additions & 2 deletions .golangci.yml
@@ -1,5 +1,20 @@
# Run only staticcheck for now. Additional linters will be enabled one-by-one.
linters:
enable:
- staticcheck
- deadcode
- depguard
- durationcheck
- errorlint
- exportloopref
- gofmt
- gosimple
- ineffassign
- misspell
- nolintlint
- predeclared
- staticcheck
- structcheck
- unconvert
- unused
- varcheck
- wastedassign
disable-all: true
12 changes: 8 additions & 4 deletions api/prometheus/v1/api_test.go
Expand Up @@ -1024,7 +1024,7 @@ func TestAPIs(t *testing.T) {
reqMethod: "GET",
reqPath: "/api/v1/metadata",
res: map[string][]Metadata{
"go_goroutines": []Metadata{
"go_goroutines": {
{
Type: "gauge",
Help: "Number of goroutines that currently exist.",
Expand Down Expand Up @@ -1455,9 +1455,13 @@ func TestAPIClientDo(t *testing.T) {
}

if test.expectedErr.Detail != "" {
apiErr := err.(*Error)
if apiErr.Detail != test.expectedErr.Detail {
t.Fatalf("expected error detail :%v, but got:%v", apiErr.Detail, test.expectedErr.Detail)
apiErr := &Error{}
if errors.As(err, &apiErr) {
if apiErr.Detail != test.expectedErr.Detail {
t.Fatalf("expected error detail :%v, but got:%v", apiErr.Detail, test.expectedErr.Detail)
}
} else {
t.Fatalf("expected v1.Error instance, but got:%T", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion prometheus/counter_test.go
Expand Up @@ -231,7 +231,7 @@ func TestCounterExemplar(t *testing.T) {
}
expectedExemplar := &dto.Exemplar{
Label: []*dto.LabelPair{
&dto.LabelPair{Name: proto.String("foo"), Value: proto.String("bar")},
{Name: proto.String("foo"), Value: proto.String("bar")},
},
Value: proto.Float64(42),
Timestamp: ts,
Expand Down
6 changes: 3 additions & 3 deletions prometheus/internal/difflib.go
Expand Up @@ -163,12 +163,12 @@ func (m *SequenceMatcher) chainB() {
m.bJunk = map[string]struct{}{}
if m.IsJunk != nil {
junk := m.bJunk
for s, _ := range b2j {
for s := range b2j {
if m.IsJunk(s) {
junk[s] = struct{}{}
}
}
for s, _ := range junk {
for s := range junk {
delete(b2j, s)
}
}
Expand All @@ -183,7 +183,7 @@ func (m *SequenceMatcher) chainB() {
popular[s] = struct{}{}
}
}
for s, _ := range popular {
for s := range popular {
delete(b2j, s)
}
}
Expand Down
4 changes: 2 additions & 2 deletions prometheus/internal/difflib_test.go
Expand Up @@ -185,14 +185,14 @@ func TestWithAsciiBJunk(t *testing.T) {

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

isJunk = func(s string) bool {
return s == " " || s == "b"
}
sm = NewMatcherWithJunk(splitChars(rep("a", 40)+rep("b", 40)),
splitChars(rep("a", 44)+rep("b", 40)+rep(" ", 20)), false, isJunk)
assertEqual(t, sm.bJunk, map[string]struct{}{" ": struct{}{}, "b": struct{}{}})
assertEqual(t, sm.bJunk, map[string]struct{}{" ": {}, "b": {}})
}

func TestSFBugsRatioForNullSeqn(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions prometheus/process_collector.go
Expand Up @@ -154,11 +154,11 @@ func NewPidFileFn(pidFilePath string) func() (int, error) {
return func() (int, error) {
content, err := ioutil.ReadFile(pidFilePath)
if err != nil {
return 0, fmt.Errorf("can't read pid file %q: %+v", pidFilePath, err)
return 0, fmt.Errorf("can't read pid file %q: %w", pidFilePath, err)
}
pid, err := strconv.Atoi(strings.TrimSpace(string(content)))
if err != nil {
return 0, fmt.Errorf("can't parse pid file %q: %+v", pidFilePath, err)
return 0, fmt.Errorf("can't parse pid file %q: %w", pidFilePath, err)
}

return pid, nil
Expand Down
4 changes: 3 additions & 1 deletion prometheus/registry.go
Expand Up @@ -15,6 +15,7 @@ package prometheus

import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -725,7 +726,8 @@ func (gs Gatherers) Gather() ([]*dto.MetricFamily, error) {
for i, g := range gs {
mfs, err := g.Gather()
if err != nil {
if multiErr, ok := err.(MultiError); ok {
multiErr := MultiError{}
if errors.As(err, &multiErr) {
for _, err := range multiErr {
errs = append(errs, fmt.Errorf("[from Gatherer #%d] %w", i+1, err))
}
Expand Down
2 changes: 1 addition & 1 deletion prometheus/registry_test.go
Expand Up @@ -1243,7 +1243,7 @@ func TestNewMultiTRegistry(t *testing.T) {
t.Run("two registries, one with error", func(t *testing.T) {
m := prometheus.NewMultiTRegistry(prometheus.ToTransactionalGatherer(reg), treg)
ret, done, err := m.Gather()
if err != treg.err {
if !errors.Is(err, treg.err) {
t.Error("unexpected error:", err)
}
done()
Expand Down

0 comments on commit fd42e30

Please sign in to comment.