Skip to content

Commit

Permalink
linters: Add intrange, additional go vet linters to match gopls and f…
Browse files Browse the repository at this point in the history
…ix issues
  • Loading branch information
thrasher- committed Aug 16, 2024
1 parent f341862 commit ab48dab
Show file tree
Hide file tree
Showing 68 changed files with 135 additions and 174 deletions.
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ linters:
# - importas
# - inamedparam
# - interfacebloat
# - intrange
- intrange
# - ireturn
# - lll
# - loggercheck
Expand Down Expand Up @@ -120,6 +120,8 @@ linters-settings:
govet:
enable:
- shadow
- nilness
- unusedwrite
goconst:
min-occurrences: 6
gocritic:
Expand Down
4 changes: 2 additions & 2 deletions backtester/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func FitStringToLimit(str, spacer string, limit int, upper bool) string {
return str[0:limit]
}
spacerLen := len(spacer)
for i := 0; i < limResp; i++ {
for i := range limResp {
str += spacer
for j := 0; j < spacerLen; j++ {
for j := range spacerLen {
if j > 0 {
// prevent clever people from going beyond
// the limit by having a spacer longer than 1
Expand Down
11 changes: 0 additions & 11 deletions backtester/engine/backtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1416,21 +1416,10 @@ func TestRunLive(t *testing.T) {
bt.LiveDataHandler = dc
cp := currency.NewPair(currency.BTC, currency.USD)
i := &gctkline.Item{
Exchange: testExchange,
Pair: cp,
UnderlyingPair: cp,
Asset: asset.Spot,
Interval: gctkline.FifteenSecond,
Candles: []gctkline.Candle{
{
Time: time.Now(),
Open: 1337,
High: 1337,
Low: 1337,
Close: 1337,
Volume: 1337,
},
},
}
// AppendDataSource(exchange gctexchange.IBotExchange, interval gctkline.Interval, asset asset.Asset, pair, underlyingPair currency.Pair, dataType int64) error
setup := &liveDataSourceSetup{
Expand Down
12 changes: 7 additions & 5 deletions backtester/engine/grpcserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,13 @@ func TestExecuteStrategyFromConfig(t *testing.T) {
}
var fd *btrpc.FuturesDetails
if defaultConfig.CurrencySettings[i].FuturesDetails != nil {
fd.Leverage = &btrpc.Leverage{
CanUseLeverage: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.CanUseLeverage,
MaximumOrdersWithLeverageRatio: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.MaximumOrdersWithLeverageRatio.String(),
MaximumLeverageRate: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.MaximumOrderLeverageRate.String(),
MaximumCollateralLeverageRate: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.MaximumCollateralLeverageRate.String(),
fd = &btrpc.FuturesDetails{
Leverage: &btrpc.Leverage{
CanUseLeverage: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.CanUseLeverage,
MaximumOrdersWithLeverageRatio: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.MaximumOrdersWithLeverageRatio.String(),
MaximumLeverageRate: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.MaximumOrderLeverageRate.String(),
MaximumCollateralLeverageRate: defaultConfig.CurrencySettings[i].FuturesDetails.Leverage.MaximumCollateralLeverageRate.String(),
},
}
}
var makerFee, takerFee string
Expand Down
1 change: 0 additions & 1 deletion backtester/engine/live_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var (
ErrLiveDataTimeout = errors.New("no data processed within timeframe")

errDataSourceExists = errors.New("data source already exists")
errInvalidCredentials = errors.New("credentials are invalid, please check your config")
errNoCredsNoLive = errors.New("cannot use real orders without credentials to fulfil those real orders")
errNoDataSetForClosingPositions = errors.New("no data was set for closing positions")
errNilError = errors.New("nil error received when expecting an error")
Expand Down
3 changes: 0 additions & 3 deletions backtester/eventhandlers/exchange/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ func TestPlaceOrder(t *testing.T) {
if !errors.Is(err, nil) {
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
}
bot.ExchangeManager = em
bot.OrderManager, err = engine.SetupOrderManager(em, &engine.CommunicationManager{}, &bot.ServicesWG, &gctconfig.OrderManager{})
if !errors.Is(err, nil) {
t.Errorf("received '%v' expected '%v'", err, nil)
Expand Down Expand Up @@ -256,7 +255,6 @@ func TestExecuteOrder(t *testing.T) {
if !errors.Is(err, nil) {
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
}
bot.ExchangeManager = em
bot.OrderManager, err = engine.SetupOrderManager(em, &engine.CommunicationManager{}, &bot.ServicesWG, &gctconfig.OrderManager{})
if !errors.Is(err, nil) {
t.Errorf("received: %v, expected: %v", err, nil)
Expand Down Expand Up @@ -392,7 +390,6 @@ func TestExecuteOrderBuySellSizeLimit(t *testing.T) {
if !errors.Is(err, nil) {
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
}
bot.ExchangeManager = em
bot.OrderManager, err = engine.SetupOrderManager(em, &engine.CommunicationManager{}, &bot.ServicesWG, &gctconfig.OrderManager{})
if !errors.Is(err, nil) {
t.Errorf("received: %v, expected: %v", err, nil)
Expand Down
2 changes: 1 addition & 1 deletion backtester/eventhandlers/statistics/statistics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ func TestCalculateBiggestEventDrawdown(t *testing.T) {
a := asset.Spot
p := currency.NewPair(currency.BTC, currency.USDT)
var events []data.Event
for i := int64(0); i < 100; i++ {
for i := range int64(100) {
tt1 = tt1.Add(gctkline.OneDay.Duration())
even := &event.Base{
Exchange: exch,
Expand Down
2 changes: 0 additions & 2 deletions backtester/funding/funding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ func TestExists(t *testing.T) {
isCollateral: baseItem.isCollateral,
collateralCandles: baseItem.collateralCandles,
}
quoteCopy := Item{pairedWith: quoteItem.pairedWith}
quoteCopy.pairedWith = &baseCopy
if !f.Exists(&baseCopy) {
t.Errorf("received '%v' expected '%v'", false, true)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/exchange_wrapper_coverage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ func testWrappers(e exchange.IBotExchange) ([]string, error) {
contextParam := reflect.TypeOf((*context.Context)(nil)).Elem()

var funcs []string
for x := 0; x < iExchange.NumMethod(); x++ {
for x := range iExchange.NumMethod() {
name := iExchange.Method(x).Name
method := actualExchange.MethodByName(name)
inputs := make([]reflect.Value, method.Type().NumIn())

for y := 0; y < method.Type().NumIn(); y++ {
for y := range method.Type().NumIn() {
input := method.Type().In(y)

if input.Implements(contextParam) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ func executeExchangeWrapperTests(ctx context.Context, t *testing.T, exch exchang
t.Helper()
iExchange := reflect.TypeOf(&exch).Elem()
actualExchange := reflect.ValueOf(exch)
for x := 0; x < iExchange.NumMethod(); x++ {
for x := range iExchange.NumMethod() {
methodName := iExchange.Method(x).Name
if _, ok := excludedMethodNames[methodName]; ok {
continue
}
method := actualExchange.MethodByName(methodName)

var assetLen int
for y := 0; y < method.Type().NumIn(); y++ {
for y := range method.Type().NumIn() {
input := method.Type().In(y)
for _, t := range []reflect.Type{
assetParam, orderSubmitParam, orderModifyParam, orderCancelParam, orderCancelsParam, pairKeySliceParam, getOrdersRequestParam, latestRateRequest,
Expand Down Expand Up @@ -213,7 +213,7 @@ func executeExchangeWrapperTests(ctx context.Context, t *testing.T, exch exchang
Start: s,
End: e,
}
for z := 0; z < method.Type().NumIn(); z++ {
for z := range method.Type().NumIn() {
argGenerator.MethodInputType = method.Type().In(z)
generatedArg := generateMethodArg(ctx, t, argGenerator)
inputs[z] = *generatedArg
Expand Down
2 changes: 1 addition & 1 deletion cmd/gctcli/orderbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ func getOrderbookStream(c *cli.Context) error {
fmt.Println("\t\tBids\t\t\t\tAsks")
fmt.Println()

for i := int64(0); i < maxLen; i++ {
for i := range maxLen {
var bidAmount, bidPrice float64
if i <= bidLen {
bidAmount = resp.Bids[i].Amount
Expand Down
2 changes: 1 addition & 1 deletion cmd/gen_otp/otp_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func main() {
for {
log.Println("Please enter in your OTP secret:")
if _, err = fmt.Scanln(&input); err != nil {
log.Printf("Failed to read input. Err: %s", err)
log.Printf("Failed to read input. Err: %s\n", err)
continue
}
if input != "" {
Expand Down
2 changes: 1 addition & 1 deletion common/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestContainsOrAdd(t *testing.T) {

func TestClear(t *testing.T) {
lruCache := New(5)
for x := 0; x < 5; x++ {
for x := range 5 {
lruCache.Add(x, x)
}
if lruCache.Len() != 5 {
Expand Down
6 changes: 3 additions & 3 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func NewHTTPClientWithTimeout(t time.Duration) *http.Client {
// returns an individual string array
func StringSliceDifference(slice1, slice2 []string) []string {
var diff []string
for i := 0; i < 2; i++ {
for i := range 2 {
for _, s1 := range slice1 {
found := false
for _, s2 := range slice2 {
Expand Down Expand Up @@ -399,7 +399,7 @@ func AddPaddingOnUpperCase(s string) string {
}
var result []string
left := 0
for x := 0; x < len(s); x++ {
for x := range s {
if x == 0 {
continue
}
Expand Down Expand Up @@ -431,7 +431,7 @@ func InArray(val, array interface{}) (exists bool, index int) {
switch reflect.TypeOf(array).Kind() {
case reflect.Array, reflect.Slice:
s := reflect.ValueOf(array)
for i := 0; i < s.Len(); i++ {
for i := range s.Len() {
if reflect.DeepEqual(val, s.Index(i).Interface()) {
index = i
exists = true
Expand Down
7 changes: 0 additions & 7 deletions common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,6 @@ func TestChangePermission(t *testing.T) {
}
}

func initStringSlice(size int) (out []string) {
for x := 0; x < size; x++ {
out = append(out, "gct-"+strconv.Itoa(x))
}
return
}

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

Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ func readEncryptedConfWithKey(reader *bufio.Reader, keyProvider func() ([]byte,
if err != nil {
return nil, err
}
for errCounter := 0; errCounter < maxAuthFailures; errCounter++ {
for range maxAuthFailures {
key, err := keyProvider()
if err != nil {
log.Errorf(log.ConfigMgr, "PromptForConfigKey err: %s", err)
Expand Down
2 changes: 0 additions & 2 deletions currency/forexprovider/currencylayer/currencylayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ var (
apiKeyLevel = 0
)

var isSet bool

func TestMain(m *testing.M) {
if apiKey == "" {
apiKey = os.Getenv("CURRENCYLAYER_APIKEY")
Expand Down
2 changes: 1 addition & 1 deletion currency/pair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ func TestRandomPairFromPairs(t *testing.T) {
// currency pairs
pairs = append(pairs, NewPair(ETH, USD))
expectedResults := make(map[string]bool)
for i := 0; i < 50; i++ {
for range 50 {
result, err = pairs.GetRandomPair()
if !errors.Is(err, nil) {
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
Expand Down
4 changes: 2 additions & 2 deletions currency/pairs.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ pairs:
}
base := p[x].Base.Lower().String()
baseLength := len(base)
for y := 0; y < baseLength; y++ {
for y := range baseLength {
if base[y] != symbol[y] {
continue pairs
}
}
quote := p[x].Quote.Lower().String()
for y := 0; y < len(quote); y++ {
for y := range quote {
if quote[y] != symbol[baseLength+y] {
continue pairs
}
Expand Down
2 changes: 1 addition & 1 deletion database/repository/audit/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func writeAudit(t *testing.T) {
t.Helper()
var wg sync.WaitGroup

for x := 0; x < 20; x++ {
for x := range 20 {
wg.Add(1)

go func(x int) {
Expand Down
2 changes: 1 addition & 1 deletion database/repository/candle/candle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func genOHCLVData() (out Item, err error) {
out.Asset = "spot"

start := time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC)
for x := 0; x < 365; x++ {
for x := range 365 {
out.Candles = append(out.Candles, Candle{
Timestamp: start.Add(time.Hour * 24 * time.Duration(x)),
Open: 1000,
Expand Down
4 changes: 2 additions & 2 deletions database/repository/datahistoryjob/datahistoryjob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestDataHistoryJob(t *testing.T) {
}

var jerberinos, jerberoos []*DataHistoryJob
for i := 0; i < 20; i++ {
for i := range 20 {
uu, _ := uuid.NewV4()
jerberinos = append(jerberinos, &DataHistoryJob{
ID: uu.String(),
Expand All @@ -138,7 +138,7 @@ func TestDataHistoryJob(t *testing.T) {
t.Fatal(err)
}
// insert the same jerbs to test conflict resolution
for i := 0; i < 20; i++ {
for i := range 20 {
uu, _ := uuid.NewV4()
j := &DataHistoryJob{
ID: uu.String(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestDataHistoryJob(t *testing.T) {
}

var resulterinos, resultaroos []*DataHistoryJobResult
for i := 0; i < 20; i++ {
for range 20 {
uu, _ := uuid.NewV4()
resulterinos = append(resulterinos, &DataHistoryJobResult{
ID: uu.String(),
Expand All @@ -156,7 +156,7 @@ func TestDataHistoryJob(t *testing.T) {
t.Fatal(err)
}
// insert the same results to test conflict resolution
for i := 0; i < 20; i++ {
for i := range 20 {
uu, _ := uuid.NewV4()
j := &DataHistoryJobResult{
ID: uu.String(),
Expand Down
2 changes: 1 addition & 1 deletion database/repository/script/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestScript(t *testing.T) {

func writeScript() {
var wg sync.WaitGroup
for x := 0; x < 20; x++ {
for x := range 20 {
wg.Add(1)

go func(x int) {
Expand Down
16 changes: 9 additions & 7 deletions database/repository/trade/trade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ func TestTrades(t *testing.T) {

func tradeSQLTester(t *testing.T) {
t.Helper()
var trades, trades2 []Data
trades := make([]Data, 20)
firstTime := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
for i := 0; i < 20; i++ {
for i := range 20 {
uu, _ := uuid.NewV4()
trades = append(trades, Data{
trades[i] = Data{
ID: uu.String(),
Timestamp: firstTime.Add(time.Minute * time.Duration(i+1)),
Exchange: testExchanges[0].Name,
Expand All @@ -122,16 +122,18 @@ func tradeSQLTester(t *testing.T) {
Amount: float64(i * (i + 2)),
Side: order.Buy.String(),
TID: strconv.Itoa(i),
})
}
}
err := Insert(trades...)
if err != nil {
t.Fatal(err)
}
// insert the same trades to test conflict resolution
for i := 0; i < 20; i++ {

trades2 := make([]Data, 20)
for i := range 20 {
uu, _ := uuid.NewV4()
trades2 = append(trades2, Data{
trades2[i] = Data{
ID: uu.String(),
Timestamp: firstTime.Add(time.Minute * time.Duration(i+1)),
Exchange: testExchanges[0].Name,
Expand All @@ -142,7 +144,7 @@ func tradeSQLTester(t *testing.T) {
Amount: float64(i * (i + 2)),
Side: order.Buy.String(),
TID: strconv.Itoa(i),
})
}
}
err = Insert(trades2...)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion database/repository/withdraw/withdraw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestWithdraw(t *testing.T) {
}

func seedWithdrawData() {
for x := 0; x < 20; x++ {
for x := range 20 {
test := fmt.Sprintf("test-%v", x)
resp := &withdraw.Response{
Exchange: withdraw.ExchangeResponse{
Expand Down
Loading

0 comments on commit ab48dab

Please sign in to comment.