Add lint checks: gofmt, goimports, golint

- gofmt - Gofmt checks whether code was gofmt-ed. By default this tool runs
  with -s option to check for code simplification
- goimports - Goimports does everything that gofmt does. Additionally it checks
  unused imports
- golint - Golint differs from gofmt. Gofmt reformats Go source code, whereas
  golint prints out style mistakes
    - checks the uncommented exported functions & types

Update the code to fix the lint checks.
This commit is contained in:
arnaucube
2020-08-31 12:26:35 +02:00
parent 3bd91ec736
commit cbbcb65c8c
21 changed files with 98 additions and 51 deletions

View File

@@ -1,3 +1,7 @@
// Package utils provides methods to work with Hermez custom half float
// precision, 16 bits, codification internally called Float16 has been adopted
// to encode large integers. This is done in order to save bits when L2
// transactions are published.
//nolint:gomnd
package utils
@@ -23,8 +27,8 @@ func (f16 Float16) Bytes() []byte {
}
// BigInt converts the Float16 to a *big.Int integer
func (fl16 *Float16) BigInt() *big.Int {
fl := int64(*fl16)
func (f16 *Float16) BigInt() *big.Int {
fl := int64(*f16)
m := big.NewInt(fl & 0x3FF)
e := big.NewInt(fl >> 11)

View File

@@ -101,17 +101,17 @@ func BenchmarkFloat16(b *testing.B) {
BigInt *big.Int
}
testVector := []pair{
pair{0x307B, newBigInt("123000000")},
pair{0x1DC6, newBigInt("454500")},
pair{0xFFFF, newBigInt("10235000000000000000000000000000000")},
pair{0x0000, newBigInt("0")},
pair{0x0400, newBigInt("0")},
pair{0x0001, newBigInt("1")},
pair{0x0401, newBigInt("1")},
pair{0x0800, newBigInt("0")},
pair{0x0c00, newBigInt("5")},
pair{0x0801, newBigInt("10")},
pair{0x0c01, newBigInt("15")},
{0x307B, newBigInt("123000000")},
{0x1DC6, newBigInt("454500")},
{0xFFFF, newBigInt("10235000000000000000000000000000000")},
{0x0000, newBigInt("0")},
{0x0400, newBigInt("0")},
{0x0001, newBigInt("1")},
{0x0401, newBigInt("1")},
{0x0800, newBigInt("0")},
{0x0c00, newBigInt("5")},
{0x0801, newBigInt("10")},
{0x0c01, newBigInt("15")},
}
b.Run("floorFix2Float()", func(b *testing.B) {
for i := 0; i < b.N; i++ {
@@ -120,7 +120,7 @@ func BenchmarkFloat16(b *testing.B) {
})
b.Run("NewFloat16()", func(b *testing.B) {
for i := 0; i < b.N; i++ {
NewFloat16(testVector[i%len(testVector)].BigInt) //nolint:errcheck
_, _ = NewFloat16(testVector[i%len(testVector)].BigInt)
}
})
b.Run("Float16.BigInt()", func(b *testing.B) {