Skip to content

Commit f431046

Browse files
committed
Upgrade to golangci-lint v2
1 parent 0fcfd61 commit f431046

9 files changed

Lines changed: 80 additions & 81 deletions

File tree

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- run: go version
2626

2727
- name: golangci-lint
28-
uses: golangci/golangci-lint-action@v6
28+
uses: golangci/golangci-lint-action@v8
2929
with:
3030
version: latest
3131
args: --timeout=5m

.golangci.yml

Lines changed: 65 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
linters-settings:
2-
gocyclo:
3-
min-complexity: 15
4-
govet:
5-
enable:
6-
- nilness
7-
- shadow
8-
1+
version: "2"
2+
run:
3+
go: "1.20"
4+
# issues:
5+
# fix: true
96
linters:
107
enable:
118
- asasalint # Check for pass []any as any in variadic func(...any)
@@ -22,26 +19,21 @@ linters:
2219
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted.
2320
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
2421
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
25-
- exportloopref # checks for pointers to enclosing loop variables
22+
# - exportloopref # checks for pointers to enclosing loop variables
2623
- forcetypeassert # finds forced type assertions
27-
- gci # Gci control golang package import order and make it always deterministic.
2824
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid.
2925
- gocognit # Computes and checks the cognitive complexity of functions
3026
- goconst # Finds repeated strings that could be replaced by a constant
3127
- gocritic # The most opinionated Go source code linter
3228
- gocyclo # Computes and checks the cyclomatic complexity of functions
3329
- godox # Tool for detection of FIXME, TODO and other comment keywords
3430
# - goerr113 # Golang linter to check the errors handling expressions
35-
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
36-
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
3731
- goheader # Checks is file header matches to pattern
38-
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
39-
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
32+
# - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
4033
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
4134
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
4235
- gosec # Inspects source code for security problems
4336
- gosmopolitan # Report certain i18n/l10n anti-patterns in your Go codebase
44-
- gosimple # Linter for Go source code that specializes in simplifying a code
4537
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
4638
- grouper # An analyzer to analyze expression groups
4739
- importas # Enforces consistent import aliases
@@ -66,12 +58,9 @@ linters:
6658
- sloglint # Ensure consistent code style when using log/slog
6759
- spancheck # Checks for mistakes with OpenTelemetry/Census spans
6860
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
69-
- stylecheck # Stylecheck is a replacement for golint
7061
- tagliatelle # Checks the struct tags.
71-
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
7262
- testifylint # Checks usage of github.com/stretchr/testify.
7363
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
74-
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
7564
- unconvert # Remove unnecessary type conversions
7665
- unparam # Reports unused function parameters
7766
- unused # Checks Go code for unused constants, variables, functions and types
@@ -90,7 +79,6 @@ linters:
9079
- gochecknoglobals # Checks that no globals are present in Go code
9180
- gochecknoinits # Checks that no init functions are present in Go code
9281
- godot # Check if comments end in a period
93-
- gomnd # An analyzer to detect magic numbers.
9482
- inamedparam # Reports interfaces with unnamed method parameters.
9583
- interfacebloat # A linter that checks the number of methods inside an interface
9684
- ireturn # Accept Interfaces, Return Concrete Types
@@ -110,45 +98,61 @@ linters:
11098
- varnamelen # checks that the length of a variable's name matches its scope
11199
- wrapcheck # Checks that errors returned from external packages are wrapped
112100
- wsl # Whitespace Linter - Forces you to use empty lines!
113-
114-
issues:
115-
# Excluding configuration per-path, per-linter, per-text and per-source
116-
exclude-rules:
117-
# Exclude some linters from running on tests files.
118-
- path: _test\.go
119-
linters:
120-
- dupl
121-
- dupword
122-
- forcetypeassert
123-
- gosec
124-
- gocyclo
125-
- gocognit
126-
- nakedret
127-
128-
- path: ^test/.*\.go
129-
linters:
130-
- dupl
131-
- forcetypeassert
132-
- gosec
133-
- gocyclo
134-
- gocognit
135-
136-
- path: example_test\.go
137-
text: "exitAfterDefer"
138-
linters:
139-
- gocritic
140-
141-
- path: .*/client/conn.go
142-
linters:
143-
- godox
144-
145-
- path: .*.go
146-
text: "replace with standard maps package"
147-
linters:
148-
- godox
149-
150-
# # Fix found issues (if it's supported by the linter).
151-
# fix: true
152-
153-
run:
154-
go: "1.20"
101+
settings:
102+
gocyclo:
103+
min-complexity: 15
104+
govet:
105+
enable:
106+
- nilness
107+
- shadow
108+
exclusions:
109+
generated: lax
110+
presets:
111+
- comments
112+
- common-false-positives
113+
- legacy
114+
- std-error-handling
115+
# Log a warning if an exclusion rule is unused.
116+
# Default: false
117+
warn-unused: true
118+
rules:
119+
- linters:
120+
- dupl
121+
- dupword
122+
- forcetypeassert
123+
- gocognit
124+
- gocyclo
125+
- gosec
126+
- nakedret
127+
path: _test\.go
128+
- linters:
129+
- dupl
130+
- forcetypeassert
131+
- gocognit
132+
- gocyclo
133+
- gosec
134+
path: ^test/.*\.go
135+
- linters:
136+
- gocritic
137+
path: example_test\.go
138+
text: exitAfterDefer
139+
- linters:
140+
- godox
141+
path: .*/client/conn.go
142+
- linters:
143+
- godox
144+
path: .*.go
145+
text: replace with standard maps package
146+
# Which file paths to exclude: they will be analyzed, but issues from them won't be reported.
147+
# "/" will be replaced by the current OS file path separator to properly work on Windows.
148+
# Default: []
149+
paths:
150+
- examples
151+
formatters:
152+
enable:
153+
- gci
154+
- gofmt
155+
- gofumpt
156+
- goimports
157+
exclusions:
158+
generated: lax

examples/dtls/cid/server/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/plgd-dev/go-coap/v3/mux"
1616
"github.com/plgd-dev/go-coap/v3/options"
1717
udpClient "github.com/plgd-dev/go-coap/v3/udp/client"
18-
"go.uber.org/atomic"
1918
)
2019

2120
func handleA(w mux.ResponseWriter, r *mux.Message) {
@@ -45,8 +44,7 @@ func handleB(w mux.ResponseWriter, r *mux.Message) {
4544
// NOTE: this utility is for example purposes only. Context should be handled
4645
// properly in meaningful scenarios.
4746
type wrappedListener struct {
48-
l net.Listener
49-
closed atomic.Bool
47+
l net.Listener
5048
}
5149

5250
// AcceptWithContext disregards the passed context and calls the underlying
@@ -87,6 +85,6 @@ func main() {
8785
if err != nil {
8886
log.Fatalf("Error establishing DTLS listener: %v", err)
8987
}
90-
s := server.New(options.WithMux(m), options.WithInactivityMonitor(10*time.Second, func(cc *udpClient.Conn) {}))
88+
s := server.New(options.WithMux(m), options.WithInactivityMonitor(10*time.Second, func(*udpClient.Conn) {}))
9189
s.Serve(wrapListener(l))
9290
}

examples/dtls/pki/cert_util.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ func LoadCertPool(caBytes []byte) (*x509.CertPool, error) {
8787
for _, certBytes := range rootCertificate.Certificate {
8888
cert, err := x509.ParseCertificate(certBytes)
8989
if err != nil {
90-
certPool = nil
9190
return nil, err
9291
}
9392
certPool.AddCert(cert)

examples/mcast/client/main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,14 @@ func main() {
103103
err = req.SetupGet("/oic/res", token) /* msg.Option{
104104
ID: msg.URIQuery,
105105
Value: []byte("rt=oic.wk.d"),
106-
}*/
107-
if err != nil {
106+
}*/if err != nil {
108107
panic(fmt.Errorf("cannot create discover request: %w", err))
109108
}
110109
req.SetMessageID(message.GetMID())
111110
req.SetType(message.NonConfirmable)
112111
defer messagePool.ReleaseMessage(req)
113112

114-
err = s.DiscoveryRequest(req, "224.0.1.187:5683", func(cc *client.Conn, resp *pool.Message) {
113+
err = s.DiscoveryRequest(req, "224.0.1.187:5683", func(cc *client.Conn, _ *pool.Message) {
115114
_, loaded := duplicit.LoadOrStore(cc.RemoteAddr().String(), true)
116115
if loaded {
117116
atomic.AddUint32(&numDuplicit, 1)
@@ -125,7 +124,7 @@ func main() {
125124

126125
previousNum := uint32(0)
127126
if previousDuplicit != nil {
128-
previousDuplicit.Range(func(key, value interface{}) bool {
127+
previousDuplicit.Range(func(key, _ interface{}) bool {
129128
_, ok := duplicit.Load(key)
130129
if !ok {
131130
fmt.Printf("device %v is lost\n", key)

examples/mcast/server/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func main() {
4949

5050
for i := range ifaces {
5151
iface := ifaces[i]
52-
err := l.JoinGroup(&iface, a)
52+
err = l.JoinGroup(&iface, a)
5353
if err != nil {
5454
log.Printf("cannot JoinGroup(%v, %v): %v", iface, a, err)
5555
}

examples/options/server/main.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ import (
99

1010
piondtls "github.com/pion/dtls/v3"
1111
coap "github.com/plgd-dev/go-coap/v3"
12+
dtlsServer "github.com/plgd-dev/go-coap/v3/dtls/server"
1213
"github.com/plgd-dev/go-coap/v3/message"
1314
"github.com/plgd-dev/go-coap/v3/message/codes"
1415
"github.com/plgd-dev/go-coap/v3/mux"
1516
"github.com/plgd-dev/go-coap/v3/options"
16-
17-
dtlsServer "github.com/plgd-dev/go-coap/v3/dtls/server"
1817
tcpServer "github.com/plgd-dev/go-coap/v3/tcp/server"
1918
udpClient "github.com/plgd-dev/go-coap/v3/udp/client"
2019
)
@@ -50,11 +49,11 @@ func handleOnNewConn(cc *udpClient.Conn) {
5049
if !ok {
5150
log.Fatalf("cannot get connection state")
5251
}
53-
clientId := state.IdentityHint
54-
cc.SetContextValue("clientId", clientId)
52+
clientID := state.IdentityHint
53+
cc.SetContextValue("clientId", clientID)
5554
cc.AddOnClose(func() {
56-
clientId := state.IdentityHint
57-
log.Printf("closed connection clientId: %s", clientId)
55+
clientID := state.IdentityHint
56+
log.Printf("closed connection clientId: %s", clientID)
5857
})
5958
}
6059

examples/simple/server/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func loggingMiddleware(next mux.Handler) mux.Handler {
1717
})
1818
}
1919

20-
func handleA(w mux.ResponseWriter, r *mux.Message) {
20+
func handleA(w mux.ResponseWriter, _ *mux.Message) {
2121
err := w.SetResponse(codes.Content, message.TextPlain, bytes.NewReader([]byte("hello world")))
2222
if err != nil {
2323
log.Printf("cannot set response: %v", err)

pkg/cache/cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func NewCache[K comparable, D any]() *Cache[K, D] {
5050

5151
func (c *Cache[K, D]) LoadOrStore(key K, e *Element[D]) (actual *Element[D], loaded bool) {
5252
now := time.Now()
53-
c.Map.ReplaceWithFunc(key, func(oldValue *Element[D], oldLoaded bool) (newValue *Element[D], deleteValue bool) {
53+
c.ReplaceWithFunc(key, func(oldValue *Element[D], oldLoaded bool) (newValue *Element[D], deleteValue bool) {
5454
if oldLoaded {
5555
if !oldValue.IsExpired(now) {
5656
actual = oldValue
@@ -77,7 +77,7 @@ func (c *Cache[K, D]) Load(key K) (actual *Element[D]) {
7777
func (c *Cache[K, D]) CheckExpirations(now time.Time) {
7878
c.Range(func(key K, value *Element[D]) bool {
7979
if value.IsExpired(now) {
80-
c.Map.Delete(key)
80+
c.Delete(key)
8181
value.onExpire(value.Data())
8282
}
8383
return true

0 commit comments

Comments
 (0)