Skip to content

Commit

Permalink
ci: .golanci.yml (#142)
Browse files Browse the repository at this point in the history
* fix: solve linting issues

* update: .golangci.yml

* fix: test
  • Loading branch information
JulianToledano committed Aug 7, 2024
1 parent f102605 commit 5b88a3c
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 51 deletions.
19 changes: 17 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ run:
linters:
disable-all: true
enable:
- depguard
- dogsled
- errcheck
- errorlint
- exportloopref
- gci
- goconst
- gocritic
- gofumpt
Expand All @@ -21,9 +23,10 @@ linters:
- misspell
- nakedret
- nolintlint
- staticcheck
- revive
- staticcheck
- stylecheck
- thelper
- typecheck
- unconvert
- unused
Expand Down Expand Up @@ -54,6 +57,18 @@ issues:
max-same-issues: 10000

linters-settings:
gci:
custom-order: true
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(cosmossdk.io)
- prefix(github.com/cosmos/cosmos-sdk)
- prefix(github.com/cosmos/rosetta)
revive:
rules:
- name: redefines-builtin-id
disabled: true
gosec:
# To select a subset of rules to run.
# Available rules: https://github.com/securego/gosec#available-rules
Expand Down
4 changes: 2 additions & 2 deletions client_offline.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

"github.com/coinbase/rosetta-sdk-go/types"

crgerrs "github.com/cosmos/rosetta/lib/errors"

sdk "github.com/cosmos/cosmos-sdk/types"

crgerrs "github.com/cosmos/rosetta/lib/errors"
)

// ---------- cosmos-rosetta-gateway.types.NetworkInformationProvider implementation ------------ //
Expand Down
20 changes: 8 additions & 12 deletions client_online.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,24 @@ import (
"strconv"
"time"

"github.com/cosmos/cosmos-sdk/version"

abcitypes "github.com/cometbft/cometbft/abci/types"

rosettatypes "github.com/coinbase/rosetta-sdk-go/types"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"

abcitypes "github.com/cometbft/cometbft/abci/types"
tmrpc "github.com/cometbft/cometbft/rpc/client"
"github.com/cometbft/cometbft/rpc/client/http"
"google.golang.org/grpc"

crgerrs "github.com/cosmos/rosetta/lib/errors"
crgtypes "github.com/cosmos/rosetta/lib/types"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"

sdk "github.com/cosmos/cosmos-sdk/types"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/version"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
auth "github.com/cosmos/cosmos-sdk/x/auth/types"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"

tmrpc "github.com/cometbft/cometbft/rpc/client"
"github.com/cosmos/cosmos-sdk/types/query"
crgerrs "github.com/cosmos/rosetta/lib/errors"
crgtypes "github.com/cosmos/rosetta/lib/types"
)

// interface assertion
Expand Down
1 change: 1 addition & 0 deletions cmd/rosetta.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"

"github.com/cosmos/rosetta"
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/rosetta/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package main
import (
"os"

"github.com/cosmos/rosetta"

"cosmossdk.io/log"

"github.com/cosmos/rosetta"
rosettaCmd "github.com/cosmos/rosetta/cmd"
)

Expand Down
4 changes: 3 additions & 1 deletion codec.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package rosetta

import (
"github.com/cosmos/gogoproto/proto"

"cosmossdk.io/x/tx/signing"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/address"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -10,7 +13,6 @@ import (
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/types"
bankcodec "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/gogoproto/proto"
)

// MakeCodec generates the codec required to interact
Expand Down
7 changes: 3 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import (
"fmt"
"time"

crgerrs "github.com/cosmos/rosetta/lib/errors"

"github.com/coinbase/rosetta-sdk-go/types"
url "github.com/goware/urlx"
"github.com/spf13/pflag"

crg "github.com/cosmos/rosetta/lib/server"

clientflags "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"

crgerrs "github.com/cosmos/rosetta/lib/errors"
crg "github.com/cosmos/rosetta/lib/server"
)

const (
Expand Down
4 changes: 3 additions & 1 deletion converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import (
"fmt"
"reflect"

signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"
rosettatypes "github.com/coinbase/rosetta-sdk-go/types"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto"
tmcoretypes "github.com/cometbft/cometbft/rpc/core/types"
cmttypes "github.com/cometbft/cometbft/types"
secp "github.com/decred/dcrd/dcrec/secp256k1/v4"

signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"
sdkmath "cosmossdk.io/math"

sdkclient "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -26,6 +27,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

crgerrs "github.com/cosmos/rosetta/lib/errors"
crgtypes "github.com/cosmos/rosetta/lib/types"
)
Expand Down
6 changes: 3 additions & 3 deletions converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import (
"encoding/json"
"testing"

"github.com/cosmos/rosetta"
crgerrs "github.com/cosmos/rosetta/lib/errors"

rosettatypes "github.com/coinbase/rosetta-sdk-go/types"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/stretchr/testify/suite"
Expand All @@ -19,6 +16,9 @@ import (
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/cosmos/rosetta"
crgerrs "github.com/cosmos/rosetta/lib/errors"
)

type ConverterTestSuite struct {
Expand Down
15 changes: 9 additions & 6 deletions lib/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ package errors
// plus some extra utilities to parse those errors

import (
"errors"
"fmt"
"net/http"

grpccodes "google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"

"github.com/coinbase/rosetta-sdk-go/types"
cmttypes "github.com/cometbft/cometbft/rpc/jsonrpc/types"
grpccodes "google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"
)

// ListErrors lists all the registered errors
Expand Down Expand Up @@ -41,7 +41,8 @@ func (e *Error) Error() string {
// if their error codes are identical
func (e *Error) Is(err error) bool {
// assert it can be casted
rosErr, ok := err.(*Error)
var rosErr *Error
ok := errors.As(err, &rosErr)
if rosErr == nil || !ok {
return false
}
Expand Down Expand Up @@ -70,9 +71,11 @@ func WrapError(err *Error, msg string) *Error {
// error, if the error cannot be converted it will be parsed as unknown
func ToRosetta(err error) *types.Error {
// if it's null or not known
rosErr, ok := err.(*Error)
var rosErr *Error
ok := errors.As(err, &rosErr)
if rosErr == nil || !ok {
tmErr, ok := err.(*cmttypes.RPCError)
var tmErr *cmttypes.RPCError
ok := errors.As(err, &tmErr)
if tmErr != nil && ok {
return fromCometToRosettaError(tmErr).rosErr
}
Expand Down
2 changes: 1 addition & 1 deletion lib/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestRegisterError(t *testing.T) {
registeredErrorsCount++
assert.Equal(t, len(ListErrors()), registeredErrorsCount)
// re-register an error should not change anything
RegisterError(69, "nice!", false, "nice!")
_ = RegisterError(69, "nice!", false, "nice!")
assert.Equal(t, len(ListErrors()), registeredErrorsCount)

// test sealing
Expand Down
1 change: 1 addition & 0 deletions lib/internal/service/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/coinbase/rosetta-sdk-go/types"

"github.com/cosmos/rosetta/lib/errors"
crgtypes "github.com/cosmos/rosetta/lib/types"
)
Expand Down
1 change: 1 addition & 0 deletions lib/internal/service/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/coinbase/rosetta-sdk-go/types"

"github.com/cosmos/rosetta/lib/errors"
crgtypes "github.com/cosmos/rosetta/lib/types"
)
Expand Down
6 changes: 4 additions & 2 deletions lib/internal/service/construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"strconv"
"strings"

sdkmath "cosmossdk.io/math"
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/cosmos/rosetta/lib/errors"

sdkmath "cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/rosetta/lib/errors"
)

// ConstructionCombine Combine creates a network-specific transaction from an unsigned transaction
Expand Down
1 change: 1 addition & 0 deletions lib/internal/service/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/coinbase/rosetta-sdk-go/types"

"github.com/cosmos/rosetta/lib/errors"
)

Expand Down
1 change: 1 addition & 0 deletions lib/internal/service/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

coinbase "github.com/coinbase/rosetta-sdk-go/types"

"github.com/cosmos/rosetta/lib/errors"
)

Expand Down
1 change: 1 addition & 0 deletions lib/internal/service/online.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/coinbase/rosetta-sdk-go/types"

"cosmossdk.io/log"

crgerrs "github.com/cosmos/rosetta/lib/errors"
crgtypes "github.com/cosmos/rosetta/lib/types"
)
Expand Down
5 changes: 3 additions & 2 deletions lib/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"time"

"github.com/coinbase/rosetta-sdk-go/types"
assert "github.com/cosmos/rosetta-sdk-go/asserter"
"github.com/cosmos/rosetta-sdk-go/server"

"cosmossdk.io/log"

assert "github.com/cosmos/rosetta-sdk-go/asserter"
"github.com/cosmos/rosetta-sdk-go/server"
"github.com/cosmos/rosetta/lib/internal/service"
crgtypes "github.com/cosmos/rosetta/lib/types"
)
Expand Down
1 change: 1 addition & 0 deletions lib/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/coinbase/rosetta-sdk-go/types"

"github.com/cosmos/rosetta-sdk-go/server"
)

Expand Down
14 changes: 8 additions & 6 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ package rosetta
import (
"context"
"crypto/tls"
"errors"
"fmt"
"io"
"strings"

crgerrs "github.com/cosmos/rosetta/lib/errors"

reflectionv1beta1 "cosmossdk.io/api/cosmos/base/reflection/v1beta1"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/descriptorpb"

reflectionv1beta1 "cosmossdk.io/api/cosmos/base/reflection/v1beta1"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"

crgerrs "github.com/cosmos/rosetta/lib/errors"
)

func ReflectInterfaces(ir codectypes.InterfaceRegistry, endpoint string) (err error) {
Expand Down Expand Up @@ -71,7 +73,7 @@ func getFileDescriptorSet(c context.Context, client *grpc.ClientConn) (fdSet *de
go func() {
for {
in, err := reflectClient.Recv()
if err == io.EOF {
if errors.Is(err, io.EOF) {
close(wait)
return
}
Expand Down
5 changes: 0 additions & 5 deletions plugins/cosmos-hub/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ package main
import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"

// ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
// ibcLightClient "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"

sdk "github.com/cosmos/cosmos-sdk/types"
txtypes "github.com/cosmos/cosmos-sdk/types/tx"

bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)

Expand Down
5 changes: 3 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"strconv"
"time"

authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"google.golang.org/protobuf/types/known/anypb"

v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1"
txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1"
signing2 "cosmossdk.io/x/tx/signing"
"google.golang.org/protobuf/types/known/anypb"

sdk "github.com/cosmos/cosmos-sdk/types"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"

crgerrs "github.com/cosmos/rosetta/lib/errors"
)

Expand Down

0 comments on commit 5b88a3c

Please sign in to comment.