Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lint): add linter in CI #533

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ jobs:
- checkout
- run: make build

lint:
executor: golang
steps:
- run: make lint

plugins:
executor: golang
steps:
Expand Down
186 changes: 186 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
1 change: 0 additions & 1 deletion cmd/connect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion cmd/connect/session/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func (c *Client) functionHelp(line string) {
helpKey = args[0]
}
switch helpKey {

case "help":
fmt.Println(`
Usage: \help command_name
Expand Down
1 change: 0 additions & 1 deletion cmd/connect/session/local_api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion cmd/connect/session/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func (c *Client) parseQueryArgs(args []string) (tbk *io.TimeBucketKey, start, en
start = &t
parsedTime = true
}

}
}

Expand Down
1 change: 0 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions contrib/ondiskagg/aggtrigger/aggtrigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions contrib/polygon/backfill/backfiller/backfiller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion contrib/polygon/polygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions frontend/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion frontend/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ func (s GRPCService) Query(ctx context.Context, reqs *proto.MultiQueryRequest) (
&proto.QueryResponse{
Result: ToProtoNumpyMultiDataSet(nmds),
})

}
}
return &response, nil
Expand Down
1 change: 0 additions & 1 deletion frontend/utilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestHandler(t *testing.T) {
},
}
for key, val := range TestValues {

switch key {
case "Success":
atomic.StoreUint32(&Queryable, uint32(1))
Expand Down