Skip to content

Commit

Permalink
CI/build: Update Go version, linters and fix minor issues (thrasher-c…
Browse files Browse the repository at this point in the history
…orp#1473)

* CI/build: Update Go version, linters and fix minor issues

* Bump golangci-lint to v1.56.1

* BinanceUS: Make uint usage consistent

* Throw blank identifiers into the trash
  • Loading branch information
thrasher- authored Feb 14, 2024
1 parent 9ff502b commit 08da42d
Show file tree
Hide file tree
Showing 79 changed files with 364 additions and 374 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.21
FROM arm64v8/golang:1.22

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,9 +8,9 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21.x'
go-version: '1.22.x'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.54.0
version: v1.56.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.21.x
go-version: 1.22.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.21.x
GO_VERSION: 1.22.x
jobs:
backend-psql:
name: GoCryptoTrader back-end
Expand Down
12 changes: 11 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ linters:
- govet
- ineffassign
- staticcheck
- typecheck
# - unused

# disabled by default linters
Expand Down Expand Up @@ -51,6 +50,7 @@ linters:
- gocheckcompilerdirectives
# - gochecknoglobals
# - gochecknoinits
- gochecksumtype
# - gocognit
- goconst
- gocritic
Expand All @@ -72,6 +72,7 @@ linters:
- grouper
# - ifshort // deprecated by its owner
# - importas
# - inamedparam
# - interfacebloat
# - interfacer // deprecated by its owner
# - ireturn
Expand All @@ -94,19 +95,23 @@ linters:
# - nosnakecase // deprecated by its owner, replaced by revive 'var-naming'
- nosprintfhostport
# - paralleltest
- perfsprint
- prealloc
- predeclared
# - promlinter
# - protogetter
- reassign
- revive
- rowserrcheck
# - scopelint // deprecated since v1.39.0, replaced by exportloopref
- sqlclosecheck
# - structcheck // abandoned by its owner, replaced by unused
- stylecheck
- tagalign
# - tagliatelle
- tenv
- testableexamples
- testifylint
# - testpackage
- thelper
- tparallel
Expand Down Expand Up @@ -136,6 +141,11 @@ linters-settings:
- importShadow
- methodExprCall
- evalOrder
testifylint:
enable-all: true
disable:
- require-error
- float-compare

issues:
max-issues-per-linter: 0
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.21 as build
FROM golang:1.22 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.54.0
LINTPKG = github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.1
LINTBIN = $(GOPATH)/bin/golangci-lint
GCTLISTENPORT=9050
GCTPROFILERLISTENPORT=8085
Expand Down
4 changes: 2 additions & 2 deletions backtester/common/common.go
Original file line number Diff line number Diff line change
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")
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 + "@@@@@@@@@" + 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")
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.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
10 changes: 5 additions & 5 deletions backtester/engine/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,21 @@ func (s *GRPCServer) StartRPCRESTProxy() error {
func (s *GRPCServer) authenticateClient(ctx context.Context) (context.Context, error) {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return ctx, fmt.Errorf("unable to extract metadata")
return ctx, errors.New("unable to extract metadata")
}

authStr, ok := md["authorization"]
if !ok {
return ctx, fmt.Errorf("authorization header missing")
return ctx, errors.New("authorization header missing")
}

if !strings.Contains(authStr[0], "Basic") {
return ctx, fmt.Errorf("basic not found in authorization header")
return ctx, errors.New("basic not found in authorization header")
}

decoded, err := crypto.Base64Decode(strings.Split(authStr[0], " ")[1])
if err != nil {
return ctx, fmt.Errorf("unable to base64 decode authorization header")
return ctx, errors.New("unable to base64 decode authorization header")
}

creds := strings.Split(string(decoded), ":")
Expand All @@ -164,7 +164,7 @@ func (s *GRPCServer) authenticateClient(ctx context.Context) (context.Context, e

if username != s.config.GRPC.Username ||
password != s.config.GRPC.Password {
return ctx, fmt.Errorf("username/password mismatch")
return ctx, errors.New("username/password mismatch")
}
return ctx, nil
}
Expand Down
2 changes: 1 addition & 1 deletion backtester/engine/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ func (bt *BackTest) loadData(cfg *config.Config, exch gctexchange.IBotExchange,
return nil, err
}
if resp == nil {
return nil, fmt.Errorf("processing error, response returned nil")
return nil, errors.New("processing error, response returned nil")
}

resp.Item.UnderlyingPair = underlyingPair
Expand Down
8 changes: 4 additions & 4 deletions cmd/apichecker/apicheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ func addExch(exchName, checkType string, data interface{}, isUpdate bool) error
}
if canUpdateTrello() {
if !isUpdate {
err := trelloCreateNewCheck(fmt.Sprintf("%s 1", exchName))
err := trelloCreateNewCheck(exchName + " 1")
if err != nil {
return err
}
Expand Down Expand Up @@ -1187,7 +1187,7 @@ func nameStateChanges(currentName, currentState string) (string, error) {
}
name = fmt.Sprintf("%s %s", strings.Split(currentName, " ")[0], strings.Split(currentName, " ")[1])
if !exists {
return fmt.Sprintf("%s 1", name), nil
return name + " 1", nil
}
num, err = strconv.ParseInt(strings.Split(currentName, " ")[2], 10, 64)
if err != nil {
Expand All @@ -1198,15 +1198,15 @@ func nameStateChanges(currentName, currentState string) (string, error) {
exists = true
name = strings.Split(currentName, " ")[0]
if !exists {
return fmt.Sprintf("%s 1", name), nil
return name + " 1", nil
}
num, err = strconv.ParseInt(strings.Split(currentName, " ")[1], 10, 64)
if err != nil {
return "", err
}
}
if !exists {
return fmt.Sprintf("%s 1", name), nil
return name + " 1", nil
}
}

Expand Down
14 changes: 7 additions & 7 deletions cmd/gctcli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ func cancelOrder(c *cli.Context) error {

// pair is optional, but if it's set, do a validity check
var p currency.Pair
if len(currencyPair) > 0 {
if currencyPair != "" {
if !validPair(currencyPair) {
return errInvalidPair
}
Expand Down Expand Up @@ -1917,7 +1917,7 @@ func cancelBatchOrders(c *cli.Context) error {

// pair is optional, but if it's set, do a validity check
var p currency.Pair
if len(currencyPair) > 0 {
if currencyPair != "" {
if !validPair(currencyPair) {
return errInvalidPair
}
Expand Down Expand Up @@ -2208,19 +2208,19 @@ func addEvent(c *cli.Context) error {
if c.IsSet("exchange") {
exchangeName = c.String("exchange")
} else {
return fmt.Errorf("exchange name is required")
return errors.New("exchange name is required")
}

if c.IsSet("item") {
item = c.String("item")
} else {
return fmt.Errorf("item is required")
return errors.New("item is required")
}

if c.IsSet("condition") {
condition = c.String("condition")
} else {
return fmt.Errorf("condition is required")
return errors.New("condition is required")
}

if c.IsSet("price") {
Expand All @@ -2242,7 +2242,7 @@ func addEvent(c *cli.Context) error {
if c.IsSet("pair") {
currencyPair = c.String("pair")
} else {
return fmt.Errorf("currency pair is required")
return errors.New("currency pair is required")
}

if !validPair(currencyPair) {
Expand All @@ -2261,7 +2261,7 @@ func addEvent(c *cli.Context) error {
if c.IsSet("action") {
action = c.String("action")
} else {
return fmt.Errorf("action is required")
return errors.New("action is required")
}

p, err := currency.NewPairDelimiter(currencyPair, pairDelimiter)
Expand Down
12 changes: 6 additions & 6 deletions common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ func TestErrors(t *testing.T) {
e5 := errors.New("add vodka")

// Nil tests
assert.Nil(t, AppendError(nil, nil), "Append nil to nil should nil")
assert.NoError(t, AppendError(nil, nil), "Append nil to nil should nil")
assert.Same(t, AppendError(e1, nil), e1, "Append nil to e1 should e1")
assert.Same(t, AppendError(nil, e2), e2, "Append e2 to nil should e2")

Expand All @@ -676,7 +676,7 @@ func TestErrors(t *testing.T) {

err = ExcludeError(err, e2)
assert.ErrorIs(t, err, e1, "Should still be bored")
assert.False(t, errors.Is(err, e2), "Should not be an e2")
assert.NotErrorIs(t, err, e2, "Should not be an e2")
me, ok := err.(*multiError)
if assert.True(t, ok, "Should be a multiError") {
assert.Len(t, me.errs, 2, "Should only have 2 errors")
Expand All @@ -690,19 +690,19 @@ func TestErrors(t *testing.T) {
err = fmt.Errorf("%w: %w", e3, fmt.Errorf("%w: %w", e4, e5))
assert.ErrorIs(t, ExcludeError(err, e4), e3, "Excluding e4 should retain e3")
assert.ErrorIs(t, ExcludeError(err, e4), e5, "Excluding e4 should retain the vanilla co-wrapped e5")
assert.False(t, errors.Is(ExcludeError(err, e4), e4), "e4 should be excluded")
assert.NotErrorIs(t, ExcludeError(err, e4), e4, "e4 should be excluded")
assert.ErrorIs(t, ExcludeError(err, e5), e3, "Excluding e5 should retain e3")
assert.ErrorIs(t, ExcludeError(err, e5), e4, "Excluding e5 should retain the vanilla co-wrapped e4")
assert.False(t, errors.Is(ExcludeError(err, e5), e5), "e5 should be excluded")
assert.NotErrorIs(t, ExcludeError(err, e5), e5, "e5 should be excluded")

// Hybrid tests
err = AppendError(fmt.Errorf("%w: %w", e4, e5), e3)
assert.ErrorIs(t, ExcludeError(err, e4), e3, "Excluding e4 should retain e3")
assert.ErrorIs(t, ExcludeError(err, e4), e5, "Excluding e4 should retain the vanilla co-wrapped e5")
assert.False(t, errors.Is(ExcludeError(err, e4), e4), "e4 should be excluded")
assert.NotErrorIs(t, ExcludeError(err, e4), e4, "e4 should be excluded")
assert.ErrorIs(t, ExcludeError(err, e5), e3, "Excluding e5 should retain e3")
assert.ErrorIs(t, ExcludeError(err, e5), e4, "Excluding e5 should retain the vanilla co-wrapped e4")
assert.False(t, errors.Is(ExcludeError(err, e5), e5), "e4 should be excluded")
assert.NotErrorIs(t, ExcludeError(err, e5), e5, "e4 should be excluded")
}

func TestParseStartEndDate(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions common/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ func IntToHumanFriendlyString(number int64, thousandsSep string) string {
number = -number
neg = true
}
str := fmt.Sprintf("%v", number)
return numberToHumanFriendlyString(str, 0, "", thousandsSep, neg)
return numberToHumanFriendlyString(strconv.FormatInt(number, 10), 0, "", thousandsSep, neg)
}

// FloatToHumanFriendlyString converts a float to a comma separated string at the thousand point
Expand Down
4 changes: 2 additions & 2 deletions common/file/file_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package file

import (
"fmt"
"errors"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -70,7 +70,7 @@ func TestMove(t *testing.T) {
}

if !strings.Contains(string(contents), "GoCryptoTrader") {
return fmt.Errorf("unable to find previously written data")
return errors.New("unable to find previously written data")
}

return os.Remove(out)
Expand Down
2 changes: 1 addition & 1 deletion communications/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (t *Telegram) HandleMessages(text string, chatID int64) error {
return t.SendMessage(fmt.Sprintf("%s: %s", talkRoot, cmdHelpReply), chatID)

case strings.Contains(text, cmdStart):
return t.SendMessage(fmt.Sprintf("%s: START COMMANDS HERE", talkRoot), chatID)
return t.SendMessage(talkRoot+": START COMMANDS HERE", chatID)

case strings.Contains(text, cmdStatus):
return t.SendMessage(fmt.Sprintf("%s: %s", talkRoot, t.GetStatus()), chatID)
Expand Down
4 changes: 2 additions & 2 deletions currency/forexprovider/currencylayer/currencylayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestGetHistoricalData(t *testing.T) {
r, err := c.GetHistoricalData("2022-09-26", []string{"USD"}, "EUR")
if assert.NoError(t, err, "GetHistoricalData should not error") {
assert.Contains(t, r, "EURUSD", "Should find rate")
assert.Equal(t, r["EURUSD"], 0.962232, "Rate should be exactly correct")
assert.Equal(t, 0.962232, r["EURUSD"], "Rate should be exactly correct")
}
}

Expand All @@ -110,7 +110,7 @@ func TestQueryTimeFrame(t *testing.T) {
assert.Len(t, r, 5, "Should get correct number of days")
a, ok := r["2020-03-16"].(map[string]any)
assert.True(t, ok, "Has final date entry")
assert.Equal(t, a["USDAUD"], 1.6397, "And it was a bad week")
assert.Equal(t, 1.6397, a["USDAUD"], "And it was a bad week")
}
}

Expand Down
10 changes: 5 additions & 5 deletions currency/forexprovider/exchangeratesapi.io/exchangeratesapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ func (e *ExchangeRates) GetSymbols() (map[string]string, error) {
// all supported currencies
func (e *ExchangeRates) GetLatestRates(baseCurrency, symbols string) (*Rates, error) {
vals := url.Values{}
if len(baseCurrency) > 0 && e.APIKeyLvl <= apiKeyFree && !strings.EqualFold("EUR", baseCurrency) {
if baseCurrency != "" && e.APIKeyLvl <= apiKeyFree && !strings.EqualFold("EUR", baseCurrency) {
return nil, errCannotSetBaseCurrencyOnFreePlan
} else if len(baseCurrency) > 0 {
} else if baseCurrency != "" {
vals.Set("base", baseCurrency)
}

if len(symbols) > 0 {
if symbols != "" {
symbols = e.cleanCurrencies(baseCurrency, symbols)
vals.Set("symbols", symbols)
}
Expand All @@ -120,9 +120,9 @@ func (e *ExchangeRates) GetHistoricalRates(date time.Time, baseCurrency string,
var resp HistoricalRates
v := url.Values{}

if len(baseCurrency) > 0 && e.APIKeyLvl <= apiKeyFree && !strings.EqualFold("EUR", baseCurrency) {
if baseCurrency != "" && e.APIKeyLvl <= apiKeyFree && !strings.EqualFold("EUR", baseCurrency) {
return nil, errCannotSetBaseCurrencyOnFreePlan
} else if len(baseCurrency) > 0 {
} else if baseCurrency != "" {
v.Set("base", baseCurrency)
}

Expand Down
1 change: 0 additions & 1 deletion currency/forexprovider/fixer.io/fixer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var f Fixer

var isSetup bool

//nolint:gocritic // Only used as a testing helper function in this package
func setup(t *testing.T) {
t.Helper()
if !isSetup {
Expand Down
Loading

0 comments on commit 08da42d

Please sign in to comment.