From ffe810e55a9ba066863e7d953c863d6c12ebd76f Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Fri, 12 Apr 2024 18:52:17 +0530 Subject: [PATCH] Update lintci and fix lints (#1217) --- .golangci.yml | 6 +++--- Makefile | 2 +- core/txpool/legacypool/legacypool_test.go | 7 ++++--- rlp/unsafe.go | 8 +------- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 72955396a8..924e084431 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,8 +6,6 @@ run: # default is true. Enables skipping of directories: # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ skip-dirs-use-default: true - skip-files: - - core/genesis_alloc.go linters: disable-all: true @@ -44,6 +42,8 @@ linters-settings: min-occurrences: 6 # minimum number of occurrences issues: + exclude-files: + - core/genesis_alloc.go exclude-rules: - path: crypto/bn256/cloudflare/optate.go linters: @@ -64,4 +64,4 @@ issues: - 'SA1029: should not use built-in type string as key for value' - 'SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details' - 'SA1019: grpc.WithInsecure is deprecated: use WithTransportCredentials and insecure.NewCredentials() instead. Will be supported throughout 1.x' - - "SA1019: rand.Read has been deprecated since Go 1.20 because it shouldn't be used: For almost all use cases, crypto/rand.Read is more appropriate" + - "SA1019: rand.Read has been deprecated since Go 1.20 because it shouldn't be used: For almost all use cases, crypto/rand.Read is more appropriate" \ No newline at end of file diff --git a/Makefile b/Makefile index cdd0822c15..f074cddc32 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,7 @@ lint: lintci-deps: rm -f ./build/bin/golangci-lint - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v1.53.3 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v1.57.2 goimports: goimports -local "$(PACKAGE)" -w . diff --git a/core/txpool/legacypool/legacypool_test.go b/core/txpool/legacypool/legacypool_test.go index ea191b42ca..1c2f706cab 100644 --- a/core/txpool/legacypool/legacypool_test.go +++ b/core/txpool/legacypool/legacypool_test.go @@ -18,6 +18,7 @@ package legacypool import ( "crypto/ecdsa" + crand "crypto/rand" "errors" "fmt" "io" @@ -30,7 +31,7 @@ import ( "time" "github.com/holiman/uint256" - "github.com/maticnetwork/crand" + crand2 "github.com/maticnetwork/crand" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" @@ -115,7 +116,7 @@ func pricedTransaction(nonce uint64, gaslimit uint64, gasprice *big.Int, key *ec func pricedDataTransaction(nonce uint64, gaslimit uint64, gasprice *big.Int, key *ecdsa.PrivateKey, bytes uint64) *types.Transaction { data := make([]byte, bytes) - rand.Read(data) + crand.Read(data) tx, _ := types.SignTx(types.NewTransaction(nonce, common.Address{}, big.NewInt(0), gaslimit, gasprice, data), types.HomesteadSigner{}, key) @@ -3801,7 +3802,7 @@ func BenchmarkBigs(b *testing.B) { var over bool for i := 0; i < len(ints); i++ { - ints[i] = crand.BigInt(max) + ints[i] = crand2.BigInt(max) intUs[i], over = uint256.FromBig(ints[i]) if over { diff --git a/rlp/unsafe.go b/rlp/unsafe.go index d5b0d29a09..10868caaf2 100644 --- a/rlp/unsafe.go +++ b/rlp/unsafe.go @@ -26,11 +26,5 @@ import ( // byteArrayBytes returns a slice of the byte array v. func byteArrayBytes(v reflect.Value, length int) []byte { - var s []byte - hdr := (*reflect.SliceHeader)(unsafe.Pointer(&s)) - hdr.Data = v.UnsafeAddr() - hdr.Cap = length - hdr.Len = length - - return s + return unsafe.Slice((*byte)(unsafe.Pointer(v.UnsafeAddr())), length) }