From e25825cb96ff35db308af06deee69acd5caea9b7 Mon Sep 17 00:00:00 2001 From: Roman Behma <13855864+begmaroman@users.noreply.github.com> Date: Tue, 27 Sep 2022 10:06:38 +0100 Subject: [PATCH] Moved golangci linter config to the separate file (#764) --- .github/workflows/main.yml | 27 ----------- .golangci.yml | 60 ++++++++++++++++++++++++ Makefile | 4 +- command/version/result.go | 1 + helper/enode/enode_test.go | 2 +- helper/keccak/keccak.go | 3 -- helper/keccak/pool.go | 1 - jsonrpc/eth_endpoint.go | 8 ++-- jsonrpc/txpool_endpoint_test.go | 1 - state/immutable-trie/encoding_test.go | 1 - state/runtime/precompiled/base_test.go | 4 +- state/runtime/precompiled/bn256_test.go | 1 - state/runtime/precompiled/modexp_test.go | 1 - state/txn.go | 2 +- syncer/client_test.go | 10 ++-- types/buildroot/buildroot_fast.go | 2 +- types/header_test.go | 1 - types/receipt.go | 2 - 18 files changed, 78 insertions(+), 53 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a1f93e9bd2..b34eb43aad 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,33 +19,6 @@ jobs: - name: Lint uses: golangci/golangci-lint-action@v3 - with: - version: v1.49.0 - args: - --timeout=3m - -E whitespace - -E wsl - -E wastedassign - -E unconvert - -E tparallel - -E thelper - -E stylecheck - -E prealloc - -E predeclared - -E nolintlint - -E nlreturn - -E misspell - -E makezero - -E lll - -E importas - -E gosec - -E gofmt - -E goconst - -E forcetypeassert - -E dogsled - -E dupl - -E errname - -E errorlint test: runs-on: ubuntu-latest diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000000..5fe6ce8882 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,60 @@ +# This file configures github.com/golangci/golangci-lint. + +run: + timeout: 3m + tests: true + # default is true. Enables skipping of directories: + # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ + skip-dirs-use-default: true + +service: + golangci-lint-version: 1.49.0 + +linters: + disable-all: true + enable: + - whitespace # Tool for detection of leading and trailing whitespace + - wsl # Forces you to use empty lines + - wastedassign # Finds wasted assignment statements + - unconvert # Unnecessary type conversions + - tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes + - thelper # Detects golang test helpers without t.Helper() call and checks the consistency of test helpers + - stylecheck # Stylecheck is a replacement for golint + - prealloc # Finds slice declarations that could potentially be pre-allocated + - predeclared # Finds code that shadows one of Go's predeclared identifiers + - nolintlint # Ill-formed or insufficient nolint directives + - nlreturn # Checks for a new line before return and branch statements to increase code clarity + - misspell # Misspelled English words in comments + - makezero # Finds slice declarations with non-zero initial length + - lll # Long lines + - importas # Enforces consistent import aliases + - gosec # Security problems + - gofmt # Whether the code was gofmt-ed + - goimports # Unused imports + - goconst # Repeated strings that could be replaced by a constant + - forcetypeassert # Finds forced type assertions + - dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f()) + - dupl # Code clone detection + - errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error + - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13 + +linters-settings: + gofmt: + simplify: true + goconst: + min-len: 3 + min-occurrences: 3 + +issues: + new-from-rev: origin/develop # report only new issues with reference to develop branch + exclude-rules: + - path: _test\.go + linters: + - gosec + - unparam + - lll + include: + - EXC0012 # Exported (.+) should have comment( \(or a comment on this block\))? or be unexported + - EXC0013 # Package comment should be of the form "(.+)... + - EXC0014 # Comment on exported (.+) should be of the form "(.+)..." + - EXC0015 # Should have a package comment diff --git a/Makefile b/Makefile index 561ede6201..1e8d6a9c9d 100644 --- a/Makefile +++ b/Makefile @@ -31,9 +31,7 @@ build: .PHONY: lint lint: - golangci-lint run -E whitespace -E wsl -E wastedassign -E unconvert -E tparallel -E thelper -E stylecheck -E prealloc \ - -E predeclared -E nlreturn -E misspell -E makezero -E lll -E importas -E gosec -E gofmt -E goconst \ - -E forcetypeassert -E dogsled -E dupl -E errname -E errorlint -E nolintlint --timeout 2m + golangci-lint run --config .golangci.yml .PHONY: generate-bsd-licenses generate-bsd-licenses: diff --git a/command/version/result.go b/command/version/result.go index 146dbee32c..b178aabe40 100644 --- a/command/version/result.go +++ b/command/version/result.go @@ -3,6 +3,7 @@ package version import ( "bytes" "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" ) diff --git a/helper/enode/enode_test.go b/helper/enode/enode_test.go index 4c6cfe7937..258aa04b13 100644 --- a/helper/enode/enode_test.go +++ b/helper/enode/enode_test.go @@ -6,7 +6,7 @@ import ( ) func TestParseEnode(t *testing.T) { - id1 := "1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439" //nolint:lll + id1 := "1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439" enode := func(prefix, id, ip, port string) string { return fmt.Sprintf("%s://%s@%s:%s", prefix, id, ip, port) diff --git a/helper/keccak/keccak.go b/helper/keccak/keccak.go index 1a8471203b..cafc7277e1 100644 --- a/helper/keccak/keccak.go +++ b/helper/keccak/keccak.go @@ -22,7 +22,6 @@ type Keccak struct { // WriteRlp writes an RLP value func (k *Keccak) WriteRlp(dst []byte, v *fastrlp.Value) []byte { k.buf = v.MarshalTo(k.buf[:0]) - //nolint k.Write(k.buf) return k.Sum(dst) @@ -41,7 +40,6 @@ func (k *Keccak) Reset() { // Read hashes the content and returns the intermediate buffer. func (k *Keccak) Read() []byte { - //nolint k.hash.Read(k.tmp) return k.tmp @@ -49,7 +47,6 @@ func (k *Keccak) Read() []byte { // Sum implements the hash interface func (k *Keccak) Sum(dst []byte) []byte { - //nolint k.hash.Read(k.tmp) dst = append(dst, k.tmp[:]...) diff --git a/helper/keccak/pool.go b/helper/keccak/pool.go index ff20c31354..d95c5bdd9a 100644 --- a/helper/keccak/pool.go +++ b/helper/keccak/pool.go @@ -38,7 +38,6 @@ func (p *Pool) Put(k *Keccak) { // Keccak256 hashes a src with keccak-256 func Keccak256(dst, src []byte) []byte { h := DefaultKeccakPool.Get() - //nolint h.Write(src) dst = h.Sum(dst) DefaultKeccakPool.Put(h) diff --git a/jsonrpc/eth_endpoint.go b/jsonrpc/eth_endpoint.go index edc4c63628..3f1067b6d9 100644 --- a/jsonrpc/eth_endpoint.go +++ b/jsonrpc/eth_endpoint.go @@ -5,6 +5,9 @@ import ( "fmt" "math/big" + "github.com/hashicorp/go-hclog" + "github.com/umbracle/fastrlp" + "github.com/0xPolygon/polygon-edge/chain" "github.com/0xPolygon/polygon-edge/helper/common" "github.com/0xPolygon/polygon-edge/helper/hex" @@ -12,8 +15,6 @@ import ( "github.com/0xPolygon/polygon-edge/state" "github.com/0xPolygon/polygon-edge/state/runtime" "github.com/0xPolygon/polygon-edge/types" - "github.com/hashicorp/go-hclog" - "github.com/umbracle/fastrlp" ) type ethTxPoolStore interface { @@ -84,7 +85,8 @@ var ( ) // ChainId returns the chain id of the client -//nolint:stylecheck, gofmt +// +//nolint:stylecheck func (e *Eth) ChainId() (interface{}, error) { return argUintPtr(e.chainID), nil } diff --git a/jsonrpc/txpool_endpoint_test.go b/jsonrpc/txpool_endpoint_test.go index 6db457d07f..f571411a77 100644 --- a/jsonrpc/txpool_endpoint_test.go +++ b/jsonrpc/txpool_endpoint_test.go @@ -243,7 +243,6 @@ func newMockTxPoolStore() *mockTxPoolStore { } } -//nolint:lll func (s *mockTxPoolStore) GetTxs(inclQueued bool) (map[types.Address][]*types.Transaction, map[types.Address][]*types.Transaction) { s.includeQueued = inclQueued diff --git a/state/immutable-trie/encoding_test.go b/state/immutable-trie/encoding_test.go index e33c242926..6741335067 100644 --- a/state/immutable-trie/encoding_test.go +++ b/state/immutable-trie/encoding_test.go @@ -122,7 +122,6 @@ func TestEncoding_KeyBytesToHexNibbles(t *testing.T) { func TestEncoding_HexCompact(t *testing.T) { // As per the official spec: - //nolint:lll // https://eth.wiki/en/fundamentals/patricia-tree#specification-compact-encoding-of-hex-sequence-with-optional-terminator // hex char bits | node type partial path length // ---------------------------------------------------------- diff --git a/state/runtime/precompiled/base_test.go b/state/runtime/precompiled/base_test.go index 1901c53569..5bc5a3b93c 100644 --- a/state/runtime/precompiled/base_test.go +++ b/state/runtime/precompiled/base_test.go @@ -1,11 +1,11 @@ -//nolint: lll,gofmt package precompiled import ( "testing" - "github.com/0xPolygon/polygon-edge/helper/hex" "github.com/stretchr/testify/assert" + + "github.com/0xPolygon/polygon-edge/helper/hex" ) type precompiledTest struct { diff --git a/state/runtime/precompiled/bn256_test.go b/state/runtime/precompiled/bn256_test.go index 660b10acd9..6621e28535 100644 --- a/state/runtime/precompiled/bn256_test.go +++ b/state/runtime/precompiled/bn256_test.go @@ -1,4 +1,3 @@ -//nolint:lll package precompiled import "testing" diff --git a/state/runtime/precompiled/modexp_test.go b/state/runtime/precompiled/modexp_test.go index d7978837b3..0199e9208f 100644 --- a/state/runtime/precompiled/modexp_test.go +++ b/state/runtime/precompiled/modexp_test.go @@ -1,4 +1,3 @@ -//nolint:lll package precompiled import ( diff --git a/state/txn.go b/state/txn.go index 59108338da..fd131e2033 100644 --- a/state/txn.go +++ b/state/txn.go @@ -54,7 +54,7 @@ func newTxn(state State, snapshot Snapshot) *Txn { func (txn *Txn) hashit(src []byte) []byte { txn.hash.Reset() - txn.hash.Write(src) //nolint + txn.hash.Write(src) // hashit is used to make queries so we do not need to // make copies of the result return txn.hash.Read() diff --git a/syncer/client_test.go b/syncer/client_test.go index 4963ec7946..d28cb797af 100644 --- a/syncer/client_test.go +++ b/syncer/client_test.go @@ -6,15 +6,16 @@ import ( "testing" "time" + "github.com/hashicorp/go-hclog" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/stretchr/testify/assert" + "github.com/0xPolygon/polygon-edge/blockchain" "github.com/0xPolygon/polygon-edge/network" "github.com/0xPolygon/polygon-edge/network/event" "github.com/0xPolygon/polygon-edge/network/grpc" "github.com/0xPolygon/polygon-edge/syncer/proto" "github.com/0xPolygon/polygon-edge/types" - "github.com/hashicorp/go-hclog" - "github.com/libp2p/go-libp2p/core/peer" - "github.com/stretchr/testify/assert" ) var ( @@ -371,7 +372,8 @@ func TestPeerConnectionUpdateEventCh(t *testing.T) { // Make sure the peer shouldn't emit status if the shouldEmitBlocks flag is set. // The subtests cannot contain t.Parallel() due to how // the test is organized -//nolint:tparallel, gofmt +// +//nolint:tparallel func Test_shouldEmitBlocks(t *testing.T) { t.Parallel() diff --git a/types/buildroot/buildroot_fast.go b/types/buildroot/buildroot_fast.go index 2aa866c3d4..c1a611932d 100644 --- a/types/buildroot/buildroot_fast.go +++ b/types/buildroot/buildroot_fast.go @@ -144,7 +144,7 @@ func (f *FastHasher) Hash(num int, cb func(i int) []byte) ([]byte, bool) { } func (f *FastHasher) hash(dst, b []byte) []byte { - f.k.Write(b) //nolint + f.k.Write(b) dst = f.k.Sum(dst) f.k.Reset() diff --git a/types/header_test.go b/types/header_test.go index 79df510f4d..1f916d0361 100644 --- a/types/header_test.go +++ b/types/header_test.go @@ -14,7 +14,6 @@ func TestHeader_JSON(t *testing.T) { t.Parallel() var ( - //nolint:lll headerJSON = `{ "parentHash": "0x0100000000000000000000000000000000000000000000000000000000000000", "sha3Uncles" : "0x0200000000000000000000000000000000000000000000000000000000000000", diff --git a/types/receipt.go b/types/receipt.go index 87ffed4b5d..b0f1018329 100644 --- a/types/receipt.go +++ b/types/receipt.go @@ -111,7 +111,6 @@ func CreateBloom(receipts []*Receipt) (b Bloom) { func (b *Bloom) setEncode(hasher *keccak.Keccak, h []byte) { hasher.Reset() - //nolint hasher.Write(h[:]) buf := hasher.Read() @@ -153,7 +152,6 @@ func (b *Bloom) IsLogInBloom(log *Log) bool { // isByteArrPresent checks if the byte array is possibly present in the Bloom filter func (b *Bloom) isByteArrPresent(hasher *keccak.Keccak, data []byte) bool { hasher.Reset() - //nolint hasher.Write(data[:]) buf := hasher.Read()