Skip to content

Commit

Permalink
CI/build: Update Go version, linters and fix minor issues (#1612)
Browse files Browse the repository at this point in the history
* CI/build: Update Go version, linters and fix minor issues

* linters: Add intrange, copyloopvar, additional go vet linters to match gopls and fix issues
  • Loading branch information
thrasher- authored Aug 16, 2024
1 parent facf291 commit 225429b
Show file tree
Hide file tree
Showing 111 changed files with 239 additions and 379 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/arm64.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM arm64v8/golang:1.22
FROM arm64v8/golang:1.23

WORKDIR /app

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22.x'
go-version: '1.23.x'
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.56.1
version: v1.60.1
2 changes: 1 addition & 1 deletion .github/workflows/proto-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.22.x
go-version: 1.23.x

- name: Setup build depends
run: |
Expand Down
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.22.x
GO_VERSION: 1.23.x
jobs:
backend-psql:
name: GoCryptoTrader back-end
Expand Down
37 changes: 18 additions & 19 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ run:
timeout: 10m
issues-exit-code: 1
tests: true
skip-dirs:
- vendor
- web/
- testdata
- database/models/

linters:
disable-all: true
Expand All @@ -24,24 +19,25 @@ linters:
- asciicheck
- bidichk
- bodyclose
# - canonicalheader
- containedctx
# - contextcheck
- copyloopvar
# - cyclop
# - deadcode // abandoned by its owner, replaced by unused
- decorder
# - depguard
- dogsled
# - dupl
- dupword
- durationcheck
# - err113
- errchkjson
- errname
# - errorlint
- execinquery
# - exhaustive
# - exhaustivestruct // abandoned by its owner, replaced by exhaustruct
# - exhaustruct
- exportloopref
- fatcontext
# - forbidigo
- forcetypeassert
# - funlen
Expand All @@ -57,32 +53,28 @@ linters:
# - gocyclo
# - godot
# - godox
# - goerr113
- gofmt
# - gofumpt
# - goheader
- goimports
# - golint // deprecated since 1.41.0, replaced by revive
# - gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
# - gosmopolitan
- grouper
# - ifshort // deprecated by its owner
# - importas
# - inamedparam
# - interfacebloat
# - interfacer // deprecated by its owner
- intrange
# - ireturn
# - lll
# - loggercheck
# - maintidx
- makezero
# - maligned // deprecated by its owner, replaced by govet 'fieldalignment'
- mirror
- misspell
# - mnd
# - musttag
# - nakedret
# - nestif
Expand All @@ -92,7 +84,6 @@ linters:
- noctx
- nolintlint
# - nonamedreturns
# - nosnakecase // deprecated by its owner, replaced by revive 'var-naming'
- nosprintfhostport
# - paralleltest
- perfsprint
Expand All @@ -103,9 +94,9 @@ linters:
- reassign
- revive
- rowserrcheck
# - scopelint // deprecated since v1.39.0, replaced by exportloopref
# - sloglint
# - spancheck
- sqlclosecheck
# - structcheck // abandoned by its owner, replaced by unused
- stylecheck
- tagalign
# - tagliatelle
Expand All @@ -118,7 +109,6 @@ linters:
- unconvert
- unparam
- usestdlibvars
# - varcheck // abandoned by its owner, replaced by unused
# - varnamelen
- wastedassign
- whitespace
Expand All @@ -128,7 +118,10 @@ linters:

linters-settings:
govet:
check-shadowing: true
enable:
- shadow
- nilness
- unusedwrite
goconst:
min-occurrences: 6
gocritic:
Expand Down Expand Up @@ -158,6 +151,12 @@ issues:
linters:
- gosec

exclude-dirs:
- vendor
- web/
- testdata
- database/models/

# List of regexps of issue texts to exclude, empty list by default.
# But independently from this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`. To list all
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.22 as build
FROM golang:1.23 as build
WORKDIR /go/src/github.com/thrasher-corp/gocryptotrader
COPY . .
RUN GO111MODULE=on go mod vendor
Expand Down
2 changes: 1 addition & 1 deletion 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.56.1
LINTPKG = github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.1
LINTBIN = $(GOPATH)/bin/golangci-lint
GCTLISTENPORT=9050
GCTPROFILERLISTENPORT=8085
Expand Down
8 changes: 4 additions & 4 deletions backtester/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func FitStringToLimit(str, spacer string, limit int, upper bool) string {
return str[0:limit]
}
spacerLen := len(spacer)
for i := 0; i < limResp; i++ {
for i := range limResp {
str += spacer
for j := 0; j < spacerLen; j++ {
for j := range spacerLen {
if j > 0 {
// prevent clever people from going beyond
// the limit by having a spacer longer than 1
Expand Down Expand Up @@ -206,10 +206,10 @@ func Logo() string {
sb := strings.Builder{}
sb.WriteString(" \n")
sb.WriteString(" " + CMDColours.White + "@@@@@@@@@@@@@@@@@ \n")
sb.WriteString(" " + CMDColours.White + "@@@@@@@@@@@@@@@@@@@@@@@ " + CMDColours.Grey + ",,,,,," + CMDColours.White + " \n") //nolint:goconst // not needed for this glorious logo
sb.WriteString(" " + CMDColours.White + "@@@@@@@@@@@@@@@@@@@@@@@ " + CMDColours.Grey + ",,,,,," + CMDColours.White + " \n")
sb.WriteString(" " + CMDColours.White + "@@@@@@@@" + CMDColours.Grey + ",,,,, " + CMDColours.White + "@@@@@@@@@" + CMDColours.Grey + ",,,,,,,," + CMDColours.White + " \n")
sb.WriteString(" " + CMDColours.White + "@@@@@@@@" + CMDColours.Grey + ",,,,,,, " + CMDColours.White + "@@@@@@@" + CMDColours.Grey + ",,,,,,," + CMDColours.White + " \n")
sb.WriteString(" " + CMDColours.White + "@@@@@@" + CMDColours.Grey + "(,,,,,,,, " + CMDColours.Grey + ",," + CMDColours.White + "@@@@@@@" + CMDColours.Grey + ",,,,,," + CMDColours.White + " \n") //nolint:goconst // not needed for this glorious logo
sb.WriteString(" " + CMDColours.White + "@@@@@@" + CMDColours.Grey + "(,,,,,,,, " + CMDColours.Grey + ",," + CMDColours.White + "@@@@@@@" + CMDColours.Grey + ",,,,,," + CMDColours.White + " \n")
sb.WriteString(" " + CMDColours.Grey + ",," + CMDColours.White + "@@@@@@" + CMDColours.Grey + ",,,,,,,,, #,,,,,,,,,,,,,,,,,," + CMDColours.White + " \n")
sb.WriteString(" " + CMDColours.Grey + ",,,,*" + CMDColours.White + "@@@@@@" + CMDColours.Grey + ",,,,,,,,,,,,,,,,,,,,,,,,,," + CMDColours.Green + "%%%%%%%" + CMDColours.White + " \n")
sb.WriteString(" " + CMDColours.Grey + ",,,,,,,*" + CMDColours.White + "@@@@@@" + CMDColours.Grey + ",,,,,,,,,,,,,," + CMDColours.Green + "%%%%%" + CMDColours.Grey + " ,,,,,," + CMDColours.Grey + "%" + CMDColours.Green + "%%%%%%" + CMDColours.White + " \n")
Expand Down
2 changes: 0 additions & 2 deletions backtester/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func TestCanTransact(t *testing.T) {
expected: false,
},
} {
ti := ti
t.Run(ti.side.String(), func(t *testing.T) {
t.Parallel()
if CanTransact(ti.side) != ti.expected {
Expand Down Expand Up @@ -124,7 +123,6 @@ func TestDataTypeConversion(t *testing.T) {
expectErr: true,
},
} {
ti := ti
t.Run(ti.title, func(t *testing.T) {
t.Parallel()
got, err := DataTypeToInt(ti.dataType)
Expand Down
2 changes: 1 addition & 1 deletion backtester/config/strategyconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (c *Config) PrintSetting() {
c.CurrencySettings[i].Asset,
c.CurrencySettings[i].Base,
c.CurrencySettings[i].Quote)
log.Infof(common.Config, currStr[:61])
log.Infoln(common.Config, currStr[:61])
log.Infof(common.Config, "Exchange: %v", c.CurrencySettings[i].ExchangeName)
switch {
case c.DataSettings.LiveData != nil && c.DataSettings.LiveData.RealOrders:
Expand Down
11 changes: 0 additions & 11 deletions backtester/engine/backtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1416,21 +1416,10 @@ func TestRunLive(t *testing.T) {
bt.LiveDataHandler = dc
cp := currency.NewPair(currency.BTC, currency.USD)
i := &gctkline.Item{
Exchange: testExchange,
Pair: cp,
UnderlyingPair: cp,
Asset: asset.Spot,
Interval: gctkline.FifteenSecond,
Candles: []gctkline.Candle{
{
Time: time.Now(),
Open: 1337,
High: 1337,
Low: 1337,
Close: 1337,
Volume: 1337,
},
},
}
// AppendDataSource(exchange gctexchange.IBotExchange, interval gctkline.Interval, asset asset.Asset, pair, underlyingPair currency.Pair, dataType int64) error
setup := &liveDataSourceSetup{
Expand Down
12 changes: 7 additions & 5 deletions backtester/engine/grpcserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,13 @@ func TestExecuteStrategyFromConfig(t *testing.T) {
}
var fd *btrpc.FuturesDetails
if defaultConfig.CurrencySettings[i].FuturesDetails != nil {
fd.Leverage = &btrpc.Leverage{
CanUseLeverage: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.CanUseLeverage,
MaximumOrdersWithLeverageRatio: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.MaximumOrdersWithLeverageRatio.String(),
MaximumLeverageRate: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.MaximumOrderLeverageRate.String(),
MaximumCollateralLeverageRate: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.MaximumCollateralLeverageRate.String(),
fd = &btrpc.FuturesDetails{
Leverage: &btrpc.Leverage{
CanUseLeverage: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.CanUseLeverage,
MaximumOrdersWithLeverageRatio: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.MaximumOrdersWithLeverageRatio.String(),
MaximumLeverageRate: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.MaximumOrderLeverageRate.String(),
MaximumCollateralLeverageRate: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.MaximumCollateralLeverageRate.String(),
},
}
}
var makerFee, takerFee string
Expand Down
1 change: 0 additions & 1 deletion backtester/engine/live_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var (
ErrLiveDataTimeout = errors.New("no data processed within timeframe")

errDataSourceExists = errors.New("data source already exists")
errInvalidCredentials = errors.New("credentials are invalid, please check your config")
errNoCredsNoLive = errors.New("cannot use real orders without credentials to fulfil those real orders")
errNoDataSetForClosingPositions = errors.New("no data was set for closing positions")
errNilError = errors.New("nil error received when expecting an error")
Expand Down
3 changes: 0 additions & 3 deletions backtester/eventhandlers/exchange/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ func TestPlaceOrder(t *testing.T) {
if !errors.Is(err, nil) {
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
}
bot.ExchangeManager = em
bot.OrderManager, err = engine.SetupOrderManager(em, &engine.CommunicationManager{}, &bot.ServicesWG, &gctconfig.OrderManager{})
if !errors.Is(err, nil) {
t.Errorf("received '%v' expected '%v'", err, nil)
Expand Down Expand Up @@ -256,7 +255,6 @@ func TestExecuteOrder(t *testing.T) {
if !errors.Is(err, nil) {
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
}
bot.ExchangeManager = em
bot.OrderManager, err = engine.SetupOrderManager(em, &engine.CommunicationManager{}, &bot.ServicesWG, &gctconfig.OrderManager{})
if !errors.Is(err, nil) {
t.Errorf("received: %v, expected: %v", err, nil)
Expand Down Expand Up @@ -392,7 +390,6 @@ func TestExecuteOrderBuySellSizeLimit(t *testing.T) {
if !errors.Is(err, nil) {
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
}
bot.ExchangeManager = em
bot.OrderManager, err = engine.SetupOrderManager(em, &engine.CommunicationManager{}, &bot.ServicesWG, &gctconfig.OrderManager{})
if !errors.Is(err, nil) {
t.Errorf("received: %v, expected: %v", err, nil)
Expand Down
2 changes: 1 addition & 1 deletion backtester/eventhandlers/statistics/printresults.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (c *CurrencyPairStatistic) PrintResults(e string, a asset.Item, p currency.
last.Holdings.TotalValueLost = last.Holdings.TotalValueLostToSlippage.Add(last.Holdings.TotalValueLostToVolumeSizing)
sep := fmt.Sprintf("%v %v %v |\t", fSIL(e, limit12), fSIL(a.String(), limit10), fSIL(p.String(), limit14))
currStr := fmt.Sprintf(common.CMDColours.H1+"------------------Stats for %v %v %v------------------------------------------------------"+common.CMDColours.Default, e, a, p)
log.Infof(common.CurrencyStatistics, currStr[:70])
log.Infoln(common.CurrencyStatistics, currStr[:70])
if a.IsFutures() {
log.Infof(common.CurrencyStatistics, "%s Long orders: %s", sep, convert.IntToHumanFriendlyString(c.BuyOrders, ","))
log.Infof(common.CurrencyStatistics, "%s Short orders: %s", sep, convert.IntToHumanFriendlyString(c.SellOrders, ","))
Expand Down
2 changes: 1 addition & 1 deletion backtester/eventhandlers/statistics/statistics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ func TestCalculateBiggestEventDrawdown(t *testing.T) {
a := asset.Spot
p := currency.NewPair(currency.BTC, currency.USDT)
var events []data.Event
for i := int64(0); i < 100; i++ {
for i := range int64(100) {
tt1 = tt1.Add(gctkline.OneDay.Duration())
even := &event.Base{
Exchange: exch,
Expand Down
19 changes: 0 additions & 19 deletions backtester/funding/funding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ func TestExists(t *testing.T) {
t.Errorf("received '%v' expected '%v'", err, nil)
}

_, err = f.getFundingForEAP(exchName, a, pair)
if !errors.Is(err, nil) {
t.Errorf("received '%v' expected '%v'", err, nil)
}
// demonstration that you don't need the original *Items
// to check for existence, just matching fields
baseCopy := Item{
Expand All @@ -234,21 +230,6 @@ func TestExists(t *testing.T) {
isCollateral: baseItem.isCollateral,
collateralCandles: baseItem.collateralCandles,
}
quoteCopy := Item{
exchange: quoteItem.exchange,
asset: quoteItem.asset,
currency: quoteItem.currency,
initialFunds: quoteItem.initialFunds,
available: quoteItem.available,
reserved: quoteItem.reserved,
transferFee: quoteItem.transferFee,
pairedWith: quoteItem.pairedWith,
trackingCandles: quoteItem.trackingCandles,
snapshot: quoteItem.snapshot,
isCollateral: quoteItem.isCollateral,
collateralCandles: quoteItem.collateralCandles,
}
quoteCopy.pairedWith = &baseCopy
if !f.Exists(&baseCopy) {
t.Errorf("received '%v' expected '%v'", false, true)
}
Expand Down
3 changes: 0 additions & 3 deletions backtester/funding/trackingcurrencies/trackingcurrencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ func CreateUSDTrackingPairs(tp []TrackingPair, em *engine.ExchangeManager) ([]Tr
} else {
b := exch.GetBase()
a := tp[i].Asset
if err != nil {
return nil, err
}
if a.IsFutures() {
// futures matches to spot, not like this
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ func TestFindMatchingUSDPairs(t *testing.T) {
expectedErr: errCurrencyNotFoundInPairs,
},
}
for i := range tests {
tt := tests[i]
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
t.Parallel()
basePair, quotePair, err := findMatchingUSDPairs(tt.initialPair, tt.availablePairs)
Expand Down Expand Up @@ -222,8 +221,7 @@ func TestPairContainsUSD(t *testing.T) {
currency.NewPair(currency.BTC, currency.PAX),
},
}
for i := range pairs {
tt := pairs[i]
for _, tt := range pairs {
t.Run(tt.description, func(t *testing.T) {
t.Parallel()
resp := pairContainsUSD(tt.pair)
Expand Down
4 changes: 2 additions & 2 deletions cmd/exchange_wrapper_coverage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ func testWrappers(e exchange.IBotExchange) ([]string, error) {
contextParam := reflect.TypeOf((*context.Context)(nil)).Elem()

var funcs []string
for x := 0; x < iExchange.NumMethod(); x++ {
for x := range iExchange.NumMethod() {
name := iExchange.Method(x).Name
method := actualExchange.MethodByName(name)
inputs := make([]reflect.Value, method.Type().NumIn())

for y := 0; y < method.Type().NumIn(); y++ {
for y := range method.Type().NumIn() {
input := method.Type().In(y)

if input.Implements(contextParam) {
Expand Down
Loading

0 comments on commit 225429b

Please sign in to comment.