From 52e747b076b8b6e7991a20870d83980f06bb4499 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Wed, 19 Jun 2024 00:25:22 +0200 Subject: [PATCH] Fix linter problems --- .golangci.yml | 5 +---- Makefile | 4 ++-- cmd/soroban-rpc/internal/config/parse.go | 2 ++ cmd/soroban-rpc/internal/daemon/daemon.go | 2 ++ .../internal/network/requestdurationlimiter.go | 13 ++++++++----- cmd/soroban-rpc/main.go | 2 +- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d61b70c7..9799847f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -76,10 +76,7 @@ linters-settings: # Forbid the following identifiers (list of regexp). # Default: ["^(fmt\\.Print(|f|ln)|print|println)$"] forbid: - # Builtin function: - - ^print.*$ - # Optional message that gets included in error reports. - - p: ^fmt\.Print.*$ + - p: "^(fmt\\.Print(|f|ln)|print|println)$" msg: Do not commit debug print statements. - p: .* pkg: ^stellar/go/support/errors$ diff --git a/Makefile b/Makefile index c9e37996..5c40ff71 100644 --- a/Makefile +++ b/Makefile @@ -81,8 +81,8 @@ clean: build-soroban-rpc: build-libpreflight go build -ldflags="${GOLDFLAGS}" ${MACOS_MIN_VER} -o soroban-rpc -trimpath -v ./cmd/soroban-rpc -go-check-changes: - golangci-lint run ./... --new-from-rev $$(git rev-parse HEAD) +go-check-diff-main: + golangci-lint run ./... --new-from-rev $$(git rev-parse origin/main) go-check: golangci-lint run ./... diff --git a/cmd/soroban-rpc/internal/config/parse.go b/cmd/soroban-rpc/internal/config/parse.go index 0ad03f07..6001f5d7 100644 --- a/cmd/soroban-rpc/internal/config/parse.go +++ b/cmd/soroban-rpc/internal/config/parse.go @@ -16,6 +16,7 @@ func parseBool(option *ConfigOption, i interface{}) error { case nil: return nil case bool: + //nolint:forcetypeassert *option.ConfigKey.(*bool) = v case string: lower := strings.ToLower(v) @@ -23,6 +24,7 @@ func parseBool(option *ConfigOption, i interface{}) error { if err != nil { return fmt.Errorf("invalid boolean value %s: %s", option.Name, v) } + //nolint:forcetypeassert *option.ConfigKey.(*bool) = b default: return fmt.Errorf("could not parse boolean %s: %v", option.Name, i) diff --git a/cmd/soroban-rpc/internal/daemon/daemon.go b/cmd/soroban-rpc/internal/daemon/daemon.go index 2e6edd47..bf55fa4a 100644 --- a/cmd/soroban-rpc/internal/daemon/daemon.go +++ b/cmd/soroban-rpc/internal/daemon/daemon.go @@ -67,9 +67,11 @@ func (d *Daemon) GetDB() *db.DB { } func (d *Daemon) GetEndpointAddrs() (net.TCPAddr, *net.TCPAddr) { + //nolint:forcetypeassert addr := d.listener.Addr().(*net.TCPAddr) var adminAddr *net.TCPAddr if d.adminListener != nil { + //nolint:forcetypeassert adminAddr = d.adminListener.Addr().(*net.TCPAddr) } return *addr, adminAddr diff --git a/cmd/soroban-rpc/internal/network/requestdurationlimiter.go b/cmd/soroban-rpc/internal/network/requestdurationlimiter.go index 466b2c14..c5af738f 100644 --- a/cmd/soroban-rpc/internal/network/requestdurationlimiter.go +++ b/cmd/soroban-rpc/internal/network/requestdurationlimiter.go @@ -48,7 +48,7 @@ func MakeHTTPRequestDurationLimiter( warningCounter increasingCounter, limitCounter increasingCounter, logger *log.Entry, -) *httpRequestDurationLimiter { +) http.Handler { // make sure the warning threshold is less then the limit threshold; otherwise, just set it to the limit threshold. if warningThreshold > limitThreshold { warningThreshold = limitThreshold @@ -196,7 +196,7 @@ func (q *httpRequestDurationLimiter) ServeHTTP(res http.ResponseWriter, req *htt } } -type rpcRequestDurationLimiter struct { +type RPCRequestDurationLimiter struct { jrpcDownstreamHandler jrpc2.Handler requestDurationLimiter } @@ -208,13 +208,13 @@ func MakeJrpcRequestDurationLimiter( warningCounter increasingCounter, limitCounter increasingCounter, logger *log.Entry, -) *rpcRequestDurationLimiter { +) *RPCRequestDurationLimiter { // make sure the warning threshold is less then the limit threshold; otherwise, just set it to the limit threshold. if warningThreshold > limitThreshold { warningThreshold = limitThreshold } - return &rpcRequestDurationLimiter{ + return &RPCRequestDurationLimiter{ jrpcDownstreamHandler: downstream, requestDurationLimiter: requestDurationLimiter{ warningThreshold: warningThreshold, @@ -226,7 +226,10 @@ func MakeJrpcRequestDurationLimiter( } } -func (q *rpcRequestDurationLimiter) Handle(ctx context.Context, req *jrpc2.Request) (interface{}, error) { +// TODO: this function is too complicated we should fix this and remove the nolint:gocognit +// +//nolint:gocognit,cyclop +func (q *RPCRequestDurationLimiter) Handle(ctx context.Context, req *jrpc2.Request) (interface{}, error) { if q.limitThreshold == RequestDurationLimiterNoLimit { // if specified max duration, pass-through return q.jrpcDownstreamHandler(ctx, req) diff --git a/cmd/soroban-rpc/main.go b/cmd/soroban-rpc/main.go index 260e46ee..002a0ee8 100644 --- a/cmd/soroban-rpc/main.go +++ b/cmd/soroban-rpc/main.go @@ -38,7 +38,7 @@ func main() { Short: "Print version information and exit", Run: func(_ *cobra.Command, _ []string) { if config.CommitHash == "" { - //nolint:forbidgo + //nolint:forbidigo fmt.Printf("soroban-rpc dev\n") } else { // avoid printing the branch for the main branch