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

@@ -2,7 +2,7 @@ package gct
// AllModuleNames returns a list of all default module names.
func AllModuleNames() []string {
var names []string
names := make([]string, 0, len(Modules))
for name := range Modules {
names = append(names, name)
}

View File

@@ -46,7 +46,7 @@ func ema(args ...objects.Object) (objects.Object, error) {
return nil, fmt.Errorf(modules.ErrParameterConvertFailed, OHLCV)
}
var ohlcvClose []float64
ohlcvClose := make([]float64, len(ohlcvInputData))
var allErrors []string
for x := range ohlcvInputData {
t, ok := ohlcvInputData[x].([]interface{})
@@ -61,7 +61,7 @@ func ema(args ...objects.Object) (objects.Object, error) {
if err != nil {
allErrors = append(allErrors, err.Error())
}
ohlcvClose = append(ohlcvClose, value)
ohlcvClose[x] = value
}
inTimePeriod, ok := objects.ToInt(args[1])

View File

@@ -47,7 +47,7 @@ func macd(args ...objects.Object) (objects.Object, error) {
return nil, fmt.Errorf(modules.ErrParameterConvertFailed, OHLCV)
}
var ohlcvClose []float64
ohlcvClose := make([]float64, len(ohlcvInputData))
var allErrors []string
for x := range ohlcvInputData {
t, ok := ohlcvInputData[x].([]interface{})
@@ -61,7 +61,7 @@ func macd(args ...objects.Object) (objects.Object, error) {
if err != nil {
allErrors = append(allErrors, err.Error())
}
ohlcvClose = append(ohlcvClose, value)
ohlcvClose[x] = value
}
inFastPeriod, ok := objects.ToInt(args[1])

View File

@@ -46,7 +46,7 @@ func rsi(args ...objects.Object) (objects.Object, error) {
return nil, fmt.Errorf(modules.ErrParameterConvertFailed, OHLCV)
}
var ohlcvClose []float64
ohlcvClose := make([]float64, len(ohlcvInputData))
var allErrors []string
for x := range ohlcvInputData {
t, ok := ohlcvInputData[x].([]interface{})
@@ -61,7 +61,7 @@ func rsi(args ...objects.Object) (objects.Object, error) {
if err != nil {
allErrors = append(allErrors, err.Error())
}
ohlcvClose = append(ohlcvClose, value)
ohlcvClose[x] = value
}
inTimePeriod, ok := objects.ToInt(args[1])

View File

@@ -46,7 +46,7 @@ func sma(args ...objects.Object) (objects.Object, error) {
return nil, fmt.Errorf(modules.ErrParameterConvertFailed, OHLCV)
}
var ohlcvClose []float64
ohlcvClose := make([]float64, len(ohlcvInputData))
var allErrors []string
for x := range ohlcvInputData {
t, ok := ohlcvInputData[x].([]interface{})
@@ -60,7 +60,7 @@ func sma(args ...objects.Object) (objects.Object, error) {
if err != nil {
allErrors = append(allErrors, err.Error())
}
ohlcvClose = append(ohlcvClose, value)
ohlcvClose[x] = value
}
inTimePeriod, ok := objects.ToInt(args[1])

View File

@@ -2,9 +2,9 @@ package ta
// AllModuleNames returns a list of all default module names.
func AllModuleNames() []string {
var names []string
for name := range Modules {
names = append(names, name)
names := make([]string, 0, len(Modules))
for x := range Modules {
names = append(names, x)
}
return names
}

View File

@@ -1,6 +1,7 @@
package vm
import (
"errors"
"fmt"
"github.com/gofrs/uuid"
@@ -50,17 +51,21 @@ func (g *GctScriptManager) ShutdownAll() (err error) {
log.Debugln(log.GCTScriptMgr, "Shutting down all Virtual Machines")
}
var errors []error
var shutdownErrors []error
AllVMSync.Range(func(k, v interface{}) bool {
errShutdown := v.(*VM).Shutdown()
vm, ok := v.(*VM)
if !ok {
shutdownErrors = append(shutdownErrors, errors.New("unable to type assert VM"))
}
errShutdown := vm.Shutdown()
if err != nil {
errors = append(errors, errShutdown)
shutdownErrors = append(shutdownErrors, errShutdown)
}
return true
})
if len(errors) > 0 {
err = fmt.Errorf("failed to shutdown the following Virtual Machines: %v", errors)
if len(shutdownErrors) > 0 {
err = fmt.Errorf("failed to shutdown the following Virtual Machines: %v", shutdownErrors)
}
return err

View File

@@ -5,7 +5,8 @@ import (
"bytes"
"context"
"encoding/hex"
"io/ioutil"
"errors"
"os"
"path/filepath"
"sync/atomic"
"time"
@@ -22,7 +23,7 @@ import (
)
// NewVM attempts to create a new Virtual Machine firstly from pool
func (g *GctScriptManager) NewVM() (vm *VM) {
func (g *GctScriptManager) NewVM() *VM {
if !g.IsRunning() {
log.Error(log.GCTScriptMgr, Error{
Action: "NewVM",
@@ -43,13 +44,21 @@ func (g *GctScriptManager) NewVM() (vm *VM) {
log.Debugln(log.GCTScriptMgr, "New GCTScript VM created")
}
vm = &VM{
s, ok := pool.Get().(*tengo.Script)
if !ok {
log.Error(log.GCTScriptMgr, Error{
Action: "NewVM",
Cause: errors.New("unable to type assert tengo script"),
})
return nil
}
return &VM{
ID: newUUID,
Script: pool.Get().(*tengo.Script),
Script: s,
config: g.config,
unregister: func() error { return g.RemoveVM(newUUID) },
}
return
}
// SetDefaultScriptOutput sets default output file for scripts
@@ -71,7 +80,7 @@ func (vm *VM) Load(file string) error {
log.Debugf(log.GCTScriptMgr, "Loading script: %s ID: %v", vm.ShortName(), vm.ID)
}
code, err := ioutil.ReadFile(file)
code, err := os.ReadFile(file)
if err != nil {
return &Error{
Action: "Load: ReadFile",
@@ -213,7 +222,7 @@ func (vm *VM) read() ([]byte, error) {
if vm.config.Verbose {
log.Debugf(log.GCTScriptMgr, "Read script: %s ID: %v", vm.ShortName(), vm.ID)
}
return ioutil.ReadFile(vm.File)
return os.ReadFile(vm.File)
}
// ShortName returns short (just filename.extension) of running script