diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..a12bd729 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,84 @@ +run: + timeout: 5m + +linters: + enable: + - bidichk + - bodyclose + # - depguard as of v1.54.2, the default config throws errors on our repo + - dogsled + - dupl + - errcheck + - errorlint + # - funlen + # - gochecknoglobals + # - gochecknoinits + - exportloopref + - gocheckcompilerdirectives + - goconst + - gocritic + # - gocyclo + # - godox + - gofmt + - gofumpt + - goimports + # - golint - deprecated since v1.41. revive will be used instead + - revive + - gosec + - gosimple + - govet + - ineffassign + # - interfacer + - lll + - loggercheck + - misspell + # - maligned + - nakedret + - nilerr + - nilnil + - nolintlint + - prealloc + - protogetter + # - scopelint - deprecated since v1.39. exportloopref will be used instead + - exportloopref + - staticcheck + - stylecheck + - typecheck + - unconvert + # - unparam + - unused + # - whitespace + # - wsl + # - gocognit + - wastedassign + - whitespace + - nolintlint + - asciicheck + - dupword + +issues: + exclude-rules: + - path: _test\.go + linters: + - gosec + - revive + - linters: + - lll + source: "https://" + max-same-issues: 50 + +linters-settings: + dogsled: + max-blank-identifiers: 3 + golint: + min-confidence: 0 + maligned: + suggest-new: true + misspell: + locale: US + goimports: + local-prefixes: github.com/celestiaorg + dupl: + threshold: 200 + gofumpt: + extra-rules: true diff --git a/Makefile b/Makefile index cce9d629..892c1a1f 100644 --- a/Makefile +++ b/Makefile @@ -16,8 +16,9 @@ deps: ## fmt: Formats only *.go (excluding *.pb.go *pb_test.go). Runs `gofmt & goimports` internally. fmt: sort-imports @find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs gofmt -w -s - @find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs goimports -w -local github.com/celestiaorg + @find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs goimports -w -local github.com/celestiaorg @go mod tidy + @gofumpt -w -extra . @cfmt -w -m=100 ./... @markdownlint --fix --quiet --config .markdownlint.yaml . .PHONY: sort-imports diff --git a/header.go b/header.go index 4f3eb53a..02e391e4 100644 --- a/header.go +++ b/header.go @@ -12,7 +12,7 @@ type Header[H any] interface { // New creates new instance of a header. // It exists to overcome limitation of Go's type system. // See: - //https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#pointer-method-example + // https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#pointer-method-example New() H // IsZero reports whether Header is a zero value of it's concrete type. IsZero() bool diff --git a/p2p/server.go b/p2p/server.go index 30a91062..5e0194ad 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -19,9 +19,7 @@ import ( p2p_pb "github.com/celestiaorg/go-header/p2p/pb" ) -var ( - tracerServ = otel.Tracer("header/server") -) +var tracerServ = otel.Tracer("header/server") // ExchangeServer represents the server-side component for // responding to inbound header-related requests. diff --git a/p2p/session.go b/p2p/session.go index 4fa92c07..96c303bf 100644 --- a/p2p/session.go +++ b/p2p/session.go @@ -18,9 +18,7 @@ import ( p2p_pb "github.com/celestiaorg/go-header/p2p/pb" ) -var ( - tracerSession = otel.Tracer("header/p2p-session") -) +var tracerSession = otel.Tracer("header/p2p-session") // errEmptyResponse means that server side closes the connection without sending at least 1 // response. diff --git a/store/keys.go b/store/keys.go index c42b4c80..7e92c467 100644 --- a/store/keys.go +++ b/store/keys.go @@ -8,9 +8,7 @@ import ( "github.com/celestiaorg/go-header" ) -var ( - headKey = datastore.NewKey("head") -) +var headKey = datastore.NewKey("head") func heightKey(h uint64) datastore.Key { return datastore.NewKey(strconv.Itoa(int(h))) diff --git a/sync/sync_head_test.go b/sync/sync_head_test.go index b952b232..cc60e481 100644 --- a/sync/sync_head_test.go +++ b/sync/sync_head_test.go @@ -45,7 +45,6 @@ func TestSyncer_incomingNetworkHeadRaces(t *testing.T) { wg.Wait() assert.EqualValues(t, 1, hits.Load()) - } // TestSyncer_HeadWithTrustedHead tests whether the syncer @@ -122,12 +121,12 @@ func (t *wrappedGetter) Head(ctx context.Context, options ...header.HeadOption[* } func (t *wrappedGetter) Get(ctx context.Context, hash header.Hash) (*headertest.DummyHeader, error) { - //TODO implement me + // TODO implement me panic("implement me") } func (t *wrappedGetter) GetByHeight(ctx context.Context, u uint64) (*headertest.DummyHeader, error) { - //TODO implement me + // TODO implement me panic("implement me") } @@ -136,6 +135,6 @@ func (t *wrappedGetter) GetRangeByHeight( from *headertest.DummyHeader, to uint64, ) ([]*headertest.DummyHeader, error) { - //TODO implement me + // TODO implement me panic("implement me") }