Skip to content

Commit

Permalink
update golangci-lint rules (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Nov 22, 2023
1 parent d7f28e9 commit 6953c5a
Show file tree
Hide file tree
Showing 50 changed files with 81 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
go-version: '1.21'

- name: Install golangci-lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2

# go.work makes it necessary to run linter manually
- name: Run golangci-lint
Expand Down
7 changes: 6 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ linters:
- misspell
- rowserrcheck
- errorlint
- unconvert
- sqlclosecheck
- noctx
- whitespace
linters-settings:
exhaustive:
default-signifies-exhaustive: true
Expand Down Expand Up @@ -40,9 +44,10 @@ linters-settings:
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
# - name: var-naming
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
golang 1.21.1
golangci-lint 1.54.2
golangci-lint 1.55.2
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ install-protoc:
mockery: $(mockery) ## Install mockery.
go install github.com/vektra/mockery/v2@v2.28.1

PHONY: generate

.PHONY: generate
generate: mockery install-protoc
# add our installed protoc to the head of the PATH
# maybe there is a cleaner way to do this
Expand All @@ -27,4 +26,4 @@ generate: mockery install-protoc
.PHONY: golangci-lint
golangci-lint: ## Run golangci-lint for all issues.
[ -d "./golangci-lint" ] || mkdir ./golangci-lint && \
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.54.2 golangci-lint run --max-issues-per-linter 0 --max-same-issues 0 > ./golangci-lint/$(shell date +%Y-%m-%d_%H:%M:%S).txt
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.55.2 golangci-lint run --max-issues-per-linter 0 --max-same-issues 0 > ./golangci-lint/$(shell date +%Y-%m-%d_%H:%M:%S).txt
4 changes: 2 additions & 2 deletions pkg/chains/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func ListNodeStatuses(pageSize int, pageTokenStr string, listFn ListNodeStatusFn
return stats, "", -1, err
}
if total > end {
next_token := &pageToken{Page: t.Page + 1, Size: t.Size}
nextPageToken = next_token.Encode()
nextToken := &pageToken{Page: t.Page + 1, Size: t.Size}
nextPageToken = nextToken.Encode()
}
return stats, nextPageToken, total, nil
}
4 changes: 2 additions & 2 deletions pkg/chains/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ func TestListNodeStatuses(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotStats, gotNext_pageToken, gotTotal, err := ListNodeStatuses(tt.args.pageSize, tt.args.pageToken, tt.args.listFn)
gotStats, gotNextPageToken, gotTotal, err := ListNodeStatuses(tt.args.pageSize, tt.args.pageToken, tt.args.listFn)
if (err != nil) != tt.wantErr {
t.Errorf("ListNodeStatuses() error = %v, wantErr %v", err, tt.wantErr)
return
}
assert.Equal(t, tt.wantStats, gotStats)
assert.Equal(t, tt.wantNextPageToken, gotNext_pageToken)
assert.Equal(t, tt.wantNextPageToken, gotNextPageToken)
assert.Equal(t, tt.wantTotal, gotTotal)
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (d *Duration) UnmarshalJSON(input []byte) error {
if err != nil {
return err
}
v, err := time.ParseDuration(string(txt))
v, err := time.ParseDuration(txt)
if err != nil {
return err
}
Expand Down
3 changes: 0 additions & 3 deletions pkg/loop/adapters/starknet/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type Signature struct {

func (s *Signature) Bytes() ([]byte, error) {
return proto.Marshal(s.sig)

}

func (s *Signature) Ints() (x *big.Int, y *big.Int, err error) {
Expand All @@ -41,7 +40,6 @@ func SignatureFromBytes(b []byte) (*Signature, error) {

// x,y must be non-negative numbers
func SignatureFromBigInts(x *big.Int, y *big.Int) (*Signature, error) {

if x.Cmp(big.NewInt(0)) < 0 || y.Cmp(big.NewInt(0)) < 0 {
return nil, fmt.Errorf("Cannot create signature from negative values (x,y), (%v, %v)", x, y)
}
Expand All @@ -53,5 +51,4 @@ func SignatureFromBigInts(x *big.Int, y *big.Int) (*Signature, error) {
return &Signature{
sig: starkPb,
}, nil

}
1 change: 0 additions & 1 deletion pkg/loop/adapters/starknet/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
)

func TestSignature(t *testing.T) {

s, err := SignatureFromBigInts(big.NewInt(7),
big.NewInt(11))

Expand Down
2 changes: 1 addition & 1 deletion pkg/loop/internal/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (a *atomicBroker) DialWithOptions(id uint32, opts ...grpc.DialOption) (conn
return a.load().DialWithOptions(id, opts...)
}

func (a *atomicBroker) NextId() uint32 {
func (a *atomicBroker) NextId() uint32 { //nolint:revive
return a.load().NextId()
}

Expand Down
1 change: 0 additions & 1 deletion pkg/loop/internal/median.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ type reportCodecServer struct {
func (r *reportCodecServer) BuildReport(ctx context.Context, request *pb.BuildReportRequest) (*pb.BuildReportReply, error) {
var obs []median.ParsedAttributedObservation
for _, o := range request.Observations {

val, jpfc := o.Value.Int(), o.JulesPerFeeCoin.Int()
if o.Observer > math.MaxUint8 {
return nil, fmt.Errorf("expected uint8 Observer (max %d) but got %d", math.MaxUint8, o.Observer)
Expand Down
1 change: 0 additions & 1 deletion pkg/loop/internal/pipeline_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,4 @@ func (p *pipelineRunnerServiceServer) ExecuteRun(ctx context.Context, rr *pb.Run
return &pb.RunResponse{
Results: taskResults,
}, nil

}
4 changes: 2 additions & 2 deletions pkg/loop/internal/pipeline_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestPipelineRunnerService(t *testing.T) {
context.Background(),
"my-spec",
types.Vars{Vars: map[string]interface{}{"my-vars": true}},
types.Options{MaxTaskDuration: time.Duration(10 * time.Second)},
types.Options{MaxTaskDuration: 10 * time.Second},
)
require.NoError(t, err)
assert.ElementsMatch(t, originalResults, trs)
Expand All @@ -78,7 +78,7 @@ func TestPipelineRunnerService_CallArgs(t *testing.T) {
Vars: map[string]interface{}{"my-vars": true},
}
options := types.Options{
MaxTaskDuration: time.Duration(10 * time.Second),
MaxTaskDuration: 10 * time.Second,
}
_, err := client.ExecuteRun(context.Background(), spec, vars, options)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/loop/internal/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (r *relayerClient) GetChainStatus(ctx context.Context) (types.ChainStatus,
}, nil
}

func (r *relayerClient) ListNodeStatuses(ctx context.Context, pageSize int32, pageToken string) (nodes []types.NodeStatus, next_page_token string, total int, err error) {
func (r *relayerClient) ListNodeStatuses(ctx context.Context, pageSize int32, pageToken string) (nodes []types.NodeStatus, nextPageToken string, total int, err error) {
reply, err := r.relayer.ListNodeStatuses(ctx, &pb.ListNodeStatusesRequest{
PageSize: pageSize,
PageToken: pageToken,
Expand Down Expand Up @@ -417,7 +417,7 @@ func (r *relayerServer) GetChainStatus(ctx context.Context, request *pb.GetChain
}

func (r *relayerServer) ListNodeStatuses(ctx context.Context, request *pb.ListNodeStatusesRequest) (*pb.ListNodeStatusesReply, error) {
nodeConfigs, next_page_token, total, err := r.impl.ListNodeStatuses(ctx, request.PageSize, request.PageToken)
nodeConfigs, nextPageToken, total, err := r.impl.ListNodeStatuses(ctx, request.PageSize, request.PageToken)
if err != nil {
return nil, err
}
Expand All @@ -430,7 +430,7 @@ func (r *relayerServer) ListNodeStatuses(ctx context.Context, request *pb.ListNo
State: n.State,
})
}
return &pb.ListNodeStatusesReply{Nodes: nodes, NextPageToken: next_page_token, Total: int32(total)}, nil
return &pb.ListNodeStatusesReply{Nodes: nodes, NextPageToken: nextPageToken, Total: int32(total)}, nil
}
func (r *relayerServer) Transact(ctx context.Context, request *pb.TransactionRequest) (*emptypb.Empty, error) {
return &emptypb.Empty{}, r.impl.Transact(ctx, request.From, request.To, request.Amount.Int(), request.BalanceCheck)
Expand Down
7 changes: 3 additions & 4 deletions pkg/loop/internal/test/median.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
)

func TestPluginMedian(t *testing.T, p types.PluginMedian) {
func PluginMedian(t *testing.T, p types.PluginMedian) {
PluginMedianTest{&StaticMedianProvider{}}.TestPluginMedian(t, p)
}

Expand All @@ -33,11 +33,11 @@ func (m PluginMedianTest) TestPluginMedian(t *testing.T, p types.PluginMedian) {
factory, err := p.NewMedianFactory(ctx, m.MedianProvider, &staticDataSource{value}, &staticDataSource{juelsPerFeeCoin}, &StaticErrorLog{})
require.NoError(t, err)

TestReportingPluginFactory(t, factory)
ReportingPluginFactory(t, factory)
})
}

func TestReportingPluginFactory(t *testing.T, factory types.ReportingPluginFactory) {
func ReportingPluginFactory(t *testing.T, factory types.ReportingPluginFactory) {
t.Run("ReportingPluginFactory", func(t *testing.T) {
rp, gotRPI, err := factory.NewReportingPlugin(reportingPluginConfig)
require.NoError(t, err)
Expand All @@ -63,7 +63,6 @@ func TestReportingPluginFactory(t *testing.T, factory types.ReportingPluginFacto
assert.True(t, gotShouldTransmit)
})
})

}

type StaticPluginMedian struct{}
Expand Down
8 changes: 3 additions & 5 deletions pkg/loop/internal/test/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,11 @@ func (s staticRelayer) GetChainStatus(ctx context.Context) (types.ChainStatus, e
}

func (s staticRelayer) ListNodeStatuses(ctx context.Context, pageSize int32, pageToken string) ([]types.NodeStatus, string, int, error) {

if limit != pageSize {
return nil, "", -1, fmt.Errorf("expected page_size %d but got %d", limit, pageSize)
}
if pageToken != "" {
return nil, "", -1, fmt.Errorf("expected empty page_token but got %q", pageToken)

}
return nodes, "", total, nil
}
Expand Down Expand Up @@ -148,19 +146,19 @@ func newRelayArgsWithProviderType(_type types.OCR2PluginType) types.RelayArgs {
}
}

func TestPluginRelayer(t *testing.T, p internal.PluginRelayer) {
func RunPluginRelayer(t *testing.T, p internal.PluginRelayer) {
ctx := tests.Context(t)

t.Run("Relayer", func(t *testing.T) {
relayer, err := p.NewRelayer(ctx, ConfigTOML, StaticKeystore{})
require.NoError(t, err)
require.NoError(t, relayer.Start(ctx))
t.Cleanup(func() { assert.NoError(t, relayer.Close()) })
TestRelayer(t, relayer)
RunRelayer(t, relayer)
})
}

func TestRelayer(t *testing.T, relayer internal.Relayer) {
func RunRelayer(t *testing.T, relayer internal.Relayer) {
ctx := tests.Context(t)

t.Run("ConfigProvider", func(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/loop/median_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestMedianService(t *testing.T) {
t.Cleanup(func() { assert.NoError(t, median.Close()) })

t.Run("control", func(t *testing.T) {
test.TestReportingPluginFactory(t, median)
test.ReportingPluginFactory(t, median)
})

t.Run("Kill", func(t *testing.T) {
Expand All @@ -35,7 +35,7 @@ func TestMedianService(t *testing.T) {
// wait for relaunch
time.Sleep(2 * internal.KeepAliveTickDuration)

test.TestReportingPluginFactory(t, median)
test.ReportingPluginFactory(t, median)
})

t.Run("Reset", func(t *testing.T) {
Expand All @@ -44,7 +44,7 @@ func TestMedianService(t *testing.T) {
// wait for relaunch
time.Sleep(2 * internal.KeepAliveTickDuration)

test.TestReportingPluginFactory(t, median)
test.ReportingPluginFactory(t, median)
})
}

Expand All @@ -61,5 +61,5 @@ func TestMedianService_recovery(t *testing.T) {
require.NoError(t, median.Start(tests.Context(t)))
t.Cleanup(func() { assert.NoError(t, median.Close()) })

test.TestReportingPluginFactory(t, median)
test.ReportingPluginFactory(t, median)
}
4 changes: 2 additions & 2 deletions pkg/loop/plugin_median_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestPluginMedian(t *testing.T) {
t.Parallel()

stopCh := newStopCh(t)
test.PluginTest(t, loop.PluginMedianName, &loop.GRPCPluginMedian{PluginServer: test.StaticPluginMedian{}, BrokerConfig: loop.BrokerConfig{Logger: logger.Test(t), StopCh: stopCh}}, test.TestPluginMedian)
test.PluginTest(t, loop.PluginMedianName, &loop.GRPCPluginMedian{PluginServer: test.StaticPluginMedian{}, BrokerConfig: loop.BrokerConfig{Logger: logger.Test(t), StopCh: stopCh}}, test.PluginMedian)

t.Run("proxy", func(t *testing.T) {
test.PluginTest(t, loop.PluginRelayerName, &loop.GRPCPluginRelayer{PluginServer: test.StaticPluginRelayer{}, BrokerConfig: loop.BrokerConfig{Logger: logger.Test(t), StopCh: stopCh}}, func(t *testing.T, pr loop.PluginRelayer) {
Expand All @@ -45,7 +45,7 @@ func TestPluginMedianExec(t *testing.T) {
i, err := client.Dispense(loop.PluginMedianName)
require.NoError(t, err)

test.TestPluginMedian(t, i.(types.PluginMedian))
test.PluginMedian(t, i.(types.PluginMedian))

t.Run("proxy", func(t *testing.T) {
pr := newPluginRelayerExec(t, stopCh)
Expand Down
4 changes: 2 additions & 2 deletions pkg/loop/plugin_relayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestPluginRelayer(t *testing.T) {
t.Parallel()

stopCh := newStopCh(t)
test.PluginTest(t, loop.PluginRelayerName, &loop.GRPCPluginRelayer{PluginServer: test.StaticPluginRelayer{}, BrokerConfig: loop.BrokerConfig{Logger: logger.Test(t), StopCh: stopCh}}, test.TestPluginRelayer)
test.PluginTest(t, loop.PluginRelayerName, &loop.GRPCPluginRelayer{PluginServer: test.StaticPluginRelayer{}, BrokerConfig: loop.BrokerConfig{Logger: logger.Test(t), StopCh: stopCh}}, test.RunPluginRelayer)
}

func TestPluginRelayerExec(t *testing.T) {
Expand All @@ -24,7 +24,7 @@ func TestPluginRelayerExec(t *testing.T) {

pr := newPluginRelayerExec(t, stopCh)

test.TestPluginRelayer(t, pr)
test.RunPluginRelayer(t, pr)
}

func newPluginRelayerExec(t *testing.T, stopCh <-chan struct{}) loop.PluginRelayer {
Expand Down
1 change: 0 additions & 1 deletion pkg/loop/prom.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func (p *PromServer) Start() error {
} else {
p.lggr.Errorf("%s: %s", p.Name(), err)
}

}()
return nil
}
Expand Down
1 change: 0 additions & 1 deletion pkg/loop/prom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
)

func TestPromServer(t *testing.T) {

testReg := prometheus.NewRegistry()
testHandler := promhttp.HandlerFor(testReg, promhttp.HandlerOpts{})
testMetric := prometheus.NewCounter(prometheus.CounterOpts{
Expand Down
8 changes: 4 additions & 4 deletions pkg/loop/relayer_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestRelayerService(t *testing.T) {
t.Cleanup(func() { assert.NoError(t, relayer.Close()) })

t.Run("control", func(t *testing.T) {
test.TestRelayer(t, relayer)
test.RunRelayer(t, relayer)
})

t.Run("Kill", func(t *testing.T) {
Expand All @@ -35,7 +35,7 @@ func TestRelayerService(t *testing.T) {
// wait for relaunch
time.Sleep(2 * internal.KeepAliveTickDuration)

test.TestRelayer(t, relayer)
test.RunRelayer(t, relayer)
})

t.Run("Reset", func(t *testing.T) {
Expand All @@ -44,7 +44,7 @@ func TestRelayerService(t *testing.T) {
// wait for relaunch
time.Sleep(2 * internal.KeepAliveTickDuration)

test.TestRelayer(t, relayer)
test.RunRelayer(t, relayer)
})
}

Expand All @@ -61,5 +61,5 @@ func TestRelayerService_recovery(t *testing.T) {
require.NoError(t, relayer.Start(tests.Context(t)))
t.Cleanup(func() { assert.NoError(t, relayer.Close()) })

test.TestRelayer(t, relayer)
test.RunRelayer(t, relayer)
}
2 changes: 1 addition & 1 deletion pkg/loop/reportingplugins/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func PluginGenericTest(t *testing.T, p types.ReportingPluginClient) {
factory, err := p.NewReportingPluginFactory(ctx, types.ReportingPluginServiceConfig{}, test.MockConn{}, &test.StaticPipelineRunnerService{}, &test.StaticTelemetry{}, &test.StaticErrorLog{})
require.NoError(t, err)

test.TestReportingPluginFactory(t, factory)
test.ReportingPluginFactory(t, factory)
})
}

Expand Down
Loading

0 comments on commit 6953c5a

Please sign in to comment.