Skip to content

Commit

Permalink
Moved golangci linter config to the separate file (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
begmaroman committed Sep 27, 2022
1 parent 6b93e54 commit e25825c
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 53 deletions.
27 changes: 0 additions & 27 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions command/version/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package version
import (
"bytes"
"fmt"

"github.com/0xPolygon/polygon-edge/command/helper"
)

Expand Down
2 changes: 1 addition & 1 deletion helper/enode/enode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions helper/keccak/keccak.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -41,15 +40,13 @@ 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
}

// Sum implements the hash interface
func (k *Keccak) Sum(dst []byte) []byte {
//nolint
k.hash.Read(k.tmp)
dst = append(dst, k.tmp[:]...)

Expand Down
1 change: 0 additions & 1 deletion helper/keccak/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions jsonrpc/eth_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ 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"
"github.com/0xPolygon/polygon-edge/helper/progress"
"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 {
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion jsonrpc/txpool_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion state/immutable-trie/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ----------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions state/runtime/precompiled/base_test.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 0 additions & 1 deletion state/runtime/precompiled/bn256_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:lll
package precompiled

import "testing"
Expand Down
1 change: 0 additions & 1 deletion state/runtime/precompiled/modexp_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:lll
package precompiled

import (
Expand Down
2 changes: 1 addition & 1 deletion state/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 6 additions & 4 deletions syncer/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion types/buildroot/buildroot_fast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 0 additions & 1 deletion types/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func TestHeader_JSON(t *testing.T) {
t.Parallel()

var (
//nolint:lll
headerJSON = `{
"parentHash": "0x0100000000000000000000000000000000000000000000000000000000000000",
"sha3Uncles" : "0x0200000000000000000000000000000000000000000000000000000000000000",
Expand Down
2 changes: 0 additions & 2 deletions types/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit e25825c

Please sign in to comment.