golangci-lint/CI: Bump versions and introduce new linters (#798)

* golangci-lint/CI: Bump versions

Fix remaining linter issues

* Specifically set AppVeyor version

* Fix the infamous typos 👀

* Add go env cmd to AppVeyor

* Add go version cmd to AppVeyor

* Specify AppVeyor image, adjust linters

* Update go get to go install due to deprecation

* Bump golangci-lint timeout time for AppVeyor

* Change NW contract to NQ

* Address nitters

* GetRandomPair -> Pair{}

* Address nits

* Address time nitterinos plus additional tweaks

* More time inception upgrades!

* Bending time and space
This commit is contained in:
Adrian Gallagher
2021-10-14 16:38:53 +11:00
committed by GitHub
parent 0a91af0f2e
commit f0d45aa1d2
194 changed files with 1506 additions and 1233 deletions

View File

@@ -130,16 +130,14 @@ func TestRemove(t *testing.T) {
func TestGetNewest(t *testing.T) {
lruCache := New(2)
k, _ := lruCache.getNewest()
if k != nil {
if k, _ := lruCache.getNewest(); k != nil {
t.Fatal("expected GetNewest() on empty cache to return nil")
}
}
func TestGetOldest(t *testing.T) {
lruCache := New(2)
k, _ := lruCache.getOldest()
if k != nil {
if k, _ := lruCache.getOldest(); k != nil {
t.Fatal("expected GetOldest() on empty cache to return nil")
}
}

9
common/cache/lru.go vendored
View File

@@ -47,8 +47,7 @@ func (l *LRU) Get(key interface{}) interface{} {
// GetOldest returns the oldest entry
func (l *LRU) getOldest() (key, value interface{}) {
x := l.l.Back()
if x != nil {
if x := l.l.Back(); x != nil {
return x.Value.(*item).key, x.Value.(*item).value
}
return
@@ -56,8 +55,7 @@ func (l *LRU) getOldest() (key, value interface{}) {
// GetNewest returns the newest entry
func (l *LRU) getNewest() (key, value interface{}) {
x := l.l.Front()
if x != nil {
if x := l.l.Front(); x != nil {
return x.Value.(*item).key, x.Value.(*item).value
}
return
@@ -93,8 +91,7 @@ func (l *LRU) Len() uint64 {
// removeOldest removes the oldest item from the cache.
func (l *LRU) removeOldestEntry() {
i := l.l.Back()
if i != nil {
if i := l.l.Back(); i != nil {
l.removeElement(i)
}
}

View File

@@ -248,15 +248,13 @@ func TestStringDataContains(t *testing.T) {
originalHaystack := []string{"hello", "world", "USDT", "Contains", "string"}
originalNeedle := "USD"
anotherNeedle := "thing"
expectedOutput := true
expectedOutputTwo := false
actualResult := StringDataContains(originalHaystack, originalNeedle)
if actualResult != expectedOutput {
if expectedOutput := true; actualResult != expectedOutput {
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
actualResult = StringDataContains(originalHaystack, anotherNeedle)
if actualResult != expectedOutputTwo {
if expectedOutput := false; actualResult != expectedOutput {
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
@@ -267,15 +265,13 @@ func TestStringDataCompare(t *testing.T) {
originalHaystack := []string{"hello", "WoRld", "USDT", "Contains", "string"}
originalNeedle := "WoRld"
anotherNeedle := "USD"
expectedOutput := true
expectedOutputTwo := false
actualResult := StringDataCompare(originalHaystack, originalNeedle)
if actualResult != expectedOutput {
if expectedOutput := true; actualResult != expectedOutput {
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
actualResult = StringDataCompare(originalHaystack, anotherNeedle)
if actualResult != expectedOutputTwo {
if expectedOutput := false; actualResult != expectedOutput {
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
@@ -286,16 +282,14 @@ func TestStringDataCompareUpper(t *testing.T) {
originalHaystack := []string{"hello", "WoRld", "USDT", "Contains", "string"}
originalNeedle := "WoRld"
anotherNeedle := "WoRldD"
expectedOutput := true
expectedOutputTwo := false
actualResult := StringDataCompareInsensitive(originalHaystack, originalNeedle)
if actualResult != expectedOutput {
if expectedOutput := true; actualResult != expectedOutput {
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
actualResult = StringDataCompareInsensitive(originalHaystack, anotherNeedle)
if actualResult != expectedOutputTwo {
if expectedOutput := false; actualResult != expectedOutput {
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
@@ -306,15 +300,13 @@ func TestStringDataContainsUpper(t *testing.T) {
originalHaystack := []string{"bLa", "BrO", "sUp"}
originalNeedle := "Bla"
anotherNeedle := "ning"
expectedOutput := true
expectedOutputTwo := false
actualResult := StringDataContainsInsensitive(originalHaystack, originalNeedle)
if actualResult != expectedOutput {
if expectedOutput := true; actualResult != expectedOutput {
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
actualResult = StringDataContainsInsensitive(originalHaystack, anotherNeedle)
if actualResult != expectedOutputTwo {
if expectedOutput := false; actualResult != expectedOutput {
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
@@ -410,8 +402,7 @@ func TestGetURIPath(t *testing.T) {
func TestGetExecutablePath(t *testing.T) {
t.Parallel()
_, err := GetExecutablePath()
if err != nil {
if _, err := GetExecutablePath(); err != nil {
t.Errorf("Common GetExecutablePath. Error: %s", err)
}
}

View File

@@ -52,7 +52,7 @@ func TimeFromUnixTimestampFloat(raw interface{}) (time.Time, error) {
if !ok {
return time.Time{}, fmt.Errorf("unable to parse, value not float64: %T", raw)
}
return time.Unix(0, int64(ts)*int64(time.Millisecond)), nil
return time.UnixMilli(int64(ts)), nil
}
// TimeFromUnixTimestampDecimal converts a unix timestamp in decimal form to
@@ -76,23 +76,8 @@ func UnixTimestampStrToTime(timeStr string) (time.Time, error) {
return time.Unix(i, 0), nil
}
// UnixMillis converts a UnixNano timestamp to milliseconds
func UnixMillis(t time.Time) int64 {
return t.UnixNano() / int64(time.Millisecond)
}
// RecvWindow converts a supplied time.Duration to milliseconds
func RecvWindow(d time.Duration) int64 {
return int64(d) / int64(time.Millisecond)
}
// BoolPtr takes in boolen condition and returns pointer version of it
func BoolPtr(condition bool) *bool {
b := condition
return &b
}
// UnixMillisToNano converts Unix milli time to UnixNano
func UnixMillisToNano(milli int64) int64 {
return milli * int64(time.Millisecond)
}

View File

@@ -32,10 +32,8 @@ func TestFloatFromString(t *testing.T) {
func TestIntFromString(t *testing.T) {
t.Parallel()
testString := "1337"
expectedOutput := 1337
actualOutput, err := IntFromString(testString)
if actualOutput != expectedOutput || err != nil {
if expectedOutput := 1337; actualOutput != expectedOutput || err != nil {
t.Errorf("Common IntFromString. Expected '%v'. Actual '%v'. Error: %s",
expectedOutput, actualOutput, err)
}
@@ -136,33 +134,9 @@ func TestUnixTimestampStrToTime(t *testing.T) {
t.Errorf(
"Expected '%s'. Actual '%s'.", expectedOutput, actualResult)
}
actualResult, err = UnixTimestampStrToTime(incorrectTime)
_, err = UnixTimestampStrToTime(incorrectTime)
if err == nil {
t.Error("Common UnixTimestampStrToTime error")
}
}
func TestUnixMillis(t *testing.T) {
t.Parallel()
testTime := time.Date(2014, time.October, 28, 0, 32, 0, 0, time.UTC)
expectedOutput := int64(1414456320000)
actualOutput := UnixMillis(testTime)
if actualOutput != expectedOutput {
t.Errorf("Common UnixMillis. Expected '%d'. Actual '%d'.",
expectedOutput, actualOutput)
}
}
func TestRecvWindow(t *testing.T) {
t.Parallel()
testTime := time.Duration(24760000)
expectedOutput := int64(24)
actualOutput := RecvWindow(testTime)
if actualOutput != expectedOutput {
t.Errorf("Common RecvWindow. Expected '%d'. Actual '%d'",
expectedOutput, actualOutput)
t.Error("should throw an error")
}
}
@@ -176,10 +150,3 @@ func TestBoolPtr(t *testing.T) {
t.Fatal("false expected received true")
}
}
func TestUnixMillisToNano(t *testing.T) {
v := UnixMillisToNano(1588653603424)
if v != 1588653603424000000 {
t.Fatalf("unexpected result received %v", v)
}
}

View File

@@ -35,9 +35,8 @@ func TestBase64Decode(t *testing.T) {
func TestBase64Encode(t *testing.T) {
t.Parallel()
originalInput := []byte("hello")
expectedOutput := "aGVsbG8="
actualResult := Base64Encode(originalInput)
if actualResult != expectedOutput {
if expectedOutput := "aGVsbG8="; actualResult != expectedOutput {
t.Errorf("Expected '%s'. Actual '%s'",
expectedOutput, actualResult)
}

View File

@@ -80,8 +80,7 @@ func TestZip(t *testing.T) {
if filepath.Base(o[0]) != "binance.json" || filepath.Base(o[4]) != "localbitcoins.json" {
t.Fatal("unexpected archive result received")
}
expected := 7
if len(o) != expected {
if expected := 7; len(o) != expected {
t.Fatalf("expected %v files to be extracted received: %v ", expected, len(o))
}

View File

@@ -116,8 +116,7 @@ func WriteAsCSV(filename string, records [][]string) error {
w.Flush()
err := w.Error()
if err != nil {
if err := w.Error(); err != nil {
return err
}
return Write(filename, buf.Bytes())

View File

@@ -12,9 +12,7 @@ func TestCalculateFee(t *testing.T) {
t.Parallel()
originalInput := float64(1)
fee := float64(1)
expectedOutput := 0.01
actualResult := CalculateFee(originalInput, fee)
if expectedOutput != actualResult {
if expectedOutput, actualResult := 0.01, CalculateFee(originalInput, fee); expectedOutput != actualResult {
t.Errorf(
"Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
}
@@ -24,9 +22,7 @@ func TestCalculateAmountWithFee(t *testing.T) {
t.Parallel()
originalInput := float64(1)
fee := float64(1)
expectedOutput := 1.01
actualResult := CalculateAmountWithFee(originalInput, fee)
if expectedOutput != actualResult {
if actualResult, expectedOutput := CalculateAmountWithFee(originalInput, fee), 1.01; expectedOutput != actualResult {
t.Errorf(
"Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
}
@@ -62,9 +58,8 @@ func TestCalculateNetProfit(t *testing.T) {
priceThen := float64(1)
priceNow := float64(10)
costs := float64(1)
expectedOutput := float64(44)
actualResult := CalculateNetProfit(amount, priceThen, priceNow, costs)
if expectedOutput != actualResult {
if expectedOutput := float64(44); expectedOutput != actualResult {
t.Errorf(
"Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
}
@@ -164,8 +159,7 @@ func TestSortinoRatio(t *testing.T) {
if err != nil {
t.Error(err)
}
rr := math.Round(r*10) / 10
if rr != 0.2 {
if rr := math.Round(r*10) / 10; rr != 0.2 {
t.Errorf("expected 0.2, received %v", rr)
}
}
@@ -538,8 +532,7 @@ func TestDecimalSortinoRatio(t *testing.T) {
if err != nil && !errors.Is(err, ErrInexactConversion) {
t.Error(err)
}
rr := r.Round(1)
if !rr.Equal(decimal.NewFromFloat(0.2)) {
if rr := r.Round(1); !rr.Equal(decimal.NewFromFloat(0.2)) {
t.Errorf("expected 0.2, received %v", rr)
}
}

View File

@@ -100,7 +100,6 @@ func (t *TimePeriodCalculator) calculateRanges() {
}
tr.HasDataInRange = t.TimePeriods[len(t.TimePeriods)-1].dataInRange
t.TimeRanges = append(t.TimeRanges, tr)
tr = TimeRange{}
}
}