CI: Fix golangci-lint linter issues, add prealloc linter and bump version depends for Go 1.18 (#915)

* Bump CI versions

* Specifically set go version as 1.17.x bumps it to 1.18

* Another

* Adjust AppVeyor

* Part 1 of linter issues

* Part 2

* Fix various linters and improvements

* Part 3

* Finishing touches

* Tests and EqualFold

* Fix nitterinos plus bonus requester jobs bump for exchanges with large number of tests

* Fix nitterinos and bump golangci-lint timeout for AppVeyor

* Address nits, ensure all books are returned on err due to syncer regression

* Fix the wiggins

* Fix duplication

* Fix nitterinos
This commit is contained in:
Adrian Gallagher
2022-04-20 13:45:15 +10:00
committed by GitHub
parent c48e5ea90a
commit 9a4eb9de84
216 changed files with 3493 additions and 2424 deletions

View File

@@ -6,7 +6,7 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
@@ -18,6 +18,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
gctfile "github.com/thrasher-corp/gocryptotrader/common/file"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/log"
@@ -304,9 +305,9 @@ func checkExistingExchanges(exchName string) bool {
// checkMissingExchanges checks if any supported exchanges are missing api checker functionality
func checkMissingExchanges() []string {
var tempArray []string
tempArray := make([]string, len(usageData.Exchanges))
for x := range usageData.Exchanges {
tempArray = append(tempArray, usageData.Exchanges[x].Name)
tempArray[x] = usageData.Exchanges[x].Name
}
supportedExchs := exchange.Exchanges
for z := 0; z < len(supportedExchs); {
@@ -322,7 +323,7 @@ func checkMissingExchanges() []string {
// readFileData reads the file data from the given json file
func readFileData(fileName string) (Config, error) {
var c Config
data, err := ioutil.ReadFile(fileName)
data, err := os.ReadFile(fileName)
if err != nil {
return c, err
}
@@ -448,7 +449,7 @@ func checkUpdates(fileName string) error {
unsup := checkMissingExchanges()
log.Warnf(log.Global, "The following exchanges are not supported by apichecker: %v\n", unsup)
log.Debugf(log.Global, "Saving the updates to the following file: %s\n", fileName)
return ioutil.WriteFile(fileName, file, 0770)
return os.WriteFile(fileName, file, gctfile.DefaultPermissionOctal)
}
// checkChangeLog checks the exchanges which support changelog updates.json
@@ -559,9 +560,9 @@ func addExch(exchName, checkType string, data interface{}, isUpdate bool) error
return err
}
}
return ioutil.WriteFile(jsonFile, file, 0770)
return os.WriteFile(jsonFile, file, gctfile.DefaultPermissionOctal)
}
return ioutil.WriteFile(testJSONFile, file, 0770)
return os.WriteFile(testJSONFile, file, gctfile.DefaultPermissionOctal)
}
// fillData fills exchange data based on the given checkType
@@ -749,7 +750,7 @@ func htmlScrapeHitBTC(htmlData *HTMLScrapingData) ([]string, error) {
}
defer temp.Body.Close()
a, err := ioutil.ReadAll(temp.Body)
a, err := io.ReadAll(temp.Body)
if err != nil {
return nil, err
}
@@ -784,7 +785,7 @@ func htmlScrapeBTCMarkets(htmlData *HTMLScrapingData) ([]string, error) {
return nil, err
}
defer temp.Body.Close()
tempData, err := ioutil.ReadAll(temp.Body)
tempData, err := io.ReadAll(temp.Body)
if err != nil {
return resp, err
}
@@ -862,7 +863,7 @@ func htmlScrapeANX(htmlData *HTMLScrapingData) ([]string, error) {
}
defer temp.Body.Close()
a, err := ioutil.ReadAll(temp.Body)
a, err := io.ReadAll(temp.Body)
if err != nil {
return nil, err
}
@@ -901,7 +902,7 @@ func htmlScrapeExmo(htmlData *HTMLScrapingData) ([]string, error) {
}
defer httpResp.Body.Close()
a, err := ioutil.ReadAll(httpResp.Body)
a, err := io.ReadAll(httpResp.Body)
if err != nil {
return nil, err
}
@@ -1010,7 +1011,7 @@ func htmlScrapeBitstamp(htmlData *HTMLScrapingData) ([]string, error) {
}
defer temp.Body.Close()
a, err := ioutil.ReadAll(temp.Body)
a, err := io.ReadAll(temp.Body)
if err != nil {
return nil, err
}
@@ -1145,7 +1146,7 @@ func htmlScrapeLocalBitcoins(htmlData *HTMLScrapingData) ([]string, error) {
}
defer temp.Body.Close()
a, err := ioutil.ReadAll(temp.Body)
a, err := io.ReadAll(temp.Body)
if err != nil {
return nil, err
}
@@ -1284,7 +1285,7 @@ func updateFile(name string) error {
if err != nil {
return err
}
return ioutil.WriteFile(name, file, 0770)
return os.WriteFile(name, file, gctfile.DefaultPermissionOctal)
}
// SendGetReq sends get req
@@ -1690,7 +1691,7 @@ func htmlScrapeBitfinex(htmlData *HTMLScrapingData) ([]string, error) {
}
defer temp.Body.Close()
a, err := ioutil.ReadAll(temp.Body)
a, err := io.ReadAll(temp.Body)
if err != nil {
return nil, err
}
@@ -1775,7 +1776,7 @@ func sendHTTPGetRequest(path string, headers map[string]string) (*http.Response,
req, err := http.NewRequestWithContext(context.TODO(),
http.MethodGet,
path,
nil)
http.NoBody)
if err != nil {
return nil, err
}

View File

@@ -2,12 +2,12 @@ package main
import (
"encoding/json"
"io/ioutil"
"os"
"reflect"
"testing"
"github.com/thrasher-corp/gocryptotrader/common/convert"
gctfile "github.com/thrasher-corp/gocryptotrader/common/file"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/log"
)
@@ -86,7 +86,7 @@ func removeTestFileVars() error {
if err != nil {
return err
}
return ioutil.WriteFile(testJSONFile, file, 0770)
return os.WriteFile(testJSONFile, file, gctfile.DefaultPermissionOctal)
}
func canTestTrello() bool {
@@ -439,8 +439,7 @@ func TestUpdate(t *testing.T) {
func TestCheckMissingExchanges(t *testing.T) {
t.Parallel()
a := checkMissingExchanges()
if len(a) > len(exchange.Exchanges) {
if a := checkMissingExchanges(); len(a) > len(exchange.Exchanges) {
t.Fatal("invalid response")
}
}

View File

@@ -3,8 +3,8 @@ package main
import (
"encoding/json"
"flag"
"io/ioutil"
"log"
"os"
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/config"
@@ -38,7 +38,7 @@ func main() {
key = string(result)
}
fileData, err := ioutil.ReadFile(inFile)
fileData, err := os.ReadFile(inFile)
if err != nil {
log.Fatalf("Unable to read input file %s. Error: %s.", inFile, err)
}

View File

@@ -30,8 +30,8 @@ func main() {
wg.Wait()
log.Println("Done.")
var cfgs []config.Exchange
exchanges := engine.Bot.GetExchanges()
cfgs := make([]config.Exchange, 0, len(exchanges))
for x := range exchanges {
var cfg *config.Exchange
cfg, err = exchanges[x].GetDefaultConfig()

View File

@@ -51,11 +51,11 @@ func seedExchangeFromDefaultList(c *cli.Context) error {
if err != nil {
return err
}
var allExchanges []exchangeDB.Details
allExchanges := make([]exchangeDB.Details, len(exchange.Exchanges))
for x := range exchange.Exchanges {
allExchanges = append(allExchanges, exchangeDB.Details{
allExchanges[x] = exchangeDB.Details{
Name: exchange.Exchanges[x],
})
}
}
err = exchangeDB.InsertMany(allExchanges)
if err != nil {

View File

@@ -4,7 +4,6 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/core"
@@ -44,7 +43,7 @@ func main() {
workingDir, err = os.Getwd()
if err != nil {
log.Println("error getting current working path")
workingDir = filepath.Join(".")
workingDir = "."
}
fmt.Println("GoCryptoTrader database seeding tool")

View File

@@ -7,7 +7,6 @@ import (
"flag"
"fmt"
"html/template"
"io/ioutil"
"log"
"net/http"
"os"
@@ -329,7 +328,7 @@ func GetConfiguration() (Config, error) {
configFilePath := filepath.Join(toolDir, "config.json")
if file.Exists(configFilePath) {
config, err := ioutil.ReadFile(configFilePath)
config, err := os.ReadFile(configFilePath)
if err != nil {
return c, err
}
@@ -360,7 +359,7 @@ func GetConfiguration() (Config, error) {
return c, err
}
if err := ioutil.WriteFile(configFilePath, data, 0770); err != nil {
if err := os.WriteFile(configFilePath, data, file.DefaultPermissionOctal); err != nil {
return c, err
}
@@ -485,7 +484,7 @@ func GetPackageName(name string, capital bool) string {
i = len(newStrings) - 1
}
if capital {
return strings.Replace(strings.Title(newStrings[i]), "_", " ", -1)
return strings.Replace(strings.Title(newStrings[i]), "_", " ", -1) // nolint // ignore staticcheck strings.Title warning
}
return newStrings[i]
}
@@ -540,7 +539,7 @@ func UpdateDocumentation(details DocumentationDetails) {
continue
}
if name == engineFolder {
d, err := ioutil.ReadDir(details.Directories[i])
d, err := os.ReadDir(details.Directories[i])
if err != nil {
fmt.Println("Excluding file:", err)
}

View File

@@ -12,6 +12,7 @@ import (
"strings"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/core"
"github.com/thrasher-corp/gocryptotrader/currency"
@@ -138,14 +139,14 @@ func makeExchange(exchangeDirectory string, configTestFile *config.Config, exch
if !os.IsNotExist(err) {
return nil, errors.New("directory already exists")
}
err = os.MkdirAll(exchangeDirectory, 0770)
err = os.MkdirAll(exchangeDirectory, file.DefaultPermissionOctal)
if err != nil {
return nil, err
}
fmt.Printf("Output directory: %s\n", exchangeDirectory)
exch.CapitalName = strings.Title(exch.Name)
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
@@ -214,7 +215,7 @@ func makeExchange(exchangeDirectory string, configTestFile *config.Config, exch
outputFile := filepath.Join(exchangeDirectory, filename)
newFile(outputFile)
var f *os.File
f, err = os.OpenFile(outputFile, os.O_WRONLY, 0770)
f, err = os.OpenFile(outputFile, os.O_WRONLY, file.DefaultPermissionOctal)
if err != nil {
return nil, err
}

View File

@@ -334,18 +334,20 @@ func ({{.Variable}} *{{.CapitalName}}) UpdateOrderbook(ctx context.Context, pair
return book, err
}
book.Bids = make([]orderbook.Item, len(orderbookNew.Bids))
for x := range orderbookNew.Bids {
book.Bids = append(book.Bids, orderbook.Item{
book.Bids[x] = orderbook.Item{
Amount: orderbookNew.Bids[x].Quantity,
Price: orderbookNew.Bids[x].Price,
})
}
}
book.Asks = make([]orderbook.Item, len(orderbookNew.Asks))
for x := range orderbookNew.Asks {
book.Asks = append(book.Asks, orderbook.Item{
book.Asks[x] = orderbook.Item{
Amount: orderBookNew.Asks[x].Quantity,
Price: orderBookNew.Asks[x].Price,
})
}
}
*/

View File

@@ -6,7 +6,6 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
@@ -283,7 +282,7 @@ func parseOrderType(orderType string) order.Type {
}
func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config) []ExchangeAssetPairResponses {
var response []ExchangeAssetPairResponses
response := make([]ExchangeAssetPairResponses, 0)
testOrderSide := parseOrderSide(config.OrderSubmission.OrderSide)
testOrderType := parseOrderType(config.OrderSubmission.OrderType)
assetTypes := base.GetAssetTypes(false)
@@ -835,13 +834,13 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
}
func jsonifyInterface(params []interface{}) json.RawMessage {
response, _ := json.MarshalIndent(params, "", " ")
response, _ := json.MarshalIndent(params, "", " ") // nolint:errchkjson // TODO: ignore this for now
return response
}
func loadConfig() (Config, error) {
var config Config
keys, err := ioutil.ReadFile("wrapperconfig.json")
keys, err := os.ReadFile("wrapperconfig.json")
if err != nil {
return config, err
}

View File

@@ -3,7 +3,7 @@ package main
import (
"errors"
"fmt"
"io/ioutil"
"io"
"math"
"os"
"path/filepath"
@@ -4226,7 +4226,7 @@ func gctScriptUpload(c *cli.Context) error {
defer closeConn(conn, cancel)
client := gctrpc.NewGoCryptoTraderClient(conn)
data, err := ioutil.ReadAll(file)
data, err := io.ReadAll(file)
if err != nil {
return err
}

View File

@@ -198,7 +198,7 @@ func enableDisableExchangePair(c *cli.Context) error {
pairList := strings.Split(pairs, ",")
var validPairs []*gctrpc.CurrencyPair
validPairs := make([]*gctrpc.CurrencyPair, len(pairList))
for i := range pairList {
if !validPair(pairList[i]) {
return errInvalidPair
@@ -209,11 +209,11 @@ func enableDisableExchangePair(c *cli.Context) error {
return err
}
validPairs = append(validPairs, &gctrpc.CurrencyPair{
validPairs[i] = &gctrpc.CurrencyPair{
Delimiter: p.Delimiter,
Base: p.Base.String(),
Quote: p.Quote.String(),
})
}
}
conn, cancel, err := setupClient(c)

View File

@@ -4,10 +4,10 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/core"
"github.com/thrasher-corp/gocryptotrader/database"
@@ -57,7 +57,7 @@ func main() {
}
path := filepath.Join(outputFolder, "sqlboiler.json")
err = ioutil.WriteFile(path, jsonOutput, 0770)
err = os.WriteFile(path, jsonOutput, file.DefaultPermissionOctal)
if err != nil {
fmt.Printf("Write failed: %v", err)
os.Exit(1)