Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golangci-lint: update ruleset #706

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 50 additions & 18 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
run:
timeout: 15m0s
linters:
enable:
- exhaustive
Expand All @@ -7,15 +9,18 @@ linters:
- gosec
- misspell
- rowserrcheck
disable:
# These are all considered deprecated: https://github.com/golangci/golangci-lint/issues/1841
- deadcode
- structcheck
- unused
- varcheck
- errorlint
- unconvert
- sqlclosecheck
- noctx
- whitespace
- depguard
- containedctx
linters-settings:
exhaustive:
default-signifies-exhaustive: true
goimports:
local-prefixes: github.com/smartcontractkit/chainlink-solana
golint:
min-confidence: 1.0
gosec:
Expand All @@ -28,6 +33,9 @@ linters-settings:
govet:
# report about shadowed variables
check-shadowing: true
errorlint:
# Allow formatting of errors without %w
errorf: false
revive:
confidence: 0.8
rules:
Expand All @@ -38,10 +46,10 @@ linters-settings:
- name: error-return
- name: error-strings
- name: error-naming
# - name: exported
- name: exported
- name: if-return
- name: increment-decrement
# - name: var-naming
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
Expand All @@ -60,30 +68,54 @@ linters-settings:
- name: struct-tag
# - name: string-format
- name: string-of-int
# - name: range-val-address
- name: range-val-address
- name: range-val-in-closure
- name: modifies-value-receiver
- name: modifies-parameter
- name: identical-branches
- name: get-return
# - name: flag-parameter
# - name: early-return
- name: early-return
- name: defer
- name: constant-logical-expr
# - name: confusing-naming
# - name: confusing-results
- name: bool-literal-in-expr
- name: atomic
depguard:
rules:
main:
list-mode: lax
deny:
- pkg: "cosmossdk.io/errors"
desc: Use the standard library instead
- pkg: "github.com/ethereum/go-ethereum"
desc: This is chain must be isolated from ethereum
- pkg: "github.com/go-gorm/gorm"
desc: Use github.com/jmoiron/sqlx directly instead
- pkg: "github.com/gofrs/uuid"
desc: Use github.com/google/uuid instead
- pkg: "github.com/pkg/errors"
desc: Use the standard library instead, for example https://pkg.go.dev/errors#Join
- pkg: "github.com/satori/go.uuid"
desc: Use github.com/google/uuid instead
- pkg: "github.com/test-go/testify/assert"
desc: Use github.com/stretchr/testify/assert instead
- pkg: "github.com/test-go/testify/mock"
desc: Use github.com/stretchr/testify/mock instead
- pkg: "github.com/test-go/testify/require"
desc: Use github.com/stretchr/testify/require instead
- pkg: "go.uber.org/multierr"
desc: Use the standard library instead, for example https://pkg.go.dev/errors#Join
- pkg: "gopkg.in/guregu/null.v1"
desc: Use gopkg.in/guregu/null.v4 instead
- pkg: "gopkg.in/guregu/null.v2"
desc: Use gopkg.in/guregu/null.v4 instead
- pkg: "gopkg.in/guregu/null.v3"
desc: Use gopkg.in/guregu/null.v4 instead
issues:
exclude-rules:
- path: test
text: "^G404:"
linters:
- gosec
include:
# Enable GoDoc comment checks.
- EXC0002
- EXC0011
- EXC0012
- EXC0013
- EXC0014
- gosec
4 changes: 2 additions & 2 deletions Makefile
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should drop in @HenryNguyen5 's script or similar here

Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ gomodtidy:

.PHONY: lint-go-integration-tests
lint-go-integration-tests:
cd ./integration-tests && golangci-lint --color=always --exclude=dot-imports --timeout 10m --out-format checkstyle:golangci-lint-integration-tests-report.xml run || true
cd ./integration-tests && golangci-lint --max-issues-per-linter 0 --max-same-issues 0 --color=always --exclude=dot-imports --timeout 10m --out-format checkstyle:golangci-lint-integration-tests-report.xml run || true

.PHONY: lint-go-relay
lint-go-relay:
cd ./pkg && golangci-lint --color=always --exclude=dot-imports --timeout 10m --out-format checkstyle:golangci-lint-relay-report.xml run || true
cd ./pkg && golangci-lint --max-issues-per-linter 0 --max-same-issues 0 --color=always --exclude=dot-imports --timeout 10m --out-format checkstyle:golangci-lint-relay-report.xml run || true

.PHONY: upgrade-e2e-solana-image
upgrade-e2e-solana-image:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ require (
github.com/hashicorp/go-plugin v1.6.0
github.com/mitchellh/mapstructure v1.5.0
github.com/pelletier/go-toml/v2 v2.1.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.17.0
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240507142850-569a909ad3b4
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052
github.com/stretchr/testify v1.9.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.26.0
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
golang.org/x/sync v0.6.0
Expand Down Expand Up @@ -77,6 +75,7 @@ require (
github.com/mwitkow/grpc-proxy v0.0.0-20230212185441-f345521cb9c9 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/onsi/gomega v1.24.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
Expand Down Expand Up @@ -104,6 +103,7 @@ require (
go.opentelemetry.io/otel/sdk v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/ratelimit v0.2.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/mod v0.14.0 // indirect
Expand Down
10 changes: 3 additions & 7 deletions integration-tests/common/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
"github.com/rs/zerolog/log"
"github.com/stretchr/testify/require"

test_env_sol "github.com/smartcontractkit/chainlink-solana/integration-tests/docker/test_env"
"github.com/smartcontractkit/chainlink-solana/integration-tests/solclient"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/utils/osutil"
"github.com/smartcontractkit/chainlink/integration-tests/testconfig"

test_env_sol "github.com/smartcontractkit/chainlink-solana/integration-tests/docker/test_env"
"github.com/smartcontractkit/chainlink-solana/integration-tests/solclient"

"golang.org/x/sync/errgroup"

"github.com/smartcontractkit/chainlink/integration-tests/client"
Expand Down Expand Up @@ -117,7 +118,6 @@ type ProposalAcceptConfig struct {
}

func NewOCRv2State(t *testing.T, contracts int, namespacePrefix string, env string, isK8s bool, testConfig *testconfig.TestConfig) (*OCRv2TestState, error) {

c, err := New(env, isK8s).Default(t, namespacePrefix)
if err != nil {
return nil, err
Expand Down Expand Up @@ -260,7 +260,6 @@ func (m *OCRv2TestState) NewSolanaClientSetup(networkSettings *solclient.SolNetw
Interface("URLs", networkSettings.URLs).
Msg("Connected Solana client")
return ec, nil

}

func (m *OCRv2TestState) SetupClients() {
Expand Down Expand Up @@ -465,7 +464,6 @@ func (m *OCRv2TestState) ValidateRoundsAfter(chaosStartTime time.Time, timeout t
}

func (m *OCRv2TestState) GenerateOnChainConfig(nodeKeys []client.NodeKeysBundle, vaultAddress string, proposalId string) (OCR2OnChainConfig, error) {

var oracles []Operator

for _, nodeKey := range nodeKeys {
Expand Down Expand Up @@ -501,7 +499,6 @@ func (m *OCRv2TestState) GenerateOffChainConfig(
secret string,

) OCROffChainConfig {

offchainPublicKeys := make([]string, len(nodeKeysBundle))
peerIds := make([]string, len(nodeKeysBundle))
configPublicKeys := make([]string, len(nodeKeysBundle))
Expand Down Expand Up @@ -631,7 +628,6 @@ func (m *OCRv2TestState) ConfigureGauntlet(secret string) map[string]string {
"LINK": linkToken,
"VAULT": vault,
}

}

// GauntletEnvToRemoteRunner Setup the environment variables that will be needed inside the remote runner
Expand Down
5 changes: 3 additions & 2 deletions integration-tests/docker/test_env/sol.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import (
tcwait "github.com/testcontainers/testcontainers-go/wait"
"golang.org/x/exp/slices"

"github.com/smartcontractkit/chainlink-solana/integration-tests/utils"
"github.com/smartcontractkit/chainlink-testing-framework/docker/test_env"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext"

"github.com/smartcontractkit/chainlink-solana/integration-tests/utils"
)

const (
Expand Down Expand Up @@ -211,7 +212,7 @@ func (f InactiveFeatures) CLIString() string {
}

// GetInactiveFeatureHashes uses the solana CLI to fetch inactive solana features
// This is used in conjuction with the solana-test-validator command to produce a solana network that has the same features as mainnet
// This is used in conjunction with the solana-test-validator command to produce a solana network that has the same features as mainnet
// the solana-test-validator has all features on by default (released + unreleased)
func GetInactiveFeatureHashes(url string) (output InactiveFeatures, err error) {
cmd := exec.Command("solana", "feature", "status", "-u="+url, "--output=json") // -um is for mainnet url
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/gauntlet/gauntlet_solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package gauntlet
import (
"encoding/json"
"fmt"
"github.com/smartcontractkit/chainlink-solana/integration-tests/common"
"os"

"github.com/smartcontractkit/chainlink-solana/integration-tests/common"

"github.com/smartcontractkit/chainlink-testing-framework/gauntlet"
)

Expand Down
3 changes: 1 addition & 2 deletions integration-tests/smoke/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestSolanaOCRV2Smoke(t *testing.T) {
name string
env map[string]string
}{
{name: "embeded"},
{name: "embedded"},
{name: "plugins", env: map[string]string{
"CL_MEDIAN_CMD": "chainlink-feeds",
"CL_SOLANA_CMD": "chainlink-solana",
Expand Down Expand Up @@ -238,7 +238,6 @@ func TestSolanaGauntletOCRV2Smoke(t *testing.T) {
}
_, err = node.MustCreateJob(jobSpec)
require.NoError(t, err)

}

// Test start
Expand Down
1 change: 1 addition & 0 deletions integration-tests/solclient/access_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package solclient

import (
"github.com/gagliardetto/solana-go"

access_controller2 "github.com/smartcontractkit/chainlink-solana/contracts/generated/access_controller"
)

Expand Down
1 change: 0 additions & 1 deletion integration-tests/solclient/solclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ func (c *Client) AddHeaderEventSubscription(key string, subscriber blockchain.He
}

func SendFunds(senderPrivateKey string, receiverPublicKey string, lamports uint64, rpcClient *rpc.Client, wsClient *ws.Client) error {

// Convert the private key string to a byte slice
var privateKeyBytes []byte
err := json.Unmarshal([]byte(senderPrivateKey), &privateKeyBytes)
Expand Down
1 change: 1 addition & 0 deletions integration-tests/solclient/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"

"github.com/smartcontractkit/chainlink-solana/contracts/generated/store"
relaySol "github.com/smartcontractkit/chainlink-solana/pkg/solana"
)
Expand Down
1 change: 1 addition & 0 deletions pkg/monitoring/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"

pkgSolana "github.com/smartcontractkit/chainlink-solana/pkg/solana"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/monitoring/config/feed_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s SolanaFeedConfig) ToMapping() map[string]interface{} {
"feed_name": s.Name,
"feed_path": s.Path,
"symbol": s.Symbol,
"heartbeat_sec": int64(s.HeartbeatSec),
"heartbeat_sec": s.HeartbeatSec,
"contract_type": s.ContractType,
"contract_status": s.ContractStatus,
"contract_address": s.ContractAddress.Bytes(),
Expand Down
1 change: 1 addition & 0 deletions pkg/monitoring/exporter/feedbalances.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/gagliardetto/solana-go"

commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"

"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/metrics"
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/types"
)
Expand Down
1 change: 1 addition & 0 deletions pkg/monitoring/exporter/feedbalances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"

commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"

"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/metrics"
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/metrics/mocks"
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/testutils"
Expand Down
4 changes: 2 additions & 2 deletions pkg/monitoring/exporter/fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/logger"
commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"
"github.com/smartcontractkit/chainlink-common/pkg/utils"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/metrics/mocks"
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/testutils"
Expand All @@ -19,7 +19,7 @@ import (
)

func TestFees(t *testing.T) {
ctx := utils.Context(t)
ctx := tests.Context(t)
lgr, logs := logger.TestObserved(t, zapcore.ErrorLevel)
m := mocks.NewFees(t)
m.On("Set", mock.Anything, mock.Anything, mock.Anything).Once()
Expand Down
2 changes: 1 addition & 1 deletion pkg/monitoring/exporter/nodebalances.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/gagliardetto/solana-go"
commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"

"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/metrics"
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/types"
)
Expand All @@ -18,7 +19,6 @@ func NewNodeBalancesFactory(log commonMonitoring.Logger, metricsFunc metricsBuil
log,
metricsFunc,
}

}

type nodeBalancesFactory struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/monitoring/exporter/nodebalances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/logger"
commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"
"github.com/smartcontractkit/chainlink-common/pkg/utils"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/metrics"
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/testutils"
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/types"
)

func TestNodeBalances(t *testing.T) {
ctx := utils.Context(t)
ctx := tests.Context(t)
lgr, logs := logger.TestObserved(t, zapcore.ErrorLevel)
factory := NewNodeBalancesFactory(lgr, metrics.NewNodeBalances)

Expand Down
1 change: 1 addition & 0 deletions pkg/monitoring/exporter/reportobservations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"

"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/metrics"
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/types"
)
Expand Down
Loading
Loading