CI/build: Update Go version, linters and fix minor issues (#1612)

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

* linters: Add intrange, copyloopvar, additional go vet linters to match gopls and fix issues
This commit is contained in:
Adrian Gallagher
2024-08-16 17:41:11 +10:00
committed by GitHub
parent facf291069
commit 225429bda6
111 changed files with 239 additions and 379 deletions

View File

@@ -591,7 +591,7 @@ func (c *websocketClient) write() {
// Add queued chat messages to the current websocket message
n := len(c.Send)
for i := 0; i < n; i++ {
for range n {
_, err = w.Write(<-c.Send)
if err != nil {
log.Errorln(log.APIServerMgr, err)

View File

@@ -958,7 +958,7 @@ func (m *DataHistoryManager) validateCandles(job *DataHistoryJob, exch exchange.
}
var validationIssues []string
multiplier := int64(1)
for i := int64(0); i < job.DecimalPlaceComparison; i++ {
for range job.DecimalPlaceComparison {
multiplier *= 10
}
for i := range apiCandles.Candles {

View File

@@ -1410,7 +1410,7 @@ func TestSaveCandlesInBatches(t *testing.T) {
t.Errorf("received %v expected %v", err, nil)
}
for i := 0; i < 10000; i++ {
for i := range 10000 {
candles.Candles = append(candles.Candles, kline.Candle{
Volume: float64(i),
})
@@ -1524,17 +1524,17 @@ func dataHistoryTraderLoader(exch, a, base, quote string, start, _ time.Time) ([
func dataHistoryCandleLoader(exch string, cp currency.Pair, a asset.Item, interval kline.Interval, start, end time.Time) (*kline.Item, error) {
start = start.Truncate(interval.Duration())
end = end.Truncate(interval.Duration())
var candles []kline.Candle
intervals := end.Sub(start) / interval.Duration()
for i := 0; i < int(intervals); i++ {
candles = append(candles, kline.Candle{
candles := make([]kline.Candle, int(intervals))
for x := range int(intervals) {
candles[x] = kline.Candle{
Time: start,
Open: 1,
High: 10,
Low: 1,
Close: 4,
Volume: 8,
})
}
start = start.Add(interval.Duration())
}
return &kline.Item{

View File

@@ -272,7 +272,7 @@ func (s *Settings) PrintLoadedSettings() {
gctlog.Debugln(gctlog.Global)
gctlog.Debugf(gctlog.Global, "ENGINE SETTINGS")
settings := reflect.ValueOf(*s)
for x := 0; x < settings.NumField(); x++ {
for x := range settings.NumField() {
field := settings.Field(x)
if field.Kind() != reflect.Struct {
continue
@@ -280,7 +280,7 @@ func (s *Settings) PrintLoadedSettings() {
fieldName := field.Type().Name()
gctlog.Debugln(gctlog.Global, "- "+common.AddPaddingOnUpperCase(fieldName)+":")
for y := 0; y < field.NumField(); y++ {
for y := range field.NumField() {
indvSetting := field.Field(y)
indvName := field.Type().Field(y).Name
if indvSetting.Kind() == reflect.String && indvSetting.IsZero() {

View File

@@ -65,7 +65,6 @@ func TestLoadConfigWithSettings(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
// prepare the 'flags'
flagSet := make(map[string]bool)

View File

@@ -216,7 +216,6 @@ func TestSetSubsystem(t *testing.T) { //nolint // TO-DO: Fix race t.Parallel() u
}
for _, tt := range testCases {
tt := tt
t.Run(tt.Subsystem, func(t *testing.T) {
t.Parallel()
err := tt.Engine.SetSubsystem(tt.Subsystem, true)

View File

@@ -52,7 +52,7 @@ func (m *ntpManager) Start() error {
// Sometimes the NTP client can have transient issues due to UDP, try
// the default retry limits before giving up
check:
for i := 0; i < m.retryLimit; i++ {
for i := range m.retryLimit {
err := m.processTime()
switch err {
case nil:

View File

@@ -1758,7 +1758,7 @@ func (s *RPCServer) WithdrawCryptocurrencyFunds(ctx context.Context, r *gctrpc.W
if exchCfg.API.Credentials.PIN != "" {
pinCode, errPin := strconv.ParseInt(exchCfg.API.Credentials.PIN, 10, 64)
if err != nil {
if errPin != nil {
return nil, errPin
}
req.PIN = pinCode
@@ -1815,12 +1815,12 @@ func (s *RPCServer) WithdrawFiatFunds(ctx context.Context, r *gctrpc.WithdrawFia
if exchCfg.API.Credentials.OTPSecret != "" {
code, errOTP := totp.GenerateCode(exchCfg.API.Credentials.OTPSecret, time.Now())
if err != nil {
if errOTP != nil {
return nil, errOTP
}
codeNum, errOTP := strconv.ParseInt(code, 10, 64)
if err != nil {
if errOTP != nil {
return nil, errOTP
}
req.OneTimePassword = codeNum
@@ -1828,7 +1828,7 @@ func (s *RPCServer) WithdrawFiatFunds(ctx context.Context, r *gctrpc.WithdrawFia
if exchCfg.API.Credentials.PIN != "" {
pinCode, errPIN := strconv.ParseInt(exchCfg.API.Credentials.PIN, 10, 64)
if err != nil {
if errPIN != nil {
return nil, errPIN
}
req.PIN = pinCode
@@ -4938,7 +4938,7 @@ func (s *RPCServer) GetCollateral(ctx context.Context, r *gctrpc.GetCollateralRe
}
tick, err = exch.FetchTicker(ctx, tickerCurr, asset.Spot)
if err != nil {
log.Errorf(log.GRPCSys, fmt.Sprintf("GetCollateral offline calculation error via FetchTicker %s %s", exch.GetName(), err))
log.Errorf(log.GRPCSys, "GetCollateral offline calculation error via FetchTicker %s %s", exch.GetName(), err)
continue
}
if tick.Last == 0 {

View File

@@ -241,7 +241,7 @@ func (f fExchange) GetHistoricCandles(_ context.Context, p currency.Pair, a asse
func generateCandles(amount int, timeStart time.Time, interval kline.Interval) []kline.Candle {
candy := make([]kline.Candle, amount)
for x := 0; x < amount; x++ {
for x := range amount {
candy[x] = kline.Candle{
Time: timeStart,
Open: 1337,
@@ -1630,8 +1630,8 @@ func TestCheckVars(t *testing.T) {
func TestParseEvents(t *testing.T) {
t.Parallel()
var exchangeName = "Binance"
var testData []*withdraw.Response
for x := 0; x < 5; x++ {
testData := make([]*withdraw.Response, 5)
for x := range 5 {
test := fmt.Sprintf("test-%v", x)
resp := &withdraw.Response{
ID: withdraw.DryRunID,
@@ -1668,13 +1668,13 @@ func TestParseEvents(t *testing.T) {
resp.RequestDetails.Crypto.FeeAmount = 0
resp.RequestDetails.Crypto.AddressTag = test
}
testData = append(testData, resp)
testData[x] = resp
}
v := parseMultipleEvents(testData)
if reflect.TypeOf(v).String() != "*gctrpc.WithdrawalEventsByExchangeResponse" {
t.Fatal("expected type to be *gctrpc.WithdrawalEventsByExchangeResponse")
}
if testData == nil || len(testData) < 2 {
if len(testData) < 2 {
t.Fatal("expected at least 2")
}
@@ -4214,7 +4214,6 @@ func TestStartRPCRESTProxy(t *testing.T) {
{"Invalid username but valid password", "bonk", "Sup3rdup3rS3cr3t"},
{"Invalid username and password despite glorious credentials", "bonk", "wif"},
} {
creds := creds
t.Run(creds.testDescription, func(t *testing.T) {
t.Parallel()
@@ -4259,7 +4258,7 @@ func TestRPCProxyAuthClient(t *testing.T) {
dummyHandler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte("MEOW"))
require.NoError(t, err, "Write should not error")
assert.NoError(t, err, "Write should not error")
})
handler := s.authClient(dummyHandler)
@@ -4274,7 +4273,6 @@ func TestRPCProxyAuthClient(t *testing.T) {
{"Invalid username but valid password", "bonk", "Sup3rdup3rS3cr3t"},
{"Invalid username and password despite glorious credentials", "bonk", "wif"},
} {
creds := creds
t.Run(creds.testDescription, func(t *testing.T) {
t.Parallel()

View File

@@ -229,7 +229,7 @@ func (m *SyncManager) Start() error {
return nil
}
for i := 0; i < m.config.NumWorkers; i++ {
for range m.config.NumWorkers {
go m.worker()
}
m.initSyncWG.Done()