Skip to content

Commit

Permalink
Bump golangci-lint, Docker and Go CI versions (thrasher-corp#564)
Browse files Browse the repository at this point in the history
* Bump golangci-lint and Go CI versions

* Bump golangci-lint version

* Address nitterinos
  • Loading branch information
thrasher- authored Sep 23, 2020
1 parent 991dfed commit d9bcf82
Show file tree
Hide file tree
Showing 24 changed files with 96 additions and 70 deletions.
4 changes: 2 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ environment:
PSQL_SSLMODE: disable
PSQL_SKIPSQLCMD: true
PSQL_TESTDBNAME: gct_dev_ci
stack: go 1.14.x
stack: go 1.15.x

services:
- postgresql96
Expand All @@ -49,7 +49,7 @@ before_test:

test_script:
# test back-end
- go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.24.0
- go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.31.0
- '%GOPATH%\bin\golangci-lint.exe run --verbose'
- ps: >-
if($env:APPVEYOR_SCHEDULED_BUILD -eq 'true') {
Expand Down
18 changes: 15 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,48 @@ linters:
# - varcheck

# disabled by default linters
- asciicheck
- bodyclose
- depguard
- dogsled
# - dupl
# - exhaustive
- exportloopref
# - funlen
- gci
# - gochecknoglobals
# - gochecknoinits
# - gocognit
- goconst
- gocritic
# - gocyclo
# - godot
# - godox
# - goerr113
- gofmt
# - gofumpt
- goheader
- goimports
- golint
# - gomnd
- gomodguard
- goprintffuncname
- gosec
# - interfacer
# - lll
# - maligned
- misspell
- nakedret
# - nestif
# - nlreturn
# - noctx
- nolintlint
# - prealloc
- rowserrcheck
- scopelint
- sqlclosecheck
- stylecheck
# - testpackage
- unconvert
- unparam
- whitespace
Expand Down Expand Up @@ -82,9 +97,6 @@ issues:
max-same-issues: 0

exclude-rules:
- text: "weak cryptographic primitive"
linters:
- gosec
- text: "Expect WriteFile permissions to be 0600 or less"
linters:
- gosec
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.14.x
- 1.15.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.14.x
- 1.15.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.14.x
- 1.15.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.14 as build
FROM golang:1.15 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.24.0
LINTPKG = github.com/golangci/golangci-lint/cmd/golangci-lint@v1.31.0
LINTBIN = $(GOPATH)/bin/golangci-lint
GCTLISTENPORT=9050
GCTPROFILERLISTENPORT=8085
Expand Down
2 changes: 1 addition & 1 deletion cmd/exchange_wrapper_coverage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func testWrappers(e exchange.IBotExchange) []string {
if !e.SupportsAsset(assetType) {
assets := e.GetAssetTypes()
rand.Seed(time.Now().Unix())
assetType = assets[rand.Intn(len(assets))]
assetType = assets[rand.Intn(len(assets))] // nolint:gosec // basic number generation required, no need for crypo/rand
}

var funcs []string
Expand Down
9 changes: 5 additions & 4 deletions common/crypto/crypto.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package crypto

// nolint:gosec // md5/sha1 hash functions used by some exchanges
import (
"crypto/hmac"
"crypto/md5" // nolint // Used by some exchanges
"crypto/md5"
"crypto/rand"
"crypto/sha1" // nolint // Used by some exchanges
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"encoding/base64"
Expand Down Expand Up @@ -62,7 +63,7 @@ func GetRandomSalt(input []byte, saltLen int) ([]byte, error) {

// GetMD5 returns a MD5 hash of a byte array
func GetMD5(input []byte) []byte {
m := md5.New() // nolint // Used by some exchanges
m := md5.New() // nolint:gosec // hash function used by some exchanges
m.Write(input)
return m.Sum(nil)
}
Expand Down Expand Up @@ -107,7 +108,7 @@ func GetHMAC(hashType int, input, key []byte) []byte {
// Sha1ToHex takes a string, sha1 hashes it and return a hex string of the
// result
func Sha1ToHex(data string) string {
h := sha1.New() // nolint // Used by some exchanges
h := sha1.New() // nolint:gosec // hash function used by some exchanges
h.Write([]byte(data))
return hex.EncodeToString(h.Sum(nil))
}
12 changes: 8 additions & 4 deletions currency/coinmarketcap/coinmarketcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,25 @@ func (c *Coinmarketcap) GetCryptocurrencyHistoricalListings() ([]CryptocurrencyH
// Status Status `json:"status"`
// }{}

// nolint: gocritic err := c.CheckAccountPlan(0)
// nolint:gocritic // unused code, used as example
// err := c.CheckAccountPlan(0)
// if err != nil {
// return resp.Data, err
// }

// nolint: gocritic err = c.SendHTTPRequest(http.MethodGet, endpointCryptocurrencyHistoricalListings, nil, &resp)
// nolint:gocritic // unused code, used as example
// err = c.SendHTTPRequest(http.MethodGet, endpointCryptocurrencyHistoricalListings, nil, &resp)
// if err != nil {
// return resp.Data, err
// }

// nolint: gocritic nolint:gocritic if resp.Status.ErrorCode != 0 {
// nolint:gocritic // unused code, used as example
// if resp.Status.ErrorCode != 0 {
// return resp.Data, errors.New(resp.Status.ErrorMessage)
// }

// nolint: gocritic nolint:gocritic return resp.Data, nil
// nolint:gocritic // unused code, used as example
// return resp.Data, nil
}

// GetCryptocurrencyLatestListing returns a paginated list of all
Expand Down
2 changes: 1 addition & 1 deletion currency/pairs.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,5 @@ func (p Pairs) GetRandomPair() Pair {
return Pair{Base: NewCode(""), Quote: NewCode("")}
}

return p[rand.Intn(pairsLen)]
return p[rand.Intn(pairsLen)] // nolint:gosec // basic number generation required, no need for crypo/rand
}
2 changes: 1 addition & 1 deletion database/repository/withdraw/withdraw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func seedWithdrawData() {
Amount: 1.0,
},
}
rnd := rand.Intn(2)
rnd := rand.Intn(2) // nolint:gosec // used for generating test data, no need to import crypo/rand
if rnd == 0 {
resp.RequestDetails.Currency = currency.AUD
resp.RequestDetails.Type = 1
Expand Down
3 changes: 2 additions & 1 deletion exchanges/bitflyer/bitflyer.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ func (b *Bitflyer) SendHTTPRequest(path string, result interface{}) error {
// if you have access and update the authenticated requests
// TODO: Fill out this function once API access is obtained
func (b *Bitflyer) SendAuthHTTPRequest() {
// nolint: gocritic headers := make(map[string]string)
// nolint:gocritic // code example
// headers := make(map[string]string)
// headers["ACCESS-KEY"] = b.API.Credentials.Key
// headers["ACCESS-TIMESTAMP"] = strconv.FormatInt(time.Now().UnixNano(), 10)
}
Expand Down
17 changes: 11 additions & 6 deletions exchanges/bithumb/bithumb.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,18 @@ func (b *Bithumb) GetTransactionHistory(symbol string) (TransactionHistory, erro
return response, nil
}

// GetAccountInformation returns account information by singular currency
func (b *Bithumb) GetAccountInformation(currency string) (Account, error) {
response := Account{}
// GetAccountInformation returns account information based on the desired
// order/payment currencies
func (b *Bithumb) GetAccountInformation(orderCurrency, paymentCurrency string) (Account, error) {
var response Account
if orderCurrency == "" {
return response, errors.New("order currency must be set")
}

val := url.Values{}
if currency != "" {
val.Set("currency", currency)
val.Add("order_currency", orderCurrency)
if paymentCurrency != "" { // optional param, default is KRW
val.Add("payment_currency", paymentCurrency)
}

return response,
Expand Down Expand Up @@ -477,7 +482,7 @@ func (b *Bithumb) SendAuthenticatedHTTPRequest(path string, params url.Values, r

params.Set("endpoint", path)
payload := params.Encode()
hmacPayload := path + string(0) + payload + string(0) + n
hmacPayload := path + string('\x00') + payload + string('\x00') + n
hmac := crypto.GetHMAC(crypto.HashSHA512,
[]byte(hmacPayload),
[]byte(b.API.Credentials.Secret))
Expand Down
19 changes: 19 additions & 0 deletions exchanges/bithumb/bithumb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ func TestGetTransactionHistory(t *testing.T) {
}
}

func TestGetAccountInformation(t *testing.T) {
t.Parallel()

// Offline test
_, err := b.GetAccountInformation("", "")
if err == nil {
t.Error("expected error when no order currency is specified")
}

if !areTestAPIKeysSet() {
t.Skip()
}

_, err = b.GetAccountInformation(testCurrency, currency.KRW.String())
if err != nil {
t.Error(err)
}
}

func TestGetAccountBalance(t *testing.T) {
t.Parallel()
if !areTestAPIKeysSet() {
Expand Down
2 changes: 1 addition & 1 deletion exchanges/coinbasepro/coinbasepro_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ type OrderbookResponse struct {

// FillResponse contains fill information from the exchange
type FillResponse struct {
TradeID int `json:"trade_id"`
TradeID int64 `json:"trade_id"`
ProductID string `json:"product_id"`
Price float64 `json:"price,string"`
Size float64 `json:"size,string"`
Expand Down
2 changes: 1 addition & 1 deletion exchanges/coinbasepro/coinbasepro_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ func (c *CoinbasePro) GetOrderInfo(orderID string) (order.Detail, error) {
}
response.Trades = append(response.Trades, order.TradeHistory{
Timestamp: fillResponse[i].CreatedAt,
TID: string(fillResponse[i].TradeID),
TID: strconv.FormatInt(fillResponse[i].TradeID, 10),
Price: fillResponse[i].Price,
Amount: fillResponse[i].Size,
Exchange: c.GetName(),
Expand Down
2 changes: 1 addition & 1 deletion exchanges/coinut/coinut.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,5 +494,5 @@ func (i *instrumentMap) GetInstrumentIDs() []int64 {
}

func getNonce() int64 {
return rand.Int63n(coinutMaxNonce-1) + 1
return rand.Int63n(coinutMaxNonce-1) + 1 // nolint:gosec // basic number generation required, no need for crypo/rand
}
10 changes: 5 additions & 5 deletions exchanges/kline/kline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ func TestCreateKline(t *testing.T) {
rand.Seed(time.Now().Unix())
for i := 0; i < 24000; i++ {
trades = append(trades, order.TradeHistory{
Timestamp: time.Now().Add((time.Duration(rand.Intn(10)) * time.Minute) +
(time.Duration(rand.Intn(10)) * time.Second)),
Timestamp: time.Now().Add((time.Duration(rand.Intn(10)) * time.Minute) + // nolint:gosec // no need to import crypo/rand for testing
(time.Duration(rand.Intn(10)) * time.Second)), // nolint:gosec // no need to import crypo/rand for testing
TID: crypto.HexEncodeToString([]byte(string(rune(i)))),
Amount: float64(rand.Intn(20)) + 1,
Price: 1000 + float64(rand.Intn(1000)),
Amount: float64(rand.Intn(20)) + 1, // nolint:gosec // no need to import crypo/rand for testing
Price: 1000 + float64(rand.Intn(1000)), // nolint:gosec // no need to import crypo/rand for testing
})
}

Expand Down Expand Up @@ -422,7 +422,7 @@ func TestItem_SortCandlesByTimestamp(t *testing.T) {
}

for x := 0; x < 100; x++ {
y := rand.Float64() // nolint gosec: used for generating test data no need to import crypo/rand
y := rand.Float64() // nolint:gosec // used for generating test data, no need to import crypo/rand
tempKline.Candles = append(tempKline.Candles,
Candle{
Time: time.Now().AddDate(0, 0, -x),
Expand Down
8 changes: 4 additions & 4 deletions exchanges/orderbook/orderbook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,12 @@ func TestProcessOrderbook(t *testing.T) {

wg.Add(1)
go func() {
newName := "Exchange" + strconv.FormatInt(rand.Int63(), 10)
newName := "Exchange" + strconv.FormatInt(rand.Int63(), 10) // nolint:gosec // no need to import crypo/rand for testing
newPairs := currency.NewPair(currency.NewCode("BTC"+strconv.FormatInt(rand.Int63(), 10)),
currency.NewCode("USD"+strconv.FormatInt(rand.Int63(), 10)))
currency.NewCode("USD"+strconv.FormatInt(rand.Int63(), 10))) // nolint:gosec // no need to import crypo/rand for testing

asks := []Item{{Price: rand.Float64(), Amount: rand.Float64()}}
bids := []Item{{Price: rand.Float64(), Amount: rand.Float64()}}
asks := []Item{{Price: rand.Float64(), Amount: rand.Float64()}} // nolint:gosec // no need to import crypo/rand for testing
bids := []Item{{Price: rand.Float64(), Amount: rand.Float64()}} // nolint:gosec // no need to import crypo/rand for testing
base := &Base{
Pair: newPairs,
Asks: asks,
Expand Down
12 changes: 6 additions & 6 deletions exchanges/stream/buffer/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ func bidAskGenerator() []orderbook.Item {
var response []orderbook.Item
randIterator := 100
for i := 0; i < randIterator; i++ {
price := float64(rand.Intn(1000))
price := float64(rand.Intn(1000)) // nolint:gosec // no need to import crypo/rand for testing
if price == 0 {
price = 1
}
response = append(response, orderbook.Item{
Amount: float64(rand.Intn(10)),
Amount: float64(rand.Intn(10)), // nolint:gosec // no need to import crypo/rand for testing
Price: price,
ID: int64(i),
})
Expand Down Expand Up @@ -124,7 +124,7 @@ func BenchmarkBufferPerformance(b *testing.B) {
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
randomIndex := rand.Intn(4)
randomIndex := rand.Intn(4) // nolint:gosec // no need to import crypo/rand for testing
update.Asks = itemArray[randomIndex]
update.Bids = itemArray[randomIndex]
err = obl.Update(update)
Expand Down Expand Up @@ -159,7 +159,7 @@ func BenchmarkBufferSortingPerformance(b *testing.B) {
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
randomIndex := rand.Intn(4)
randomIndex := rand.Intn(4) // nolint:gosec // no need to import crypo/rand for testing
update.Asks = itemArray[randomIndex]
update.Bids = itemArray[randomIndex]
err = obl.Update(update)
Expand Down Expand Up @@ -195,7 +195,7 @@ func BenchmarkBufferSortingByIDPerformance(b *testing.B) {
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
randomIndex := rand.Intn(4)
randomIndex := rand.Intn(4) // nolint:gosec // no need to import crypo/rand for testing
update.Asks = itemArray[randomIndex]
update.Bids = itemArray[randomIndex]
err = obl.Update(update)
Expand Down Expand Up @@ -229,7 +229,7 @@ func BenchmarkNoBufferPerformance(b *testing.B) {
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
randomIndex := rand.Intn(4)
randomIndex := rand.Intn(4) // nolint:gosec // no need to import crypo/rand for testing
update.Asks = itemArray[randomIndex]
update.Bids = itemArray[randomIndex]
err = obl.Update(update)
Expand Down
Loading

0 comments on commit d9bcf82

Please sign in to comment.