Skip to content

Commit

Permalink
golangci-lint/CI: Bump versions and introduce new linters (thrasher-c…
Browse files Browse the repository at this point in the history
…orp#798)

* golangci-lint/CI: Bump versions

Fix remaining linter issues

* Specifically set AppVeyor version

* Fix the infamous typos 👀

* Add go env cmd to AppVeyor

* Add go version cmd to AppVeyor

* Specify AppVeyor image, adjust linters

* Update go get to go install due to deprecation

* Bump golangci-lint timeout time for AppVeyor

* Change NW contract to NQ

* Address nitters

* GetRandomPair -> Pair{}

* Address nits

* Address time nitterinos plus additional tweaks

* More time inception upgrades!

* Bending time and space
  • Loading branch information
thrasher- authored Oct 14, 2021
1 parent 0a91af0 commit f0d45aa
Show file tree
Hide file tree
Showing 194 changed files with 1,507 additions and 1,234 deletions.
10 changes: 7 additions & 3 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
build: off

image: Visual Studio 2019

clone_folder: c:\gopath\src\github.com\thrasher-corp\gocryptotrader

cache:
Expand All @@ -26,7 +28,7 @@ environment:
PSQL_SSLMODE: disable
PSQL_SKIPSQLCMD: true
PSQL_TESTDBNAME: gct_dev_ci
stack: go 1.16.x
stack: go 1.17.x

services:
- postgresql96
Expand All @@ -45,11 +47,13 @@ build_script:

before_test:
- cd c:\gopath\src\github.com\thrasher-corp\gocryptotrader
- go get
- go env
- go version
- go install

test_script:
# test back-end
- go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.31.0
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.42.1
- '%GOPATH%\bin\golangci-lint.exe run --verbose'
- ps: >-
if($env:APPVEYOR_SCHEDULED_BUILD -eq 'true') {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.31
version: v1.42.1
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
on: [push, pull_request]
name: CI
env:
GO_VERSION: 1.16.x
GO_VERSION: 1.17.x
jobs:
backend-psql:
name: GoCryptoTrader back-end with PSQL
Expand Down
35 changes: 28 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
run:
timeout: 2m30s
timeout: 3m
issues-exit-code: 1
tests: true
skip-dirs:
Expand All @@ -25,11 +25,18 @@ linters:
# disabled by default linters
- asciicheck
- bodyclose
# - cyclop
- depguard
- dogsled
# - dupl
- durationcheck
- errname
# - errorlint
# - exhaustive
# - exhaustivestruct
- exportloopref
# - forbidigo
- forcetypeassert
# - funlen
- gci
# - gochecknoglobals
Expand All @@ -43,31 +50,45 @@ linters:
# - goerr113
- gofmt
# - gofumpt
- goheader
# - goheader
- goimports
- golint
# - golint // deprecated since 1.41.0, replaced by revive
# - gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
# - interfacer
# - lll
- ifshort
# - importas
# - interfacer // deprecated by its owner
# - lll
- makezero
# - maligned
- misspell
- nakedret
# - nestif
- nilerr
# - nlreturn
- noctx
- nolintlint
# - paralleltest
# - prealloc
- predeclared
# - promlinter
- revive
- rowserrcheck
- scopelint
- sqlclosecheck
# - scopelint // deprecated since v1.39.0, replaced by exportloopref
# - sqlclosecheck
- stylecheck
# - tagliatelle
# - testpackage
- thelper
- tparallel
- unconvert
- unparam
- wastedassign
- whitespace
# - wrapcheck
# - wsl

linters-settings:
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ matrix:
dist: xenial
name: 'GoCryptoTrader [back-end] [linux] [64-bit]'
go:
- 1.15.x
- 1.17.x
env:
- GO111MODULE=on
- PSQL_USER=postgres
Expand All @@ -43,7 +43,7 @@ matrix:
dist: xenial
name: 'GoCryptoTrader [back-end] [linux] [32-bit]'
go:
- 1.15.x
- 1.17.x
env:
- GO111MODULE=on
- NO_RACE_TEST=1
Expand Down Expand Up @@ -72,7 +72,7 @@ matrix:
os: osx
name: 'GoCryptoTrader [back-end] [darwin]'
go:
- 1.15.x
- 1.17.x
env:
- GO111MODULE=on
- PSQL_USER=postgres
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.15 as build
FROM golang:1.17 as build
WORKDIR /go/src/github.com/thrasher-corp/gocryptotrader
COPY . .
RUN GO111MODULE=on go mod vendor
Expand Down
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LDFLAGS = -ldflags "-w -s"
GCTPKG = github.com/thrasher-corp/gocryptotrader
LINTPKG = github.com/golangci/golangci-lint/cmd/golangci-lint@v1.31.0
LINTPKG = github.com/golangci/golangci-lint/cmd/golangci-lint@v1.42.1
LINTBIN = $(GOPATH)/bin/golangci-lint
GCTLISTENPORT=9050
GCTPROFILERLISTENPORT=8085
Expand All @@ -14,11 +14,11 @@ CONFIG_FLAG = $(if $(CONFIG),-config $(CONFIG),)
all: check build

get:
GO111MODULE=on go get $(GCTPKG)
go install $(GCTPKG)

linter:
GO111MODULE=on go get $(GCTPKG)
GO111MODULE=on go get $(LINTPKG)
go install $(GCTPKG)
go install $(LINTPKG)
test -z "$$($(LINTBIN) run --verbose | tee /dev/stderr)"

check: linter test
Expand All @@ -31,19 +31,19 @@ else
endif

build:
GO111MODULE=on go build $(LDFLAGS)
go build $(LDFLAGS)

install:
GO111MODULE=on go install $(LDFLAGS)
go install $(LDFLAGS)

fmt:
gofmt -l -w -s $(shell find . -type f -name '*.go')

update_deps:
GO111MODULE=on go mod verify
GO111MODULE=on go mod tidy
go mod verify
go mod tidy
rm -rf vendor
GO111MODULE=on go mod vendor
go mod vendor

.PHONY: profile_heap
profile_heap:
Expand Down
3 changes: 1 addition & 2 deletions backtester/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1208,8 +1208,7 @@ func TestValidate(t *testing.T) {
},
},
}
err := c.Validate()
if !errors.Is(err, nil) {
if err := c.Validate(); !errors.Is(err, nil) {
t.Errorf("received %v expected %v", err, nil)
}
}
3 changes: 1 addition & 2 deletions backtester/config/configbuilder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@ func parseDatabase(reader *bufio.Reader, cfg *config.Config) error {
}

fmt.Printf("What is the end date? Leave blank for \"%v\"\n", defaultStart.Format(gctcommon.SimpleTimeFormat))
endDate := quickParse(reader)
if endDate != "" {
if endDate := quickParse(reader); endDate != "" {
cfg.DataSettings.DatabaseData.EndDate, err = time.Parse(endDate, gctcommon.SimpleTimeFormat)
if err != nil {
return err
Expand Down
32 changes: 14 additions & 18 deletions backtester/data/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ type fakeDataHandler struct {
func TestBaseDataFunctions(t *testing.T) {
t.Parallel()
var d Base
latest := d.Latest()
if latest != nil {
if latest := d.Latest(); latest != nil {
t.Error("expected nil")
}
d.Next()
Expand All @@ -37,17 +36,14 @@ func TestBaseDataFunctions(t *testing.T) {
if o != 0 {
t.Error("expected 0")
}
list := d.List()
if list != nil {
if list := d.List(); list != nil {
t.Error("expected nil")
}
history := d.History()
if history != nil {
if history := d.History(); history != nil {
t.Error("expected nil")
}
d.SetStream(nil)
st := d.GetStream()
if st != nil {
if st := d.GetStream(); st != nil {
t.Error("expected nil")
}
d.Reset()
Expand Down Expand Up @@ -91,24 +87,24 @@ func TestStream(t *testing.T) {

d.SortStream()

f = d.Next().(fakeDataHandler)
if f.time != 1 {
f, ok := d.Next().(fakeDataHandler)
if f.time != 1 || !ok {
t.Error("expected 1")
}
f = d.Next().(fakeDataHandler)
if f.time != 2 {
f, ok = d.Next().(fakeDataHandler)
if f.time != 2 || !ok {
t.Error("expected 2")
}
f = d.Next().(fakeDataHandler)
if f.time != 4 {
f, ok = d.Next().(fakeDataHandler)
if f.time != 4 || !ok {
t.Error("expected 4")
}
f = d.Next().(fakeDataHandler)
if f.time != 10 {
f, ok = d.Next().(fakeDataHandler)
if f.time != 10 || !ok {
t.Error("expected 10")
}
f = d.Next().(fakeDataHandler)
if f.time != 20 {
f, ok = d.Next().(fakeDataHandler)
if f.time != 20 || !ok {
t.Error("expected 20")
}
}
Expand Down
3 changes: 1 addition & 2 deletions backtester/data/kline/kline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ func TestHasDataAtTime(t *testing.T) {
},
},
}
err := d.Load()
if err != nil {
if err := d.Load(); err != nil {
t.Error(err)
}

Expand Down
3 changes: 1 addition & 2 deletions backtester/eventhandlers/eventholder/eventholder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ func TestAppendEvent(t *testing.T) {
func TestNextEvent(t *testing.T) {
t.Parallel()
e := Holder{Queue: []common.EventHandler{}}
ev := e.NextEvent()
if ev != nil {
if ev := e.NextEvent(); ev != nil {
t.Error("expected not ok")
}

Expand Down
3 changes: 1 addition & 2 deletions backtester/eventhandlers/portfolio/holdings/holdings.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func (h *Holding) HasFunds() bool {

func (h *Holding) update(e fill.Event, f funding.IPairReader) {
direction := e.GetDirection()
o := e.GetOrder()
if o != nil {
if o := e.GetOrder(); o != nil {
amount := decimal.NewFromFloat(o.Amount)
fee := decimal.NewFromFloat(o.Fee)
price := decimal.NewFromFloat(o.Price)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestUpdate(t *testing.T) {
if err != nil {
t.Error(err)
}
t1 := h.Timestamp
t1 := h.Timestamp // nolint:ifshort,nolintlint // false positive and triggers only on Windows
h.Update(&fill.Fill{
Base: event.Base{
Time: time.Now(),
Expand Down
3 changes: 1 addition & 2 deletions backtester/eventhandlers/portfolio/portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ func (p *Portfolio) addComplianceSnapshot(fillEvent fill.Event) error {
return err
}
prevSnap := complianceManager.GetLatestSnapshot()
fo := fillEvent.GetOrder()
if fo != nil {
if fo := fillEvent.GetOrder(); fo != nil {
price := decimal.NewFromFloat(fo.Price)
amount := decimal.NewFromFloat(fo.Amount)
fee := decimal.NewFromFloat(fo.Fee)
Expand Down
3 changes: 1 addition & 2 deletions backtester/eventhandlers/statistics/statistics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,7 @@ func TestAddComplianceSnapshotForTime(t *testing.T) {
func TestSerialise(t *testing.T) {
t.Parallel()
s := Statistic{}
_, err := s.Serialise()
if err != nil {
if _, err := s.Serialise(); err != nil {
t.Error(err)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import (

func TestName(t *testing.T) {
d := Strategy{}
n := d.Name()
if n != Name {
if n := d.Name(); n != Name {
t.Errorf("expected %v", Name)
}
}
Expand Down
3 changes: 1 addition & 2 deletions backtester/eventhandlers/strategies/rsi/rsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ func (s *Strategy) OnSignal(d data.Handler, _ funding.IFundTransferer) (signal.E
return nil, err
}
es.SetPrice(d.Latest().ClosePrice())
offset := d.Offset()

if offset <= int(s.rsiPeriod.IntPart()) {
if offset := d.Offset(); offset <= int(s.rsiPeriod.IntPart()) {
es.AppendReason("Not enough data for signal generation")
es.SetDirection(common.DoNothing)
return &es, nil
Expand Down
3 changes: 1 addition & 2 deletions backtester/eventhandlers/strategies/rsi/rsi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import (
func TestName(t *testing.T) {
t.Parallel()
d := Strategy{}
n := d.Name()
if n != Name {
if n := d.Name(); n != Name {
t.Errorf("expected %v", Name)
}
}
Expand Down
Loading

0 comments on commit f0d45aa

Please sign in to comment.