Skip to content

Commit 5055748

Browse files
authored
chore(golangci-lint): migrate configuration to v2 (#975)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 2a8568e commit 5055748

File tree

31 files changed

+179
-147
lines changed

31 files changed

+179
-147
lines changed

.github/workflows/golangci-lint.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99

1010
permissions:
1111
contents: read
12-
pull-requests: read
1312

1413
jobs:
1514
golangci:
@@ -21,6 +20,4 @@ jobs:
2120
with:
2221
go-version: 1.23.x
2322
- name: golangci-lint
24-
uses: golangci/golangci-lint-action@v6
25-
with:
26-
only-new-issues: ${{ github.event_name == 'pull_request' && 'true' || 'false' }}
23+
uses: golangci/golangci-lint-action@v7

.golangci.yml

+64-28
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,71 @@
1-
issues:
2-
exclude-dirs:
3-
- docs
4-
max-issues-per-linter: 0
5-
max-same-issues: 0
1+
version: "2"
2+
run:
3+
issues-exit-code: 1
4+
tests: false
65
linters:
6+
enable:
7+
- asciicheck
8+
- bidichk
9+
- bodyclose
10+
- contextcheck
11+
- copyloopvar
12+
- durationcheck
13+
- errchkjson
14+
- errorlint
15+
- exhaustive
16+
- fatcontext
17+
- gocheckcompilerdirectives
18+
- gochecksumtype
19+
- gomodguard
20+
- gosec
21+
- gosmopolitan
22+
- loggercheck
23+
- makezero
24+
- musttag
25+
- nilerr
26+
- nilnesserr
27+
- noctx
28+
- perfsprint
29+
- prealloc
30+
- protogetter
31+
- reassign
32+
- rowserrcheck
33+
- spancheck
34+
- sqlclosecheck
35+
- testifylint
36+
- usestdlibvars
37+
- whitespace
38+
- zerologlint
739
disable:
840
- asasalint
941
- depguard
1042
- recvcheck
1143
- unparam
44+
exclusions:
45+
generated: lax
46+
presets:
47+
- comments
48+
- common-false-positives
49+
- legacy
50+
- std-error-handling
51+
paths:
52+
- docs
53+
- third_party$
54+
- builtin$
55+
- examples$
56+
issues:
57+
max-issues-per-linter: 0
58+
max-same-issues: 0
59+
formatters:
1260
enable:
13-
- errcheck
14-
- gosimple
15-
- govet
16-
- ineffassign
17-
- staticcheck
18-
- unused
19-
# Defaults above ours below
20-
- copyloopvar
21-
- usestdlibvars
22-
- whitespace
23-
presets:
24-
- bugs
25-
- format
26-
- import
27-
- performance
28-
- unused
29-
#linters-settings:
30-
# errcheck:
31-
# check-type-assertions: true
32-
run:
33-
issues-exit-code: 1
34-
tests: false
35-
timeout: 10m
61+
- gci
62+
- gofmt
63+
- gofumpt
64+
- goimports
65+
exclusions:
66+
generated: lax
67+
paths:
68+
- docs
69+
- third_party$
70+
- builtin$
71+
- examples$

cbor/tags.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (r *Rat) UnmarshalCBOR(cborData []byte) error {
121121
}
122122
// Create new big.Rat with num/denom set to big.Int values above
123123
r.Rat = new(big.Rat)
124-
r.Rat.SetFrac(tmpNum, tmpDenom)
124+
r.SetFrac(tmpNum, tmpDenom)
125125
return nil
126126
}
127127

cmd/gouroboros/chainsync.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func chainSyncRollForwardHandler(
267267
blockHash := v.Hash().Bytes()
268268
var err error
269269
if oConn == nil {
270-
return errors.New("empty ouroboros connection, aborting!")
270+
return errors.New("empty ouroboros connection, aborting")
271271
}
272272
block, err = oConn.BlockFetch().Client.GetBlock(common.NewPoint(blockSlot, blockHash))
273273
if err != nil {

connection.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func (c *Connection) setupConnection() error {
249249
// Check network magic value
250250
if c.networkMagic == 0 {
251251
return fmt.Errorf(
252-
"invalid network magic value provided: %d\n",
252+
"invalid network magic value provided: %d",
253253
c.networkMagic,
254254
)
255255
}

ledger/allegra/allegra.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,15 @@ func (t *AllegraTransaction) Cbor() []byte {
326326
func NewAllegraBlockFromCbor(data []byte) (*AllegraBlock, error) {
327327
var allegraBlock AllegraBlock
328328
if _, err := cbor.Decode(data, &allegraBlock); err != nil {
329-
return nil, fmt.Errorf("Allegra block decode error: %w", err)
329+
return nil, fmt.Errorf("decode Allegra block error: %w", err)
330330
}
331331
return &allegraBlock, nil
332332
}
333333

334334
func NewAllegraBlockHeaderFromCbor(data []byte) (*AllegraBlockHeader, error) {
335335
var allegraBlockHeader AllegraBlockHeader
336336
if _, err := cbor.Decode(data, &allegraBlockHeader); err != nil {
337-
return nil, fmt.Errorf("Allegra block header decode error: %w", err)
337+
return nil, fmt.Errorf("decode Allegra block header error: %w", err)
338338
}
339339
return &allegraBlockHeader, nil
340340
}
@@ -344,15 +344,15 @@ func NewAllegraTransactionBodyFromCbor(
344344
) (*AllegraTransactionBody, error) {
345345
var allegraTx AllegraTransactionBody
346346
if _, err := cbor.Decode(data, &allegraTx); err != nil {
347-
return nil, fmt.Errorf("Allegra transaction body decode error: %w", err)
347+
return nil, fmt.Errorf("decode Allegra transaction body error: %w", err)
348348
}
349349
return &allegraTx, nil
350350
}
351351

352352
func NewAllegraTransactionFromCbor(data []byte) (*AllegraTransaction, error) {
353353
var allegraTx AllegraTransaction
354354
if _, err := cbor.Decode(data, &allegraTx); err != nil {
355-
return nil, fmt.Errorf("Allegra transaction decode error: %w", err)
355+
return nil, fmt.Errorf("decode Allegra transaction error: %w", err)
356356
}
357357
return &allegraTx, nil
358358
}

ledger/alonzo/alonzo.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -528,15 +528,15 @@ func (t *AlonzoTransaction) Utxorpc() *utxorpc.Tx {
528528
func NewAlonzoBlockFromCbor(data []byte) (*AlonzoBlock, error) {
529529
var alonzoBlock AlonzoBlock
530530
if _, err := cbor.Decode(data, &alonzoBlock); err != nil {
531-
return nil, fmt.Errorf("Alonzo block decode error: %w", err)
531+
return nil, fmt.Errorf("decode Alonzo block error: %w", err)
532532
}
533533
return &alonzoBlock, nil
534534
}
535535

536536
func NewAlonzoBlockHeaderFromCbor(data []byte) (*AlonzoBlockHeader, error) {
537537
var alonzoBlockHeader AlonzoBlockHeader
538538
if _, err := cbor.Decode(data, &alonzoBlockHeader); err != nil {
539-
return nil, fmt.Errorf("Alonzo block header decode error: %w", err)
539+
return nil, fmt.Errorf("decode Alonzo block header error: %w", err)
540540
}
541541
return &alonzoBlockHeader, nil
542542
}
@@ -546,15 +546,15 @@ func NewAlonzoTransactionBodyFromCbor(
546546
) (*AlonzoTransactionBody, error) {
547547
var alonzoTx AlonzoTransactionBody
548548
if _, err := cbor.Decode(data, &alonzoTx); err != nil {
549-
return nil, fmt.Errorf("Alonzo transaction body decode error: %w", err)
549+
return nil, fmt.Errorf("decode Alonzo transaction body error: %w", err)
550550
}
551551
return &alonzoTx, nil
552552
}
553553

554554
func NewAlonzoTransactionFromCbor(data []byte) (*AlonzoTransaction, error) {
555555
var alonzoTx AlonzoTransaction
556556
if _, err := cbor.Decode(data, &alonzoTx); err != nil {
557-
return nil, fmt.Errorf("Alonzo transaction decode error: %w", err)
557+
return nil, fmt.Errorf("decode Alonzo transaction error: %w", err)
558558
}
559559
return &alonzoTx, nil
560560
}
@@ -565,7 +565,7 @@ func NewAlonzoTransactionOutputFromCbor(
565565
var alonzoTxOutput AlonzoTransactionOutput
566566
if _, err := cbor.Decode(data, &alonzoTxOutput); err != nil {
567567
return nil, fmt.Errorf(
568-
"Alonzo transaction output decode error: %w",
568+
"decode Alonzo transaction output error: %w",
569569
err,
570570
)
571571
}

ledger/babbage/babbage.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -684,15 +684,15 @@ func (t *BabbageTransaction) Utxorpc() *utxorpc.Tx {
684684
func NewBabbageBlockFromCbor(data []byte) (*BabbageBlock, error) {
685685
var babbageBlock BabbageBlock
686686
if _, err := cbor.Decode(data, &babbageBlock); err != nil {
687-
return nil, fmt.Errorf("Babbage block decode error: %w", err)
687+
return nil, fmt.Errorf("decode Babbage block error: %w", err)
688688
}
689689
return &babbageBlock, nil
690690
}
691691

692692
func NewBabbageBlockHeaderFromCbor(data []byte) (*BabbageBlockHeader, error) {
693693
var babbageBlockHeader BabbageBlockHeader
694694
if _, err := cbor.Decode(data, &babbageBlockHeader); err != nil {
695-
return nil, fmt.Errorf("Babbage block header decode error: %w", err)
695+
return nil, fmt.Errorf("decode Babbage block header error: %w", err)
696696
}
697697
return &babbageBlockHeader, nil
698698
}
@@ -702,15 +702,15 @@ func NewBabbageTransactionBodyFromCbor(
702702
) (*BabbageTransactionBody, error) {
703703
var babbageTx BabbageTransactionBody
704704
if _, err := cbor.Decode(data, &babbageTx); err != nil {
705-
return nil, fmt.Errorf("Babbage transaction body decode error: %w", err)
705+
return nil, fmt.Errorf("decode Babbage transaction body error: %w", err)
706706
}
707707
return &babbageTx, nil
708708
}
709709

710710
func NewBabbageTransactionFromCbor(data []byte) (*BabbageTransaction, error) {
711711
var babbageTx BabbageTransaction
712712
if _, err := cbor.Decode(data, &babbageTx); err != nil {
713-
return nil, fmt.Errorf("Babbage transaction decode error: %w", err)
713+
return nil, fmt.Errorf("decode Babbage transaction error: %w", err)
714714
}
715715
return &babbageTx, nil
716716
}
@@ -721,7 +721,7 @@ func NewBabbageTransactionOutputFromCbor(
721721
var babbageTxOutput BabbageTransactionOutput
722722
if _, err := cbor.Decode(data, &babbageTxOutput); err != nil {
723723
return nil, fmt.Errorf(
724-
"Babbage transaction output decode error: %w",
724+
"decode Babbage transaction output error: %w",
725725
err,
726726
)
727727
}

ledger/byron/byron.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ func NewByronEpochBoundaryBlockFromCbor(
683683
) (*ByronEpochBoundaryBlock, error) {
684684
var byronEbbBlock ByronEpochBoundaryBlock
685685
if _, err := cbor.Decode(data, &byronEbbBlock); err != nil {
686-
return nil, fmt.Errorf("Byron EBB block decode error: %w", err)
686+
return nil, fmt.Errorf("decode Byron EBB block error: %w", err)
687687
}
688688
return &byronEbbBlock, nil
689689
}
@@ -693,15 +693,15 @@ func NewByronEpochBoundaryBlockHeaderFromCbor(
693693
) (*ByronEpochBoundaryBlockHeader, error) {
694694
var byronEbbBlockHeader ByronEpochBoundaryBlockHeader
695695
if _, err := cbor.Decode(data, &byronEbbBlockHeader); err != nil {
696-
return nil, fmt.Errorf("Byron EBB block header decode error: %w", err)
696+
return nil, fmt.Errorf("decode Byron EBB block header error: %w", err)
697697
}
698698
return &byronEbbBlockHeader, nil
699699
}
700700

701701
func NewByronMainBlockFromCbor(data []byte) (*ByronMainBlock, error) {
702702
var byronMainBlock ByronMainBlock
703703
if _, err := cbor.Decode(data, &byronMainBlock); err != nil {
704-
return nil, fmt.Errorf("Byron main block decode error: %w", err)
704+
return nil, fmt.Errorf("decode Byron main block error: %w", err)
705705
}
706706
return &byronMainBlock, nil
707707
}
@@ -711,15 +711,15 @@ func NewByronMainBlockHeaderFromCbor(
711711
) (*ByronMainBlockHeader, error) {
712712
var byronMainBlockHeader ByronMainBlockHeader
713713
if _, err := cbor.Decode(data, &byronMainBlockHeader); err != nil {
714-
return nil, fmt.Errorf("Byron main block header decode error: %w", err)
714+
return nil, fmt.Errorf("decode Byron main block header error: %w", err)
715715
}
716716
return &byronMainBlockHeader, nil
717717
}
718718

719719
func NewByronTransactionFromCbor(data []byte) (*ByronTransaction, error) {
720720
var byronTx ByronTransaction
721721
if _, err := cbor.Decode(data, &byronTx); err != nil {
722-
return nil, fmt.Errorf("Byron transaction decode error: %w", err)
722+
return nil, fmt.Errorf("decode Byron transaction error: %w", err)
723723
}
724724
return &byronTx, nil
725725
}

ledger/common/address.go

+8-11
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,12 @@ func (a Address) ByronType() uint64 {
301301
// PaymentAddress returns a new Address with only the payment address portion. This will return nil for anything other than payment and script addresses
302302
func (a Address) PaymentAddress() *Address {
303303
var addrType uint8
304-
if a.addressType == AddressTypeKeyKey ||
305-
a.addressType == AddressTypeKeyNone {
304+
switch a.addressType {
305+
case AddressTypeKeyKey, AddressTypeKeyNone:
306306
addrType = AddressTypeKeyNone
307-
} else if a.addressType == AddressTypeScriptKey ||
308-
a.addressType == AddressTypeScriptNone ||
309-
a.addressType == AddressTypeScriptScript {
307+
case AddressTypeScriptKey, AddressTypeScriptNone, AddressTypeScriptScript:
310308
addrType = AddressTypeScriptNone
311-
} else {
309+
default:
312310
// Unsupported address type
313311
return nil
314312
}
@@ -332,13 +330,12 @@ func (a *Address) PaymentKeyHash() Blake2b224 {
332330
// StakeAddress returns a new Address with only the stake key portion. This will return nil if the address is not a payment/staking key pair
333331
func (a Address) StakeAddress() *Address {
334332
var addrType uint8
335-
if a.addressType == AddressTypeKeyKey ||
336-
a.addressType == AddressTypeScriptKey {
333+
switch a.addressType {
334+
case AddressTypeKeyKey, AddressTypeScriptKey:
337335
addrType = AddressTypeNoneKey
338-
} else if a.addressType == AddressTypeScriptScript ||
339-
a.addressType == AddressTypeNoneScript {
336+
case AddressTypeScriptScript, AddressTypeNoneScript:
340337
addrType = AddressTypeNoneScript
341-
} else {
338+
default:
342339
// Unsupported address type
343340
return nil
344341
}

ledger/common/genesis.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type GenesisRat struct {
2626

2727
func (r *GenesisRat) UnmarshalJSON(data []byte) error {
2828
r.Rat = new(big.Rat)
29-
if _, ok := r.Rat.SetString(string(data)); !ok {
29+
if _, ok := r.SetString(string(data)); !ok {
3030
return fmt.Errorf("math/big: cannot unmarshal %q into a *big.Rat", data)
3131
}
3232
return nil

ledger/conway/conway.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,15 @@ func (t *ConwayTransaction) Utxorpc() *utxorpc.Tx {
490490
func NewConwayBlockFromCbor(data []byte) (*ConwayBlock, error) {
491491
var conwayBlock ConwayBlock
492492
if _, err := cbor.Decode(data, &conwayBlock); err != nil {
493-
return nil, fmt.Errorf("Conway block decode error: %w", err)
493+
return nil, fmt.Errorf("decode Conway block error: %w", err)
494494
}
495495
return &conwayBlock, nil
496496
}
497497

498498
func NewConwayBlockHeaderFromCbor(data []byte) (*ConwayBlockHeader, error) {
499499
var conwayBlockHeader ConwayBlockHeader
500500
if _, err := cbor.Decode(data, &conwayBlockHeader); err != nil {
501-
return nil, fmt.Errorf("Conway block header decode error: %w", err)
501+
return nil, fmt.Errorf("decode Conway block header error: %w", err)
502502
}
503503
return &conwayBlockHeader, nil
504504
}
@@ -508,15 +508,15 @@ func NewConwayTransactionBodyFromCbor(
508508
) (*ConwayTransactionBody, error) {
509509
var conwayTx ConwayTransactionBody
510510
if _, err := cbor.Decode(data, &conwayTx); err != nil {
511-
return nil, fmt.Errorf("Conway transaction body decode error: %w", err)
511+
return nil, fmt.Errorf("decode Conway transaction body error: %w", err)
512512
}
513513
return &conwayTx, nil
514514
}
515515

516516
func NewConwayTransactionFromCbor(data []byte) (*ConwayTransaction, error) {
517517
var conwayTx ConwayTransaction
518518
if _, err := cbor.Decode(data, &conwayTx); err != nil {
519-
return nil, fmt.Errorf("Conway transaction decode error: %w", err)
519+
return nil, fmt.Errorf("decode Conway transaction error: %w", err)
520520
}
521521
return &conwayTx, nil
522522
}

0 commit comments

Comments
 (0)