Skip to content

Commit

Permalink
CI: Bump go version, linters and fix minor issues (thrasher-corp#1010)
Browse files Browse the repository at this point in the history
* Bump golang, golangci-lint versions and fix issues

* Add -fno-stack-protector

* Fix AppVeyor golangci-lint ver

* Nitters

* Nitters round 2
  • Loading branch information
thrasher- authored Aug 17, 2022
1 parent 0c9ad9e commit 6858856
Show file tree
Hide file tree
Showing 85 changed files with 389 additions and 246 deletions.
4 changes: 2 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ services:

init:
- set PATH=%POSTGRES_PATH%\bin;%PATH%
- set PATH=C:\go118\bin;%PATH%
- set PATH=C:\go119\bin;%PATH%

install:
- set Path=C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;%Path%
Expand All @@ -55,7 +55,7 @@ before_test:

test_script:
# test back-end
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0
- '%GOPATH%\bin\golangci-lint.exe run --verbose'
- ps: >-
if($env:APPVEYOR_SCHEDULED_BUILD -eq 'true') {
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@v3
- uses: actions/setup-go@v3
with:
go-version: '1.18.x'
go-version: '1.19.x'
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.46.2
version: v1.48.0
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@v3
with:
go-version: 1.18.x
go-version: 1.19.x

- name: Setup build depends
run: |
Expand Down
3 changes: 2 additions & 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.18.x
GO_VERSION: 1.19.x
jobs:
backend-psql:
name: GoCryptoTrader back-end with PSQL
Expand Down Expand Up @@ -115,6 +115,7 @@ jobs:
PSQL_SSLMODE: disable
GOARCH: 386
CGO_ENABLED: 1
CGO_CFLAGS: -fno-stack-protector

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down
23 changes: 17 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ linters:
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
# - unused
# - varcheck

# disabled by default linters
# - asasalint
- asciicheck
- bidichk
- bodyclose
Expand All @@ -38,8 +38,10 @@ linters:
- errchkjson
- errname
# - errorlint
- execinquery
# - exhaustive
# - exhaustivestruct
# - exhaustivestruct // abandoned by its owner, replaced with exhaustruct
# - exhaustruct
- exportloopref
# - forbidigo
- forcetypeassert
Expand All @@ -65,7 +67,7 @@ linters:
- goprintffuncname
- gosec
- grouper
- ifshort
# - ifshort // deprecated by its owner
# - importas
# - interfacer // deprecated by its owner
# - ireturn
Expand All @@ -77,24 +79,32 @@ linters:
- nakedret
# - nestif
- nilerr
# - nilnil
# - nlreturn
- noctx
- nolintlint
# - nonamedreturns
# - nosnakecase
- nosprintfhostport
# - paralleltest
- prealloc
- predeclared
# - promlinter
- revive
- rowserrcheck
# - scopelint // deprecated since v1.39.0, replaced by exportloopref
# - sqlclosecheck
- sqlclosecheck
- structcheck
- stylecheck
# - tagliatelle
- tenv
# - testpackage
- thelper
- tparallel
- unconvert
- unparam
- usestdlibvars
# - varnamelen
- wastedassign
- whitespace
# - wrapcheck
Expand All @@ -103,8 +113,6 @@ linters:
linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
goconst:
min-occurrences: 6
depguard:
Expand Down Expand Up @@ -139,3 +147,6 @@ issues:
# The following silences false positives in table tests
# https://github.com/kyoh86/scopelint/issues/4
- Using the variable on range scope `ti` in function literal
include:
- EXC0012 # revive: Comment exported (.+) should have comment( \(or a comment on this block\))? or be unexported
- EXC0014 # revive: Comment on exported (.+) should be of the form "(.+)..."
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18 as build
FROM golang:1.19 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.46.2
LINTPKG = github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0
LINTBIN = $(GOPATH)/bin/golangci-lint
GCTLISTENPORT=9050
GCTPROFILERLISTENPORT=8085
Expand Down
3 changes: 2 additions & 1 deletion backtester/common/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const (
TradeStr = "trade"

// DataCandle is an int64 representation of a candle data type
DataCandle = iota
DataCandle int64 = iota
// DataTrade is an int64 representation of a trade data type
DataTrade
)

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 @@ -3,7 +3,6 @@ package config
import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -458,7 +457,7 @@ func TestValidate(t *testing.T) {

func TestReadConfigFromFile(t *testing.T) {
tempDir := t.TempDir()
passFile, err := ioutil.TempFile(tempDir, "*.start")
passFile, err := os.CreateTemp(tempDir, "*.start")
if err != nil {
t.Fatalf("Problem creating temp file at %v: %s\n", passFile, err)
}
Expand Down
6 changes: 3 additions & 3 deletions backtester/config/configbuilder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func main() {
yn := quickParse(reader)
if yn == y || yn == yes {
var fp, wd string
extension := "strat" // nolint:misspell // its shorthand for strategy
extension := "strat" //nolint:misspell // its shorthand for strategy
for {
wd, err = os.Getwd()
if err != nil {
Expand Down Expand Up @@ -427,9 +427,9 @@ func parseDatabase(reader *bufio.Reader, cfg *config.Config) error {
}
fmt.Println("What is the database Port? eg 1337")
input = quickParse(reader)
var port float64
var port uint64
if input != "" {
port, err = strconv.ParseFloat(input, 64)
port, err = strconv.ParseUint(input, 10, 16)
if err != nil {
return err
}
Expand Down
33 changes: 11 additions & 22 deletions backtester/data/kline/database/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package database
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -39,7 +38,7 @@ func TestMain(m *testing.M) {
var err error
testhelpers.PostgresTestDatabase = testhelpers.GetConnectionDetails()
testhelpers.GetConnectionDetails()
testhelpers.TempDir, err = ioutil.TempDir("", "gct-temp")
testhelpers.TempDir, err = os.MkdirTemp("", "gct-temp")
if err != nil {
fmt.Printf("failed to create temp file: %v", err)
os.Exit(1)
Expand Down Expand Up @@ -85,16 +84,7 @@ func TestLoadDataCandles(t *testing.T) {
}
database.MigrationDir = filepath.Join("..", "..", "..", "..", "database", "migrations")
testhelpers.MigrationDir = filepath.Join("..", "..", "..", "..", "database", "migrations")
_, err = testhelpers.ConnectToDatabase(&dbConfg)
if err != nil {
t.Error(err)
}

bot.DatabaseManager, err = engine.SetupDatabaseConnectionManager(&bot.Config.Database)
if err != nil {
t.Error(err)
}
err = bot.DatabaseManager.Start(&bot.ServicesWG)
conn, err := testhelpers.ConnectToDatabase(&dbConfg)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -133,6 +123,10 @@ func TestLoadDataCandles(t *testing.T) {
if err != nil {
t.Error(err)
}

if err = conn.SQL.Close(); err != nil {
t.Error(err)
}
}

func TestLoadDataTrades(t *testing.T) {
Expand Down Expand Up @@ -165,16 +159,7 @@ func TestLoadDataTrades(t *testing.T) {
}
database.MigrationDir = filepath.Join("..", "..", "..", "..", "database", "migrations")
testhelpers.MigrationDir = filepath.Join("..", "..", "..", "..", "database", "migrations")
_, err = testhelpers.ConnectToDatabase(&dbConfg)
if err != nil {
t.Error(err)
}

bot.DatabaseManager, err = engine.SetupDatabaseConnectionManager(&bot.Config.Database)
if err != nil {
t.Error(err)
}
err = bot.DatabaseManager.Start(&bot.ServicesWG)
conn, err := testhelpers.ConnectToDatabase(&dbConfg)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -206,6 +191,10 @@ func TestLoadDataTrades(t *testing.T) {
if err != nil {
t.Error(err)
}

if err = conn.SQL.Close(); err != nil {
t.Error(err)
}
}

func TestLoadDataInvalid(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion backtester/eventhandlers/exchange/slippage/slippage.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func EstimateSlippagePercentage(maximumSlippageRate, minimumSlippageRate decimal
// eg 80 means for every dollar, keep 80%
randSeed := int(minimumSlippageRate.IntPart()) - int(maximumSlippageRate.IntPart())
if randSeed > 0 {
result := int64(rand.Intn(randSeed)) // nolint:gosec // basic number generation required, no need for crypto/rand
result := int64(rand.Intn(randSeed)) //nolint:gosec // basic number generation required, no need for crypto/rand

return maximumSlippageRate.Add(decimal.NewFromInt(result)).Div(decimal.NewFromInt(100))
}
Expand Down
2 changes: 1 addition & 1 deletion backtester/eventhandlers/strategies/base/base_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var (
// ErrSimultaneousProcessingOnly is raised when a strategy is improperly configured
ErrSimultaneousProcessingOnly = errors.New("this strategy only supports simultaneous processing")
// ErrStrategyNotFound used when strategy specified in strategy config does not exist
ErrStrategyNotFound = errors.New("not found. Please ensure the strategy-settings field 'name' is spelled properly in your .strat config") // nolint:misspell // its shorthand for strategy
ErrStrategyNotFound = errors.New("not found. Please ensure the strategy-settings field 'name' is spelled properly in your .strat config") //nolint:misspell // its shorthand for strategy
// ErrInvalidCustomSettings used when bad custom settings are found in the strategy config
ErrInvalidCustomSettings = errors.New("invalid custom settings in config")
// ErrTooMuchBadData used when there is too much missing data
Expand Down
1 change: 1 addition & 0 deletions backtester/eventtypes/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (b *Base) GetReasons() []string {
return b.Reasons
}

// GetBase returns an event base
func (b *Base) GetBase() *Base {
return b
}
2 changes: 1 addition & 1 deletion backtester/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (d *Data) enhanceCandles() error {
Asset: lookup.Asset,
Pair: lookup.Pair,
Interval: lookup.Interval,
Watermark: fmt.Sprintf("%s - %s - %s", strings.Title(lookup.Exchange), lookup.Asset.String(), lookup.Pair.Upper()), // nolint // Title usage
Watermark: fmt.Sprintf("%s - %s - %s", strings.Title(lookup.Exchange), lookup.Asset.String(), lookup.Pair.Upper()), //nolint // Title usage
}

statsForCandles :=
Expand Down
2 changes: 1 addition & 1 deletion cmd/apichecker/apicheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ func htmlScrapeBitfinex(htmlData *HTMLScrapingData) ([]string, error) {
return resp, nil
}

// htmlScrapeBinance gets checkstring for binance exchange
// htmlScrapeBinance gets checkstring for binance exchange
func htmlScrapeBinance(htmlData *HTMLScrapingData) ([]string, error) {
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/documentation/documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ func GetPackageName(name string, capital bool) string {
i = len(newStrings) - 1
}
if capital {
return strings.Replace(strings.Title(newStrings[i]), "_", " ", -1) // nolint // ignore staticcheck strings.Title warning
return strings.Replace(strings.Title(newStrings[i]), "_", " ", -1) //nolint // ignore staticcheck strings.Title warning
}
return newStrings[i]
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/exchange_template/exchange_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func makeExchange(exchangeDirectory string, configTestFile *config.Config, exch

fmt.Printf("Output directory: %s\n", exchangeDirectory)

exch.CapitalName = strings.Title(exch.Name) // nolint:staticcheck // Ignore Title usage warning
exch.CapitalName = strings.Title(exch.Name) //nolint:staticcheck // Ignore Title usage warning
exch.Variable = exch.Name[0:2]
newExchConfig := &config.Exchange{}
newExchConfig.Name = exch.CapitalName
Expand Down
2 changes: 1 addition & 1 deletion cmd/exchange_wrapper_issues/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
}

func jsonifyInterface(params []interface{}) json.RawMessage {
response, _ := json.MarshalIndent(params, "", " ") // nolint:errchkjson // TODO: ignore this for now
response, _ := json.MarshalIndent(params, "", " ") //nolint:errchkjson // TODO: ignore this for now
return response
}

Expand Down
6 changes: 4 additions & 2 deletions cmd/websocket_client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"errors"
"fmt"
"log"
"net"
"net/http"
"strconv"

"github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
Expand Down Expand Up @@ -83,8 +85,8 @@ func main() {
}

listenAddr := cfg.RemoteControl.WebsocketRPC.ListenAddress
wsHost := fmt.Sprintf("ws://%s:%d/ws", common.ExtractHost(listenAddr),
common.ExtractPort(listenAddr))
wsHost := fmt.Sprintf("ws://%s/ws", net.JoinHostPort(common.ExtractHost(listenAddr),
strconv.Itoa(common.ExtractPort(listenAddr))))
log.Printf("Connecting to websocket host: %s", wsHost)

var dialer websocket.Dialer
Expand Down
Loading

0 comments on commit 6858856

Please sign in to comment.