Skip to content

Commit 4518e1e

Browse files
authored
chore: add linter that denies importing math/rand (#270)
1 parent b5b33be commit 4518e1e

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

.golangci.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ linters:
4747
- noctx # noctx finds sending http request without context.Context
4848
- unconvert # Remove unnecessary type conversions
4949
- wastedassign # wastedassign finds wasted assignment statements.
50-
- gomodguard # check for blocked dependencies
50+
- gomodguard # check for blocked dependencies in go.mod
51+
- depguard # check for blocked dependencies in Go files
5152

5253
# all available settings of specific linters
5354
linters-settings:
@@ -115,6 +116,14 @@ linters-settings:
115116
- github.com/elastic/beats/v7:
116117
reason: "There must be no Beats dependency"
117118

119+
depguard:
120+
rules:
121+
main:
122+
list-mode: lax
123+
deny:
124+
- pkg: "math/rand$"
125+
desc: "superseded by math/rand/v2"
126+
118127
staticcheck:
119128
# Select the Go version to target. The default is '1.13'.
120129
go: "1.22.11"

transport/tlscommontest/test_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"encoding/pem"
3030
"fmt"
3131
"math/big"
32-
"math/rand"
32+
"math/rand/v2"
3333
"net"
3434
"os"
3535
"path/filepath"

transport/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package transport
2020
import (
2121
"context"
2222
"fmt"
23-
"math/rand"
23+
"math/rand/v2"
2424
"net"
2525
"strings"
2626
)

0 commit comments

Comments
 (0)