Skip to content

Commit 8f5d013

Browse files
committed
lint
1 parent 595e48c commit 8f5d013

15 files changed

Lines changed: 1044 additions & 689 deletions

.golangci.yml

Lines changed: 107 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,112 @@
1-
linters-settings:
2-
funlen:
3-
lines: 100
4-
statements: 50
5-
6-
cyclop:
7-
skip-tests: true
8-
max-complexity: 30
9-
package-average: 5
10-
11-
gocyclo:
12-
min-complexity: 15
13-
14-
goconst:
15-
min-len: 2
16-
min-occurrences: 3
17-
18-
gocritic:
19-
enable-all: true
20-
21-
godot:
22-
capital: true
23-
24-
gosimple:
25-
checks: [ "all" ]
26-
27-
govet:
28-
settings:
29-
printf:
30-
funcs:
31-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
32-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
33-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
34-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
35-
disable-all: true
36-
enable:
37-
- assign
38-
- atomic
39-
- atomicalign
40-
- bools
41-
- buildtag
42-
- cgocall
43-
- composites
44-
- copylocks
45-
- deepequalerrors
46-
- errorsas
47-
- fieldalignment
48-
- findcall
49-
- framepointer
50-
- httpresponse
51-
- ifaceassert
52-
- loopclosure
53-
- lostcancel
54-
- nilfunc
55-
- printf
56-
- reflectvaluecompare
57-
- shift
58-
- sigchanyzer
59-
- sortslice
60-
- stdmethods
61-
- stringintconv
62-
- structtag
63-
- testinggoroutine
64-
- tests
65-
- unmarshal
66-
- unreachable
67-
- unsafeptr
68-
- unusedresult
69-
70-
misspell:
71-
locale: UK
72-
73-
staticcheck:
74-
checks: [ "all" ]
75-
76-
stylecheck:
77-
checks: [ "all" ]
78-
79-
unparam:
80-
check-exported: true
81-
82-
wrapcheck:
83-
ignoreSigs:
84-
- .Errorf(
85-
- errors.New(
86-
- errors.Unwrap(
87-
- errors.Join(
88-
- .Wrap(
89-
- .Wrapf(
90-
- .WithMessage(
91-
- .WithMessagef(
92-
- .WithStack(
93-
- (context.Context).Err()
94-
95-
nlreturn:
96-
block-size: 2
97-
98-
issues:
99-
# Excluding configuration per-path, per-linter, per-text and per-source
100-
exclude-rules:
101-
- path: _test\.go
102-
linters:
103-
- contextcheck
104-
- dupl
105-
- errcheck
106-
- funlen
107-
- gochecknoinits
108-
- goconst
109-
- gocritic
110-
- gosec
111-
- govet
112-
- lll
113-
- nlreturn
114-
- nosprintfhostport
115-
- revive
116-
- testifylint
117-
- unparam
118-
- wrapcheck
119-
- path: mocks
120-
linters:
121-
- lll
122-
- revive
123-
- stylecheck
124-
- path: docs.go
125-
linters:
126-
- dupword
127-
exclude-dirs:
128-
- model
129-
- tmp
130-
- bin
131-
- scripts
132-
fix: true
133-
exclude-use-default: false
134-
1+
version: "2"
1352
run:
136-
timeout: 5m
137-
allow-parallel-runners: true
138-
tests: true
1393
build-tags:
1404
- integration
141-
5+
tests: true
6+
allow-parallel-runners: true
1427
linters:
143-
enable-all: true
8+
default: all
1449
disable:
145-
- containedctx # We need to use internal contexts.
146-
- depguard # because I don't want to write a dedicated config file.
147-
- err113 # We do not like its style.
148-
- exhaustive # Is very strict.
149-
- exhaustruct # I want to use zero values... and sometime leave a field uninitialised, because it'll be later.
150-
- gochecknoglobals # We rely on globals.
151-
- ireturn # We need to use them in logs.
152-
- nlreturn
153-
- gomnd # We have magic numbers.
154-
- mnd # Same as gomnd.
155-
- nolintlint # Sometimes we want to disable linters in specific places.
156-
- nonamedreturns # Conflicts with paramTypeCombine.
157-
- paralleltest # Full of false-positives.
158-
- varnamelen # Very strict.
159-
- wsl # Too restrictive for this project (maybe in the future).
10+
- depguard # As much as I would like to use this, it is completely unmanageable.
11+
- exhaustruct # This lib is usually pointless.
12+
settings:
13+
cyclop:
14+
max-complexity: 30
15+
package-average: 5
16+
funlen:
17+
lines: 100
18+
statements: 50
19+
settings:
20+
gci:
21+
sections:
22+
- standard
23+
- default
24+
- prefix(github.com/blokur)
25+
- localmodule
26+
goconst:
27+
min-len: 2
28+
min-occurrences: 3
29+
gocritic:
30+
enable-all: true
31+
gocyclo:
32+
min-complexity: 15
33+
godot:
34+
capital: true
35+
govet:
36+
settings:
37+
printf:
38+
funcs:
39+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
40+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
41+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
42+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
43+
misspell:
44+
locale: UK
45+
nlreturn:
46+
block-size: 2
47+
staticcheck:
48+
checks:
49+
- all
50+
unparam:
51+
check-exported: true
52+
wrapcheck:
53+
ignore-sigs:
54+
- .Errorf(
55+
- errors.New(
56+
- errors.Unwrap(
57+
- errors.Join(
58+
- .Wrap(
59+
- .Wrapf(
60+
- .WithMessage(
61+
- .WithMessagef(
62+
- .WithStack(
63+
- (context.Context).Err()
64+
exclusions:
65+
generated: lax
66+
rules:
67+
- linters:
68+
- err113
69+
- errcheck
70+
- gochecknoinits # I'm OK with inits for tests.
71+
- gocritic # Some of these are actually correct and should not be ignored / changed.
72+
- gosec # Some errors I tried to fix, others (such as forcing crypto/rand) make no sense.
73+
- testifylint # I tried to remove a few of them.
74+
- wrapcheck
75+
path: _test\.go
76+
- linters:
77+
- lll
78+
- revive
79+
- staticcheck
80+
path: mocks
81+
- linters:
82+
- dupword
83+
path: docs.go
84+
- linters:
85+
- cyclop
86+
path: (.+)_test\.go
87+
paths:
88+
- model
89+
- tmp
90+
- bin
91+
- scripts
92+
- third_party$
93+
- builtin$
94+
- examples$
95+
issues:
96+
fix: false
97+
formatters:
98+
enable:
99+
- gci
100+
- gofmt
101+
- gofumpt
102+
- goimports
103+
exclusions:
104+
generated: lax
105+
paths:
106+
- model
107+
- tmp
108+
- bin
109+
- scripts
110+
- third_party$
111+
- builtin$
112+
- examples$

config.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package harego
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"time"
87

@@ -20,6 +19,8 @@ type rabbitWrapper struct {
2019
}
2120

2221
// Channel returns the underlying channel.
22+
//
23+
//nolint:ireturn // This is a wrapper around connection.Channel
2324
func (r *rabbitWrapper) Channel() (Channel, error) {
2425
return r.Connection.Channel() //nolint:wrapcheck // Okay here.
2526
}
@@ -35,28 +36,29 @@ func URLConnector(url string) Connector {
3536
if err != nil {
3637
return nil, fmt.Errorf("creating a connection to %q: %w", url, err)
3738
}
39+
3840
return &rabbitWrapper{conn}, nil
3941
}
4042
}
4143

42-
// AMQPConnector uses r everytime the Client needs a new connection. You should
43-
// make sure r keep being alive.
44-
func AMQPConnector(r *amqp.Connection) Connector {
44+
// AMQPConnector uses the amqp connection everytime the Client needs a new connection. You should
45+
// make sure it is kept alive.
46+
func AMQPConnector(amqpConn *amqp.Connection) Connector {
4547
return func() (RabbitMQ, error) {
46-
if r.IsClosed() {
47-
return nil, errors.New("connection is closed")
48+
if amqpConn.IsClosed() {
49+
return nil, fmt.Errorf("connection is closed: %w", amqp.ErrClosed)
4850
}
49-
return &rabbitWrapper{r}, nil
51+
52+
return &rabbitWrapper{amqpConn}, nil
5053
}
5154
}
5255

53-
// nolint:govet // most likely not an issue, but cleaner this way.
5456
type config struct {
5557
workers int
5658
consumerName string
5759
retryDelay time.Duration
5860
logger logr.Logger
59-
ctx context.Context
61+
ctx context.Context //nolint:containedctx // Helps us know when the parent is shut down.
6062

6163
global bool
6264

@@ -85,15 +87,20 @@ type config struct {
8587
}
8688

8789
func defaultConfig() *config {
90+
const (
91+
defaultChannelBufferSize = 10
92+
defaultRetryDelay = 100 * time.Millisecond
93+
)
94+
8895
return &config{
8996
exchName: "default",
9097
workers: 1,
91-
chBuff: 10,
98+
chBuff: defaultChannelBufferSize,
9299
exchType: ExchangeTypeTopic,
93100
deliveryMode: DeliveryModePersistent,
94101
durable: true,
95102
consumerName: internal.GetRandomName(),
96-
retryDelay: 100 * time.Millisecond,
103+
retryDelay: defaultRetryDelay,
97104
logger: logr.Discard(),
98105
ctx: context.Background(),
99106
}

constants.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (e ExchangeType) IsValid() bool {
5959
}
6060

6161
func (e ExchangeType) String() string {
62-
switch e {
62+
switch e { //nolint:exhaustive // I don't want to panic here.
6363
case ExchangeTypeDirect:
6464
return "direct"
6565
case ExchangeTypeFanout:
@@ -69,6 +69,7 @@ func (e ExchangeType) String() string {
6969
case ExchangeTypeHeaders:
7070
return "headers"
7171
}
72+
7273
return ""
7374
}
7475

0 commit comments

Comments
 (0)