Skip to content

Commit 0104878

Browse files
authored
Merge pull request #6383 from oasisprotocol/peternose/internal/bump-golangci-lint
go: Bump golangci-lint to v2.6.0
2 parents b298a95 + abd405e commit 0104878

File tree

72 files changed

+258
-269
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+258
-269
lines changed

.changelog/6383.internal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
go: Bump golangci-lint to v2.6.0

docker/oasis-core-dev/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ARG GO_NANCY_VERSION=1.0.33
66
ARG GO_NANCY_CHECKSUM=a4bf5290d41b095c04f941ed5380674770c79d59735e33b1bd07a5cd5fbb135d
77
ARG GO_PROTOC_VERSION=3.6.1
88
ARG GO_PROTOC_GEN_GO_VERSION=1.21.0
9-
ARG GOLANGCILINT_VERSION=2.3.1
9+
ARG GOLANGCILINT_VERSION=2.6.0
1010
ARG GOCOVMERGE_VERSION=b5bfa59ec0adc420475f97f89b58045c721d761c
1111
ARG GOFUMPT_VERSION=v0.8.0
1212
ARG GOIMPORTS_VERSION=v0.36.0

docs/development-setup/prerequisites.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Core:
151151
```
152152
curl -sSfL \
153153
https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \
154-
| sh -s -- -b $(${OASIS_GO:-go} env GOPATH)/bin v2.3.1
154+
| sh -s -- -b $(${OASIS_GO:-go} env GOPATH)/bin v2.6.0
155155
```
156156
157157
* (**OPTIONAL**) [protoc-gen-go].

go/common/copy.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import (
1616
func CopyFile(src, dst string) (err error) {
1717
in, err := os.Open(src)
1818
if err != nil {
19-
return
19+
return err
2020
}
2121
defer in.Close()
2222

2323
out, err := os.Create(dst)
2424
if err != nil {
25-
return
25+
return err
2626
}
2727
defer func() {
2828
if e := out.Close(); e != nil {
@@ -32,30 +32,30 @@ func CopyFile(src, dst string) (err error) {
3232

3333
_, err = io.Copy(out, in)
3434
if err != nil {
35-
return
35+
return err
3636
}
3737

3838
err = out.Sync()
3939
if err != nil {
40-
return
40+
return err
4141
}
4242

4343
si, err := os.Stat(src)
4444
if err != nil {
45-
return
45+
return err
4646
}
4747
err = os.Chmod(dst, si.Mode())
4848
if err != nil {
49-
return
49+
return err
5050
}
5151

52-
return
52+
return nil
5353
}
5454

5555
// CopyDir recursively copies a directory tree, attempting to preserve permissions.
5656
// Source directory must exist, destination directory must *not* exist.
5757
// Symlinks are ignored and skipped.
58-
func CopyDir(src string, dst string) (err error) {
58+
func CopyDir(src string, dst string) error {
5959
src = filepath.Clean(src)
6060
dst = filepath.Clean(dst)
6161

@@ -69,20 +69,20 @@ func CopyDir(src string, dst string) (err error) {
6969

7070
_, err = os.Stat(dst)
7171
if err != nil && !os.IsNotExist(err) {
72-
return
72+
return err
7373
}
7474
if err == nil {
7575
return fmt.Errorf("destination already exists")
7676
}
7777

7878
err = os.MkdirAll(dst, si.Mode())
7979
if err != nil {
80-
return
80+
return err
8181
}
8282

8383
entries, err := os.ReadDir(src)
8484
if err != nil {
85-
return
85+
return err
8686
}
8787

8888
for _, entry := range entries {
@@ -92,7 +92,7 @@ func CopyDir(src string, dst string) (err error) {
9292
if entry.IsDir() {
9393
err = CopyDir(srcPath, dstPath)
9494
if err != nil {
95-
return
95+
return err
9696
}
9797
} else {
9898
// Skip symlinks.
@@ -102,10 +102,10 @@ func CopyDir(src string, dst string) (err error) {
102102

103103
err = CopyFile(srcPath, dstPath)
104104
if err != nil {
105-
return
105+
return err
106106
}
107107
}
108108
}
109109

110-
return
110+
return nil
111111
}

go/common/crypto/address/address.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ type Address [Size]byte
3434

3535
// MarshalBinary encodes an address into binary form.
3636
func (a Address) MarshalBinary() (data []byte, err error) {
37-
data = append([]byte{}, a[:]...)
38-
return
37+
return append([]byte{}, a[:]...), nil
3938
}
4039

4140
// UnmarshalBinary decodes a binary marshaled address.
@@ -90,7 +89,7 @@ func (a Address) IsValid() bool {
9089
}
9190

9291
// NewAddress creates a new address of specified version from address' context and data.
93-
func NewAddress(ctx Context, data []byte) (a Address) {
92+
func NewAddress(ctx Context, data []byte) Address {
9493
if _, isRegistered := registeredContexts.Load(ctx); !isRegistered {
9594
panic(fmt.Sprintf("address: context %s is not registered", ctx))
9695
}
@@ -101,6 +100,7 @@ func NewAddress(ctx Context, data []byte) (a Address) {
101100
if err != nil {
102101
panic(err)
103102
}
103+
var a Address
104104
_ = a.UnmarshalBinary(append([]byte{ctx.Version}, truncatedHash...))
105-
return
105+
return a
106106
}

go/common/crypto/address/context.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ type Context struct {
2929

3030
// MarshalBinary encodes a context into binary form.
3131
func (c Context) MarshalBinary() (data []byte, err error) {
32-
data = append([]byte(c.Identifier), c.Version)
33-
return
32+
return append([]byte(c.Identifier), c.Version), nil
3433
}
3534

3635
// String returns a string representation of address' context.

go/common/crypto/hash/hash.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ type Hash [Size]byte
3636

3737
// MarshalBinary encodes a hash into binary form.
3838
func (h *Hash) MarshalBinary() (data []byte, err error) {
39-
data = append([]byte{}, h[:]...)
40-
return
39+
return append([]byte{}, h[:]...), nil
4140
}
4241

4342
// UnmarshalBinary decodes a binary marshaled hash.
@@ -139,15 +138,17 @@ func (h Hash) Truncate(n int) ([]byte, error) {
139138
}
140139

141140
// NewFrom creates a new hash by hashing the CBOR representation of the given type.
142-
func NewFrom(v any) (h Hash) {
141+
func NewFrom(v any) Hash {
142+
var h Hash
143143
h.From(v)
144-
return
144+
return h
145145
}
146146

147147
// NewFromBytes creates a new hash by hashing the provided byte string(s).
148-
func NewFromBytes(data ...[]byte) (h Hash) {
148+
func NewFromBytes(data ...[]byte) Hash {
149+
var h Hash
149150
h.FromBytes(data...)
150-
return
151+
return h
151152
}
152153

153154
// NewFromReader creates a new hash by hashing data from the provided reader until EOF.
@@ -161,9 +162,10 @@ func NewFromReader(reader io.Reader) (Hash, error) {
161162

162163
// LoadFromHexBytes creates a new hash by loading it from the given CometBFT
163164
// HexBytes byte array.
164-
func LoadFromHexBytes(data cmtbytes.HexBytes) (h Hash) {
165+
func LoadFromHexBytes(data cmtbytes.HexBytes) Hash {
166+
var h Hash
165167
_ = h.UnmarshalBinary(data[:])
166-
return
168+
return h
167169
}
168170

169171
// Builder is a hash builder that can be used to compute hashes iteratively.
@@ -179,10 +181,11 @@ func (b *Builder) Write(p []byte) (int, error) {
179181

180182
// Build returns the current hash.
181183
// It does not change the underlying hash state.
182-
func (b *Builder) Build() (h Hash) {
184+
func (b *Builder) Build() Hash {
185+
var h Hash
183186
sum := b.hasher.Sum([]byte{})
184187
_ = h.UnmarshalBinary(sum[:])
185-
return
188+
return h
186189
}
187190

188191
// NewBuilder creates a new hash builder.

go/common/crypto/mathrand/rand_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func TestRngAdapter(t *testing.T) {
2828
//
2929
// Sort of silly to do this repeatedly since the results are determinstic.
3030
samples := make([]int, 6)
31-
for i := 0; i < nrSamples; i++ {
32-
samples[rng.Intn(6)]++
31+
for range nrSamples {
32+
samples[rng.Intn(len(samples))]++
3333
}
3434

3535
chiSq, expected := float64(0), float64(nrSamples)/6

go/common/crypto/signature/signature.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ func (k PublicKey) Verify(context Context, message, sig []byte) bool {
109109

110110
// MarshalBinary encodes a public key into binary form.
111111
func (k PublicKey) MarshalBinary() (data []byte, err error) {
112-
data = append([]byte{}, k[:]...)
113-
return
112+
return append([]byte{}, k[:]...), nil
114113
}
115114

116115
// UnmarshalBinary decodes a binary marshaled public key.
@@ -265,8 +264,7 @@ func (r RawSignature) Equal(cmp RawSignature) bool {
265264

266265
// MarshalBinary encodes a signature into binary form.
267266
func (r RawSignature) MarshalBinary() (data []byte, err error) {
268-
data = append([]byte{}, r[:]...)
269-
return
267+
return append([]byte{}, r[:]...), nil
270268
}
271269

272270
// UnmarshalBinary decodes a binary marshaled signature.
@@ -619,7 +617,7 @@ type SignedPublicKey struct {
619617
}
620618

621619
// Open first verifies the blob signature and then unmarshals the blob.
622-
func (s *SignedPublicKey) Open(context Context, pub *PublicKey) error { // nolint: interfacer
620+
func (s *SignedPublicKey) Open(context Context, pub *PublicKey) error {
623621
return s.Signed.Open(context, pub)
624622
}
625623

@@ -649,25 +647,29 @@ func VerifyManyToOne(context Context, message []byte, sigs []Signature) bool {
649647

650648
// NewPublicKey creates a new public key from the given hex representation or
651649
// panics.
652-
func NewPublicKey(hex string) (pk PublicKey) {
650+
func NewPublicKey(hex string) PublicKey {
651+
var pk PublicKey
653652
if err := pk.UnmarshalHex(hex); err != nil {
654653
panic(err)
655654
}
656-
return
655+
return pk
657656
}
658657

659658
// HashToPublicKey creates a public key via h2c from the given domain separator
660659
// and message. The private key of the returned public key is unknown.
661-
func HashToPublicKey(dst, message []byte) (pk PublicKey) {
660+
func HashToPublicKey(dst, message []byte) PublicKey {
662661
point, err := h2c.Edwards25519_XMD_SHA512_ELL2_RO(dst, message)
663662
if err != nil {
664663
panic(err)
665664
}
666665

667666
var aCompressed curve.CompressedEdwardsY
668667
aCompressed.SetEdwardsPoint(point)
668+
669+
var pk PublicKey
669670
copy(pk[:], aCompressed[:])
670-
return
671+
672+
return pk
671673
}
672674

673675
// RegisterTestPublicKey registers a hardcoded test public key with the

go/common/crypto/signature/vrf_signer.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ func (r RawProof) String() string {
9696

9797
// MarshalBinary encodes a VRF proof into binary form.
9898
func (r RawProof) MarshalBinary() (data []byte, err error) {
99-
data = append([]byte{}, r[:]...)
100-
return
99+
return append([]byte{}, r[:]...), nil
101100
}
102101

103102
// UnmarshalBinary decodes a binary marshaled VRF proof.

0 commit comments

Comments
 (0)