From 5fcf6aa1f39c8e9a9873da2cdb149f512779d4d6 Mon Sep 17 00:00:00 2001 From: Daito AKIMURA Date: Mon, 27 Dec 2021 09:09:01 +0900 Subject: [PATCH] fix(lint): add lint in CI --- .circleci/config.yml | 5 + .golangci.yml | 186 ++++++++++++++++++ Makefile | 9 +- cmd/connect/main.go | 1 - cmd/connect/session/help.go | 1 - cmd/connect/session/local_api_client.go | 1 - cmd/connect/session/show.go | 1 - cmd/main.go | 1 - contrib/ondiskagg/aggtrigger/aggtrigger.go | 3 - .../polygon/backfill/backfiller/backfiller.go | 2 - contrib/polygon/polygon.go | 1 - frontend/client/client.go | 2 - frontend/grpc.go | 1 - frontend/utilities_test.go | 1 - 14 files changed, 198 insertions(+), 17 deletions(-) create mode 100644 .golangci.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index ebc8fd109..6a2b7f473 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -20,6 +20,11 @@ jobs: - checkout - run: make build + lint: + executor: golang + steps: + - run: make lint + plugins: executor: golang steps: diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..bc24c19f7 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,186 @@ +# golangci-lint configuration file +# see: https://golangci-lint.run/usage/configuration/ + +run: + timeout: 5m + skip-dirs: + - ./docs/ + - ./data/ + - ./tests/ # most of the tests are written in python + # build-tags: + # - + +linters-settings: + depguard: + list-type: blacklist + include-go-root: false + packages: + - github.com/magiconair/properties/assert + - github.com/smartystreets/assertions/assert + packages-with-error-message: + - github.com/magiconair/properties/assert: "assertion is only allowed with stretchr/testify" + - github.com/smartystreets/assertions/assert: "assertion is only allowed with stretchr/testify" + dupl: + threshold: 100 + errorlint: + errorf: true + funlen: + lines: 80 + statements: 40 + gocognit: + min-complexity: 30 + goconst: + min-len: 3 + min-occurrences: 3 + gocritic: + disabled-checks: + - wrapperFunc + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + gocyclo: + min-complexity: 15 + godot: + check-all: false + gofumpt: + extra-rules: true + goimports: + local-prefixes: github.com/alpacahq/marketstore/v4 + gomnd: + settings: + mnd: + checks: + - argument + - case + - condition + - operation + - return + - assign + govet: + check-shadowing: true + enable-all: true + disable: + - fieldalignment + lll: + line-length: 120 + maligned: + suggest-new: true + misspell: + locale: US + nakedret: + max-func-lines: 0 + nestif: + min-complexity: 4 + nolintlint: + allow-unused: false + require-explanation: true + require-specific: true + prealloc: + for-loops: true + range-loops: true + +# All linter links can be found here: https://golangci-lint.run/usage/linters/ +linters: + disable-all: true + enable: + - deadcode + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - structcheck + - typecheck + - unused + - varcheck + - asciicheck + - bodyclose + - cyclop + - depguard + - dogsled + - dupl + - durationcheck + - errorlint + - exhaustive + - exhaustivestruct + - exportloopref + - forbidigo + - forcetypeassert + - funlen + - gci + - gochecknoinits + - gocognit + - goconst + - gocritic + - gocyclo + - godot + - godox + - gofumpt + #- goheader # This repository currently doesn't have license headers. + #- golint # replaced by revive. + - gomnd + - gomoddirectives + - gomodguard + - goprintffuncname + - gosec + - ifshort + - importas + - lll + - makezero + - misspell + - nakedret + - nestif + - noctx + - nolintlint + - paralleltest + - prealloc + - predeclared + - promlinter + - revive + - rowserrcheck + - sqlclosecheck + - stylecheck + - tagliatelle + - testpackage + - thelper + - tparallel + - unconvert + - unparam + - wastedassign + - whitespace + - wrapcheck + +issues: + max-issues-per-linter: 0 + max-same-issues: 0 + exclude-rules: + # Exclude lll issues for long lines with go:generate + - source: "^//go:generate " + linters: + - lll + + # Exclude lll for URLs, as they can sometimes be very long + - source: "http(s)?://" + linters: + - lll + + # Exclude test type File from LLL, as compacting file contents on 1 line can be better for test readability + - source: "File\\(\"" + path: _test\.go + linters: + - lll + + # Exclude godox check for TODOs, FIXMEs, and BUGs + - text: "Line contains TODO/BUG/FIXME:" + linters: + - godox + + # Exclude some linters from running on test files + - path: _test\.go + linters: + - dupl + - funlen + - gomnd diff --git a/Makefile b/Makefile index 426f54022..dc7116d0e 100644 --- a/Makefile +++ b/Makefile @@ -45,8 +45,13 @@ plugins: $(MAKE) -C contrib/xignitefeeder $(MAKE) -C contrib/alpacabkfeeder -fmt: - GOFLAGS=$(GOFLAGS) go fmt ./... +.PHONY: lint +lint: ## run linter + @golangci-lint version + @golangci-lint run ./... + +lint-fix: ## try to fix lint error(s) + @golangci-lint run --fix ./... unit-test: # marketstore/contrib/stream/shelf/shelf_test.go fails if "-race" enabled... diff --git a/cmd/connect/main.go b/cmd/connect/main.go index 23e45d763..d8768cd27 100644 --- a/cmd/connect/main.go +++ b/cmd/connect/main.go @@ -73,7 +73,6 @@ func validateArgs(cmd *cobra.Command, args []string) error { // executeConnect implements the connect command. func executeConnect(cmd *cobra.Command, args []string) error { - var ( c *session.Client conn session.APIClient diff --git a/cmd/connect/session/help.go b/cmd/connect/session/help.go index b1d9abf2d..fa4d0148d 100644 --- a/cmd/connect/session/help.go +++ b/cmd/connect/session/help.go @@ -16,7 +16,6 @@ func (c *Client) functionHelp(line string) { helpKey = args[0] } switch helpKey { - case "help": fmt.Println(` Usage: \help command_name diff --git a/cmd/connect/session/local_api_client.go b/cmd/connect/session/local_api_client.go index ef35fe10c..8704af010 100644 --- a/cmd/connect/session/local_api_client.go +++ b/cmd/connect/session/local_api_client.go @@ -68,7 +68,6 @@ func (lc *LocalAPIClient) Write(reqs *frontend.MultiWriteRequest, responses *fro func (lc *LocalAPIClient) Show(tbk *io.TimeBucketKey, start, end *time.Time, ) (csm io.ColumnSeriesMap, err error) { - if start == nil && end == nil { fmt.Println("No suitable date range supplied...") return diff --git a/cmd/connect/session/show.go b/cmd/connect/session/show.go index 9bdc7b869..15c9bd315 100644 --- a/cmd/connect/session/show.go +++ b/cmd/connect/session/show.go @@ -88,7 +88,6 @@ func (c *Client) parseQueryArgs(args []string) (tbk *io.TimeBucketKey, start, en start = &t parsedTime = true } - } } diff --git a/cmd/main.go b/cmd/main.go index 727b942e4..c8560944f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -18,7 +18,6 @@ var flagPrintVersion bool // Execute builds the command tree and executes commands. func Execute() error { - // c is the root command. c := &cobra.Command{ Use: "marketstore", diff --git a/contrib/ondiskagg/aggtrigger/aggtrigger.go b/contrib/ondiskagg/aggtrigger/aggtrigger.go index d8e9dac4b..138a78a4b 100644 --- a/contrib/ondiskagg/aggtrigger/aggtrigger.go +++ b/contrib/ondiskagg/aggtrigger/aggtrigger.go @@ -171,7 +171,6 @@ func (s *OnDiskAggTrigger) write( cs *io.ColumnSeries, tail, head time.Time, elements []string) { - for _, dest := range s.destinations { symbol := elements[0] attributeGroup := elements[2] @@ -205,7 +204,6 @@ func (s *OnDiskAggTrigger) writeAggregates( dest utils.Timeframe, head, tail time.Time, symbol string) error { - csm := io.NewColumnSeriesMap() window := utils.CandleDurationFromString(dest.String) @@ -360,7 +358,6 @@ func (s *OnDiskAggTrigger) query( tbk *io.TimeBucketKey, window *utils.CandleDuration, head, tail time.Time) (*io.ColumnSeriesMap, error) { - cDir := executor.ThisInstance.CatalogDir start := window.Truncate(head) diff --git a/contrib/polygon/backfill/backfiller/backfiller.go b/contrib/polygon/backfill/backfiller/backfiller.go index 599aac302..04b5346e0 100644 --- a/contrib/polygon/backfill/backfiller/backfiller.go +++ b/contrib/polygon/backfill/backfiller/backfiller.go @@ -352,7 +352,6 @@ func getBars(start time.Time, end time.Time, period time.Duration, symbol string func getQuotes(start time.Time, end time.Time, period time.Duration, symbol string, writerWP *worker.WorkerPool) { log.Info("[polygon] backfilling quotes for %v", symbol) for end.After(start) { - if start.Add(period).After(end) { period = end.Sub(start) } @@ -369,7 +368,6 @@ func getQuotes(start time.Time, end time.Time, period time.Duration, symbol stri func getTrades(start time.Time, end time.Time, period time.Duration, symbol string, writerWP *worker.WorkerPool) { log.Info("[polygon] backfilling trades for %v", symbol) for end.After(start) { - if start.Add(period).After(end) { period = end.Sub(start) } diff --git a/contrib/polygon/polygon.go b/contrib/polygon/polygon.go index 62219a434..953e75d38 100644 --- a/contrib/polygon/polygon.go +++ b/contrib/polygon/polygon.go @@ -129,7 +129,6 @@ func (pf *PolygonFetcher) backfillBars(symbol string, end time.Time, writerWP *w } from = time.Unix(epoch[len(epoch)-1], 0) - } else { for _, layout := range []string{ "2006-01-02 03:04:05", diff --git a/frontend/client/client.go b/frontend/client/client.go index 6ed7c8c0d..3484f1abc 100644 --- a/frontend/client/client.go +++ b/frontend/client/client.go @@ -141,7 +141,6 @@ func (cl *Client) Subscribe( handler func(pl stream.Payload) error, cancel <-chan struct{}, streams ...string) (done <-chan struct{}, err error) { - u, _ := url.Parse(cl.BaseURL + "/ws") u.Scheme = "ws" @@ -185,7 +184,6 @@ func streamConn( c *websocket.Conn, handler func(pl stream.Payload) error, cancel <-chan struct{}) <-chan struct{} { - done := make(chan struct{}, 1) go func() { diff --git a/frontend/grpc.go b/frontend/grpc.go index 2295e4177..860f1f073 100644 --- a/frontend/grpc.go +++ b/frontend/grpc.go @@ -187,7 +187,6 @@ func (s GRPCService) Query(ctx context.Context, reqs *proto.MultiQueryRequest) ( &proto.QueryResponse{ Result: ToProtoNumpyMultiDataSet(nmds), }) - } } return &response, nil diff --git a/frontend/utilities_test.go b/frontend/utilities_test.go index 81812dff0..b786fca6f 100644 --- a/frontend/utilities_test.go +++ b/frontend/utilities_test.go @@ -33,7 +33,6 @@ func TestHandler(t *testing.T) { }, } for key, val := range TestValues { - switch key { case "Success": atomic.StoreUint32(&Queryable, uint32(1))