mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Add linter checks to GHA & Fix code to pass lints
Add linter checks to GHA & Fix code to pass lints. The linters added are: - whitespace: Tool for detection of leading and trailing whitespace - gosec: Inspects source code for security problems - gci: Gci control golang package import order and make it always deterministic - misspell: Finds commonly misspelled English words in comments - gomnd: An analyzer to detect magic numbers The file utils/utils.go is excluded from the checks of gomnd, as uses magic numbers through the code
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
//nolint:gomnd
|
||||
package utils
|
||||
|
||||
import (
|
||||
@@ -33,9 +34,7 @@ func (fl16 *Float16) BigInt() *big.Int {
|
||||
res := m.Mul(m, exp)
|
||||
|
||||
if e5 != 0 && e.Cmp(big.NewInt(0)) != 0 {
|
||||
|
||||
res.Add(res, exp.Div(exp, big.NewInt(2)))
|
||||
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -56,11 +55,9 @@ func floorFix2Float(_f *big.Int) Float16 {
|
||||
s := big.NewInt(0).Rsh(m, 10)
|
||||
|
||||
for s.Cmp(zero) != 0 {
|
||||
|
||||
m.Div(m, ten)
|
||||
s.Rsh(m, 10)
|
||||
e++
|
||||
|
||||
}
|
||||
|
||||
return Float16(m.Int64() | e<<11)
|
||||
@@ -98,13 +95,11 @@ func NewFloat16(f *big.Int) (Float16, error) {
|
||||
d3 := big.NewInt(0).Abs(fi3.Sub(fi3, f))
|
||||
|
||||
if d.Cmp(d3) == 1 {
|
||||
|
||||
res = fl3
|
||||
}
|
||||
|
||||
// Do rounding check
|
||||
if res.BigInt().Cmp(f) == 0 {
|
||||
|
||||
return res, nil
|
||||
}
|
||||
return res, ErrRoundingLoss
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
)
|
||||
|
||||
func TestConversions(t *testing.T) {
|
||||
|
||||
testVector := map[Float16]string{
|
||||
0x307B: "123000000",
|
||||
0x1DC6: "454500",
|
||||
@@ -24,7 +23,6 @@ func TestConversions(t *testing.T) {
|
||||
}
|
||||
|
||||
for test := range testVector {
|
||||
|
||||
fix := test.BigInt()
|
||||
|
||||
assert.Equal(t, fix.String(), testVector[test])
|
||||
@@ -37,13 +35,10 @@ func TestConversions(t *testing.T) {
|
||||
|
||||
fx2 := fl.BigInt()
|
||||
assert.Equal(t, fx2.String(), testVector[test])
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestFloorFix2Float(t *testing.T) {
|
||||
|
||||
testVector := map[string]Float16{
|
||||
"87999990000000000": 0x776f,
|
||||
"87950000000000001": 0x776f,
|
||||
@@ -52,16 +47,13 @@ func TestFloorFix2Float(t *testing.T) {
|
||||
}
|
||||
|
||||
for test := range testVector {
|
||||
|
||||
bi := big.NewInt(0)
|
||||
bi.SetString(test, 10)
|
||||
|
||||
testFloat := NewFloat16Floor(bi)
|
||||
|
||||
assert.Equal(t, testFloat, testVector[test])
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestConversionLosses(t *testing.T) {
|
||||
@@ -94,7 +86,6 @@ func TestConversionLosses(t *testing.T) {
|
||||
assert.Equal(t, ErrRoundingLoss, err)
|
||||
c = b.BigInt()
|
||||
assert.NotEqual(t, c, a)
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkFloat16(b *testing.B) {
|
||||
|
||||
Reference in New Issue
Block a user