From 73255e15f6b46affc9df86fa202e5ad363f4582b Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Sat, 23 Oct 2021 00:45:29 +0200 Subject: [PATCH] Address golint failures from revive Signed-off-by: Julien Pivotto --- .github/workflows/golangci-lint.yml | 2 ++ cmd/promtool/rules.go | 2 +- cmd/promtool/rules_test.go | 1 + discovery/triton/triton.go | 4 ++-- tsdb/errors/errors.go | 2 +- tsdb/exemplar.go | 2 +- tsdb/wal/wal.go | 4 ++-- 7 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 431fef711..f96c76a65 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -7,6 +7,7 @@ on: - "**.go" - "scripts/errcheck_excludes.txt" - ".github/workflows/golangci-lint.yml" + - ".golangci.yml" pull_request: paths: - "go.sum" @@ -14,6 +15,7 @@ on: - "**.go" - "scripts/errcheck_excludes.txt" - ".github/workflows/golangci-lint.yml" + - ".golangci.yml" jobs: golangci: diff --git a/cmd/promtool/rules.go b/cmd/promtool/rules.go index 2c35d0105..ff98e80d8 100644 --- a/cmd/promtool/rules.go +++ b/cmd/promtool/rules.go @@ -170,7 +170,7 @@ func (importer *ruleImporter) importRule(ctx context.Context, ruleExpr, ruleName } } default: - return errors.New(fmt.Sprintf("rule result is wrong type %s", val.Type().String())) + return fmt.Errorf("rule result is wrong type %s", val.Type().String()) } if err := app.flushAndCommit(ctx); err != nil { diff --git a/cmd/promtool/rules_test.go b/cmd/promtool/rules_test.go index 685e4bd11..d1f8938b9 100644 --- a/cmd/promtool/rules_test.go +++ b/cmd/promtool/rules_test.go @@ -233,6 +233,7 @@ func TestBackfillLabels(t *testing.T) { }, } ruleImporter, err := newTestRuleImporter(ctx, start, tmpDir, mockAPISamples, defaultBlockDuration) + require.NoError(t, err) path := filepath.Join(tmpDir, "test.file") recordingRules := `groups: diff --git a/discovery/triton/triton.go b/discovery/triton/triton.go index 187d31ab6..96b9f39b1 100644 --- a/discovery/triton/triton.go +++ b/discovery/triton/triton.go @@ -188,7 +188,7 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) { case "cn": endpointFormat = "https://%s:%d/v%d/gz/discover" default: - return nil, errors.New(fmt.Sprintf("unknown role '%s' in configuration", d.sdConfig.Role)) + return nil, fmt.Errorf("unknown role '%s' in configuration", d.sdConfig.Role) } var endpoint = fmt.Sprintf(endpointFormat, d.sdConfig.Endpoint, d.sdConfig.Port, d.sdConfig.Version) if len(d.sdConfig.Groups) > 0 { @@ -223,7 +223,7 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) { case "cn": return d.processComputeNodeResponse(data, endpoint) default: - return nil, errors.New(fmt.Sprintf("unknown role '%s' in configuration", d.sdConfig.Role)) + return nil, fmt.Errorf("unknown role '%s' in configuration", d.sdConfig.Role) } } diff --git a/tsdb/errors/errors.go b/tsdb/errors/errors.go index aeac4d277..607a7782a 100644 --- a/tsdb/errors/errors.go +++ b/tsdb/errors/errors.go @@ -24,7 +24,7 @@ import ( type multiError []error // NewMulti returns multiError with provided errors added if not nil. -func NewMulti(errs ...error) multiError { // nolint:golint +func NewMulti(errs ...error) multiError { // nolint:revive m := multiError{} m.Add(errs...) return m diff --git a/tsdb/exemplar.go b/tsdb/exemplar.go index 1e09da21e..086e69667 100644 --- a/tsdb/exemplar.go +++ b/tsdb/exemplar.go @@ -284,7 +284,7 @@ func (ce *CircularExemplarStorage) Resize(l int64) int { // This math is essentially looking at nextIndex, where we would write the next exemplar to, // and find the index in the old exemplar buffer that we should start migrating exemplars from. // This way we don't migrate exemplars that would just be overwritten when migrating later exemplars. - var startIndex int64 = (oldNextIndex - count + int64(len(oldBuffer))) % int64(len(oldBuffer)) + var startIndex = (oldNextIndex - count + int64(len(oldBuffer))) % int64(len(oldBuffer)) for i := int64(0); i < count; i++ { idx := (startIndex + i) % int64(len(oldBuffer)) diff --git a/tsdb/wal/wal.go b/tsdb/wal/wal.go index c5023b0fd..7254fc4c7 100644 --- a/tsdb/wal/wal.go +++ b/tsdb/wal/wal.go @@ -875,7 +875,7 @@ type segmentBufReader struct { off int // Offset of read data into current segment. } -// nolint:golint // TODO: Consider exporting segmentBufReader +// nolint:revive // TODO: Consider exporting segmentBufReader func NewSegmentBufReader(segs ...*Segment) *segmentBufReader { return &segmentBufReader{ buf: bufio.NewReaderSize(segs[0], 16*pageSize), @@ -883,7 +883,7 @@ func NewSegmentBufReader(segs ...*Segment) *segmentBufReader { } } -// nolint:golint +// nolint:revive func NewSegmentBufReaderWithOffset(offset int, segs ...*Segment) (sbr *segmentBufReader, err error) { if offset == 0 { return NewSegmentBufReader(segs...), nil