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

chore(lint): cleanup config and enable default linters for our code #764

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.56
version: v1.63
working-directory: .
args: --timeout 3m
skip-pkg-cache: true
Expand Down
41 changes: 29 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

run:
timeout: 10m
tests: true
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
# Include non-test files tagged as test-only.
# Context: https://github.com/ava-labs/avalanchego/pull/3173

linters:
disable-all: true
Expand All @@ -18,13 +12,36 @@ linters:
- ineffassign
- misspell
- unconvert
- typecheck
- unused
- staticcheck
- bidichk
- durationcheck
- copyloopvar
- whitespace
# - revive # only certain checks enabled
- durationcheck
- gocheckcompilerdirectives
- reassign
- mirror
- tenv
- errcheck
- errorlint

linters-settings:
gofmt:
simplify: true
goconst:
min-len: 3 # minimum length of string constant
min-occurrences: 6 # minimum number of occurrences
ignore-tests: true
errorlint:
errorf: false

issues:
exclude-rules:
- path: "_test\\.go"
text: "SA1019: rand\\.(Seed|Read) has been deprecated since Go 1\\.20"
linters:
- staticcheck
- path-except: "(_ext|plugin\\/.+|libevm.*)\\.go"
linters:
- errcheck
- errorlint
- gosimple
- govet
- staticcheck
2 changes: 2 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Release Notes

## Pending Release
- Bump golang version to v1.23.6
- Bump golangci-lint to v1.63 and add linters

## [v0.14.1](https://github.com/ava-labs/coreth/releases/tag/v0.14.1)

Expand Down
1 change: 0 additions & 1 deletion accounts/abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,6 @@ func TestUnpackRevert(t *testing.T) {
{"4e487b7100000000000000000000000000000000000000000000000000000000000000ff", "unknown panic code: 0xff", nil},
}
for index, c := range cases {
index, c := index, c
t.Run(fmt.Sprintf("case %d", index), func(t *testing.T) {
t.Parallel()
got, err := UnpackRevert(common.Hex2Bytes(c.input))
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
}
// Parse library references.
for pattern, name := range libs {
matched, err := regexp.Match("__\\$"+pattern+"\\$__", []byte(contracts[types[i]].InputBin))
matched, err := regexp.MatchString("__\\$"+pattern+"\\$__", contracts[types[i]].InputBin)
if err != nil {
log.Error("Could not search for pattern", "pattern", pattern, "contract", contracts[types[i]], "err", err)
}
Expand Down
1 change: 0 additions & 1 deletion accounts/abi/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ func TestEventTupleUnpack(t *testing.T) {

for _, tc := range testCases {
assert := assert.New(t)
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := unpackTestEventData(tc.dest, tc.data, tc.jsonLog, assert)
if tc.error == "" {
Expand Down
1 change: 0 additions & 1 deletion accounts/abi/pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (
func TestPack(t *testing.T) {
t.Parallel()
for i, test := range packUnpackTests {
i, test := i, test
t.Run(strconv.Itoa(i), func(t *testing.T) {
t.Parallel()
encb, err := hex.DecodeString(test.packed)
Expand Down
1 change: 0 additions & 1 deletion accounts/abi/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ var reflectTests = []reflectTest{
func TestReflectNameToStruct(t *testing.T) {
t.Parallel()
for _, test := range reflectTests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
m, err := mapArgNamesToStructFields(test.args, reflect.ValueOf(test.struc))
Expand Down
3 changes: 0 additions & 3 deletions accounts/abi/topics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func TestMakeTopics(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := MakeTopics(tt.args.query...)
Expand Down Expand Up @@ -383,7 +382,6 @@ func TestParseTopics(t *testing.T) {
tests := setupTopicsTests()

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
createObj := tt.args.createObj()
Expand All @@ -403,7 +401,6 @@ func TestParseTopicsIntoMap(t *testing.T) {
tests := setupTopicsTests()

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
outMap := make(map[string]interface{})
Expand Down
3 changes: 1 addition & 2 deletions accounts/abi/unpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ func TestMethodMultiReturn(t *testing.T) {
"Can not unpack into a slice with wrong types",
}}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
require := require.New(t)
err := abi.UnpackIntoInterface(tc.dest, "multi", data)
Expand Down Expand Up @@ -957,7 +956,7 @@ func TestOOMMaliciousInput(t *testing.T) {
}
encb, err := hex.DecodeString(test.enc)
if err != nil {
t.Fatalf("invalid hex: %s" + test.enc)
t.Fatalf("invalid hex: %s", test.enc)
}
_, err = abi.Methods["method"].Outputs.UnpackValues(encb)
if err == nil {
Expand Down
1 change: 0 additions & 1 deletion core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ func TestBlockChainOfflinePruningUngracefulShutdown(t *testing.T) {
return createBlockChain(db, pruningConfig, gspec, lastAcceptedHash)
}
for _, tt := range tests {
tt := tt
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
tt.testFunc(t, create)
Expand Down
1 change: 0 additions & 1 deletion core/predicate_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ func TestCheckPredicate(t *testing.T) {
expectedErr: ErrIntrinsicGas,
},
} {
test := test
t.Run(name, func(t *testing.T) {
require := require.New(t)
// Create the rules from TestChainConfig and update the predicates based on the test params
Expand Down
6 changes: 3 additions & 3 deletions core/rawdb/accessors_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ func TestBlockReceiptStorage(t *testing.T) {
// Insert the receipt slice into the database and check presence
WriteReceipts(db, hash, 0, receipts)
if rs := ReadReceipts(db, hash, 0, 0, params.TestChainConfig); len(rs) == 0 {
t.Fatalf("no receipts returned")
t.Fatal("no receipts returned")
} else {
if err := checkReceiptsRLP(rs, receipts); err != nil {
t.Fatalf(err.Error())
t.Fatal(err)
}
}
// Delete the body and ensure that the receipts are no longer returned (metadata can't be recomputed)
Expand All @@ -308,7 +308,7 @@ func TestBlockReceiptStorage(t *testing.T) {
}
// Ensure that receipts without metadata can be returned without the block body too
if err := checkReceiptsRLP(ReadRawReceipts(db, hash, 0), receipts); err != nil {
t.Fatalf(err.Error())
t.Fatal(err)
}
// Sanity check that body and header alone without the receipt is a full purge
WriteHeader(db, header)
Expand Down
2 changes: 0 additions & 2 deletions core/types/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,7 @@ func TestYParityJSONUnmarshalling(t *testing.T) {
DynamicFeeTxType,
BlobTxType,
} {
txType := txType
for _, test := range tests {
test := test
t.Run(fmt.Sprintf("txType=%d: %s", txType, test.name), func(t *testing.T) {
// Copy the base json
testJson := make(map[string]interface{})
Expand Down
1 change: 0 additions & 1 deletion eth/filters/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ func (api *FilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subsc
select {
case logs := <-matchedLogs:
for _, log := range logs {
log := log
notifier.Notify(rpcSub.ID, &log)
}
case <-rpcSub.Err(): // client send an unsubscribe request
Expand Down
2 changes: 0 additions & 2 deletions eth/tracers/internal/tracetest/calltrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) {
if !strings.HasSuffix(file.Name(), ".json") {
continue
}
file := file // capture range variable
t.Run(camel(strings.TrimSuffix(file.Name(), ".json")), func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -205,7 +204,6 @@ func BenchmarkTracers(b *testing.B) {
if !strings.HasSuffix(file.Name(), ".json") {
continue
}
file := file // capture range variable
b.Run(camel(strings.TrimSuffix(file.Name(), ".json")), func(b *testing.B) {
blob, err := os.ReadFile(filepath.Join("testdata", "call_tracer", file.Name()))
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion eth/tracers/internal/tracetest/flat_calltrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ func testFlatCallTracer(tracerName string, dirPath string, t *testing.T) {
if !strings.HasSuffix(file.Name(), ".json") {
continue
}
file := file // capture range variable
t.Run(camel(strings.TrimSuffix(file.Name(), ".json")), func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion eth/tracers/internal/tracetest/prestate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) {
if !strings.HasSuffix(file.Name(), ".json") {
continue
}
file := file // capture range variable
t.Run(camel(strings.TrimSuffix(file.Name(), ".json")), func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func formatLogs(logs []StructLog) []StructLogRes {
}
formatted[index].Stack = &stack
}
if trace.ReturnData != nil && len(trace.ReturnData) > 0 {
if len(trace.ReturnData) > 0 {
formatted[index].ReturnData = hexutil.Bytes(trace.ReturnData).String()
}
if trace.Memory != nil {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/ava-labs/coreth

go 1.22.8
go 1.23.6

require (
github.com/VictoriaMetrics/fastcache v1.12.1
github.com/ava-labs/avalanchego v1.12.3-0.20250213221544-df1bf8c8a6cf
github.com/ava-labs/avalanchego v1.12.3-0.20250216200402-d76684b684f1
github.com/cespare/cp v0.1.0
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233
github.com/davecgh/go-spew v1.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/avalanchego v1.12.3-0.20250213221544-df1bf8c8a6cf h1:4aq9V24PsH92vDSQTBx+uhm60BTeaNcXg/7FreQ8Q3M=
github.com/ava-labs/avalanchego v1.12.3-0.20250213221544-df1bf8c8a6cf/go.mod h1:PkpeGfEdsTccz87SDHidto21U5+BSBGZ+BNPW6Zplbc=
github.com/ava-labs/avalanchego v1.12.3-0.20250216200402-d76684b684f1 h1:bp+RMUpgUX2HL22FnArOMkhg9IaGjA7xHExAH3zy3Og=
github.com/ava-labs/avalanchego v1.12.3-0.20250216200402-d76684b684f1/go.mod h1:kjz2dtxgb9UiSzCDMon8AqFpsRPb9SGGW9F6tsKwufc=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down
16 changes: 8 additions & 8 deletions plugin/evm/atomic/export_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,16 @@ func (utx *UnsignedExportTx) Verify(
func (utx *UnsignedExportTx) GasUsed(fixedFee bool) (uint64, error) {
byteCost := calcBytesCost(len(utx.Bytes()))
numSigs := uint64(len(utx.Ins))
sigCost, err := math.Mul64(numSigs, secp256k1fx.CostPerSignature)
sigCost, err := math.Mul(numSigs, secp256k1fx.CostPerSignature)
if err != nil {
return 0, err
}
cost, err := math.Add64(byteCost, sigCost)
cost, err := math.Add(byteCost, sigCost)
if err != nil {
return 0, err
}
if fixedFee {
cost, err = math.Add64(cost, params.AtomicTxBaseCost)
cost, err = math.Add(cost, params.AtomicTxBaseCost)
if err != nil {
return 0, err
}
Expand All @@ -160,15 +160,15 @@ func (utx *UnsignedExportTx) Burned(assetID ids.ID) (uint64, error) {
)
for _, out := range utx.ExportedOutputs {
if out.AssetID() == assetID {
spent, err = math.Add64(spent, out.Output().Amount())
spent, err = math.Add(spent, out.Output().Amount())
if err != nil {
return 0, err
}
}
}
for _, in := range utx.Ins {
if in.AssetID == assetID {
input, err = math.Add64(input, in.Amount)
input, err = math.Add(input, in.Amount)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -346,7 +346,7 @@ func NewExportTx(
avaxIns, avaxSigners, err = GetSpendableAVAXWithFee(ctx, state, keys, avaxNeeded, cost, baseFee)
default:
var newAvaxNeeded uint64
newAvaxNeeded, err = math.Add64(avaxNeeded, params.AvalancheAtomicTxFee)
newAvaxNeeded, err = math.Add(avaxNeeded, params.AvalancheAtomicTxFee)
if err != nil {
return nil, errOverflowExport
}
Expand Down Expand Up @@ -486,7 +486,7 @@ func GetSpendableAVAXWithFee(
return nil, nil, err
}

newAmount, err := math.Add64(amount, initialFee)
newAmount, err := math.Add(amount, initialFee)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -527,7 +527,7 @@ func GetSpendableAVAXWithFee(
// Update the cost for the next iteration
cost = newCost

newAmount, err := math.Add64(amount, additionalFee)
newAmount, err := math.Add(amount, additionalFee)
if err != nil {
return nil, nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions plugin/evm/atomic/import_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ func (utx *UnsignedImportTx) GasUsed(fixedFee bool) (uint64, error) {
if err != nil {
return 0, err
}
cost, err = math.Add64(cost, inCost)
cost, err = math.Add(cost, inCost)
if err != nil {
return 0, err
}
}
if fixedFee {
cost, err = math.Add64(cost, params.AtomicTxBaseCost)
cost, err = math.Add(cost, params.AtomicTxBaseCost)
if err != nil {
return 0, err
}
Expand All @@ -167,15 +167,15 @@ func (utx *UnsignedImportTx) Burned(assetID ids.ID) (uint64, error) {
)
for _, out := range utx.Outs {
if out.AssetID == assetID {
spent, err = math.Add64(spent, out.Amount)
spent, err = math.Add(spent, out.Amount)
if err != nil {
return 0, err
}
}
}
for _, in := range utx.ImportedInputs {
if in.AssetID() == assetID {
input, err = math.Add64(input, in.Input().Amount())
input, err = math.Add(input, in.Input().Amount())
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -311,7 +311,7 @@ func NewImportTx(
continue
}
aid := utxo.AssetID()
importedAmount[aid], err = math.Add64(importedAmount[aid], input.Amount())
importedAmount[aid], err = math.Add(importedAmount[aid], input.Amount())
if err != nil {
return nil, err
}
Expand Down
Loading