Skip to content

Commit

Permalink
chore(fmt/linters): enable nilerr, nilnil, nolintlint and fix related…
Browse files Browse the repository at this point in the history
… issues (celestiaorg#3332)

Enables nilerr, nilnil, nolintlint checks as well as fixing issues found
by those linters
  • Loading branch information
walldiss committed Apr 29, 2024
1 parent e53e612 commit a25773c
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ linters:
- misspell
# - maligned
- nakedret
- nilerr
- nilnil
- nolintlint
- prealloc
# - scopelint - deprecated since v1.39. exportloopref will be used instead
- exportloopref
Expand Down
4 changes: 2 additions & 2 deletions core/eds.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// nil is returned in place of the eds.
func extendBlock(data types.Data, appVersion uint64, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare, error) {
if app.IsEmptyBlock(data, appVersion) {
return nil, nil
return share.EmptyExtendedDataSquare(), nil
}

// Construct the data square from the block's transactions
Expand Down Expand Up @@ -62,7 +62,7 @@ func storeEDS(
store *eds.Store,
window pruner.AvailabilityWindow,
) error {
if eds == nil {
if eds.Equals(share.EmptyExtendedDataSquare()) {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions core/eds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestTrulyEmptySquare(t *testing.T) {

eds, err := extendBlock(data, appconsts.LatestVersion)
require.NoError(t, err)
assert.Nil(t, eds)
require.True(t, eds.Equals(share.EmptyExtendedDataSquare()))
}

// TestNonZeroSquareSize tests that the DAH hash of a block with no transactions
Expand All @@ -39,8 +39,8 @@ func TestEmptySquareWithZeroTxs(t *testing.T) {
}

eds, err := extendBlock(data, appconsts.LatestVersion)
require.Nil(t, eds)
require.NoError(t, err)
require.True(t, eds.Equals(share.EmptyExtendedDataSquare()))

// force extend the square using an empty block and compare with the min DAH
eds, err = app.ExtendBlock(data, appconsts.LatestVersion)
Expand Down
4 changes: 2 additions & 2 deletions das/daser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ func (m getterStub) GetRangeByHeight(
*header.ExtendedHeader,
uint64,
) ([]*header.ExtendedHeader, error) {
return nil, nil
panic("implement me")
}

func (m getterStub) Get(context.Context, libhead.Hash) (*header.ExtendedHeader, error) {
return nil, nil
panic("implement me")
}
2 changes: 1 addition & 1 deletion nodebuilder/fraud/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (breaker *ServiceBreaker[S, H]) Stop(ctx context.Context) error {

if breaker.ctx.Err() != nil {
// short circuit if the service was already stopped
return nil
return nil //nolint:nilerr
}

breaker.sub.Cancel()
Expand Down
3 changes: 2 additions & 1 deletion nodebuilder/node/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package node

import (
"context"
"fmt"
"time"

logging "github.com/ipfs/go-log/v2"
Expand Down Expand Up @@ -72,7 +73,7 @@ func WithMetrics(lc fx.Lifecycle) error {

clientReg, err := meter.RegisterCallback(callback, nodeStartTS, totalNodeRunTime, buildInfoGauge)
if err != nil {
return nil
return fmt.Errorf("failed to register metrics callback: %w", err)
}

lc.Append(
Expand Down
2 changes: 1 addition & 1 deletion share/eds/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (bs *blockstore) Has(ctx context.Context, cid cid.Cid) (bool, error) {
// key wasn't found in top level blockstore, but could be in datastore while being reconstructed
dsHas, dsErr := bs.ds.Has(ctx, dshelp.MultihashToDsKey(cid.Hash()))
if dsErr != nil {
return false, nil
return false, nil //nolint:nilerr // return false if error
}
return dsHas, nil
}
Expand Down
2 changes: 1 addition & 1 deletion share/p2p/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (d *Discovery) discover(ctx context.Context) bool {
wg.Go(func() error {
if findCtx.Err() != nil {
log.Debug("find has been canceled, skip peer")
return nil
return nil //nolint:nilerr
}

// we don't pass findCtx so that we don't cancel in progress connections
Expand Down
2 changes: 1 addition & 1 deletion state/core_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ func (ca *CoreAccessor) GrantFee(

msg, err := feegrant.NewMsgGrantAllowance(allowance, granter, grantee)
if err != nil {
return nil, nil
return nil, err
}

resp, err := signer.SubmitTx(ctx, []sdktypes.Msg{msg}, user.SetGasLimit(gasLim), withFee(fee))
Expand Down

0 comments on commit a25773c

Please sign in to comment.