Skip to content

Commit

Permalink
lint: separate linter config and few minor warns
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Feb 15, 2025
1 parent 1d8e763 commit ebb7c14
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 10 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ jobs:
uses: golangci/golangci-lint-action@v4
with:
version: latest
args: --config ../.golangci.yml
working-directory: v2

- name: submit coverage
Expand Down
78 changes: 78 additions & 0 deletions v2/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
linters-settings:
govet:
shadow: true
gocyclo:
min-complexity: 15
maligned:
suggest-new: true
goconst:
min-len: 2
min-occurrences: 2
misspell:
locale: US
lll:
line-length: 140
gocritic:
enabled-tags:
- performance
- style
- experimental
disabled-checks:
- wrapperFunc

linters:
enable:
- staticcheck
- revive
- govet
- unconvert
- gosec
- unparam
- typecheck
- ineffassign
- stylecheck
- gochecknoinits
- copyloopvar
- gocritic
- nakedret
- gosimple
- prealloc
- unused
- contextcheck
- copyloopvar
- decorder
- errorlint
- exptostd
- gochecknoglobals
- gofmt
- goimports
- nilerr
- predeclared
- testifylint
- thelper
fast: false
disable-all: true


run:
concurrency: 4

issues:
exclude-rules:
- text: "G114: Use of net/http serve function that has no support for setting timeouts"
linters:
- gosec
- linters:
- unparam
- revive
path: _test\.go$
text: "unused-parameter"
- linters:
- prealloc
path: _test\.go$
text: "Consider pre-allocating"
- linters:
- gosec
- intrange
path: _test\.go$
exclude-use-default: false
4 changes: 4 additions & 0 deletions v2/repeater.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Package repeater implements retry functionality with different strategies.
// It provides fixed delays and various backoff strategies (constant, linear, exponential) with jitter support.
// The package allows custom retry strategies and error-specific handling. Context-aware implementation
// supports cancellation and timeouts.
package repeater

import (
Expand Down
6 changes: 3 additions & 3 deletions v2/repeater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestNewBackoff(t *testing.T) {
assert.Equal(t, time.Second, st.initial)
assert.Equal(t, 30*time.Second, st.maxDelay)
assert.Equal(t, BackoffExponential, st.btype)
assert.Equal(t, 0.1, st.jitter)
assert.InDelta(t, 0.1, st.jitter, 0.0001, "default jitter")

// check with options
r = NewBackoff(5, time.Second,
Expand All @@ -183,7 +183,7 @@ func TestNewBackoff(t *testing.T) {
assert.Equal(t, time.Second, st.initial)
assert.Equal(t, 5*time.Second, st.maxDelay)
assert.Equal(t, BackoffLinear, st.btype)
assert.Equal(t, 0.2, st.jitter)
assert.InDelta(t, 0.2, st.jitter, 0.0001, "custom jitter")
}

func TestBackoffReal(t *testing.T) {
Expand All @@ -200,7 +200,7 @@ func TestBackoffReal(t *testing.T) {
})
require.Error(t, err)

assert.Equal(t, expectedAttempts, len(attempts), "should make exactly %d attempts", expectedAttempts)
assert.Len(t, attempts, expectedAttempts, "should make exactly %d attempts", expectedAttempts)

// first attempt should be immediate
assert.Less(t, attempts[0].Sub(startTime), 5*time.Millisecond)
Expand Down
8 changes: 4 additions & 4 deletions v2/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ type backoff struct {
type backoffOption func(*backoff)

// WithMaxDelay sets maximum delay for the backoff strategy
func WithMaxDelay(d time.Duration) backoffOption {
func WithMaxDelay(d time.Duration) backoffOption { //nolint:revive // unexported type is used in the same package
return func(b *backoff) {
b.maxDelay = d
}
}

// WithBackoffType sets backoff type for the strategy
func WithBackoffType(t BackoffType) backoffOption {
func WithBackoffType(t BackoffType) backoffOption { //nolint:revive // unexported type is used in the same package
return func(b *backoff) {
b.btype = t
}
}

// WithJitter sets jitter factor for the backoff strategy
func WithJitter(factor float64) backoffOption {
func WithJitter(factor float64) backoffOption { //nolint:revive // unexported type is used in the same package
return func(b *backoff) {
b.jitter = factor
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func (s backoff) NextDelay(attempt int) time.Duration {

if s.jitter > 0 {
jitter := float64(delay) * s.jitter
delay = time.Duration(float64(delay) + (rand.Float64()*jitter - jitter/2))
delay = time.Duration(float64(delay) + (rand.Float64()*jitter - jitter/2)) //nolint:gosec // no need for secure random here
}

return delay
Expand Down
4 changes: 2 additions & 2 deletions v2/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ func TestBackoff(t *testing.T) {
assert.Equal(t, time.Second, s.initial)
assert.Equal(t, 3*time.Second, s.maxDelay)
assert.Equal(t, BackoffLinear, s.btype)
assert.Equal(t, 0.2, s.jitter)
assert.InDelta(t, 0.2, s.jitter, 0.0001, "custom jitter")
})

t.Run("defaults", func(t *testing.T) {
s := newBackoff(time.Second)
assert.Equal(t, time.Second, s.initial)
assert.Equal(t, 30*time.Second, s.maxDelay)
assert.Equal(t, BackoffExponential, s.btype)
assert.Equal(t, 0.1, s.jitter)
assert.InDelta(t, 0.1, s.jitter, 0.0001, "default jitter")
})
}

0 comments on commit ebb7c14

Please sign in to comment.