mirror of
https://github.com/MontFerret/ferret.git
synced 2025-11-06 08:39:09 +02:00
Linter Cleanups (#294)
* sync with MontFerret/ferret * fix --param handling When params is converted to map it uses strings.Split, which slices a string into all substrings separated by :. * remove impossible conditions nil != nil * delete ineffectual assignments * replace '+= 1' with '++' * remove useless comparison with nil * merge variable declarations * remove bool comparison * fix imports * fix imports * delete unused file * use copy instead of loop * delete unused DummyInterface * remove unnecassary break statements * tidy modules
This commit is contained in:
@@ -46,7 +46,7 @@ func (iterator *FilterIterator) Next(ctx context.Context, scope *core.Scope) (*c
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if take == true {
|
||||
if take {
|
||||
return nextScope, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestArrayIterator(t *testing.T) {
|
||||
|
||||
res = append(res, nextScope.MustGetVariable(collections.DefaultValueVar))
|
||||
|
||||
pos += 1
|
||||
pos++
|
||||
}
|
||||
|
||||
So(res, ShouldHaveLength, arr.Length())
|
||||
|
||||
@@ -49,7 +49,7 @@ func TestSliceIterator(t *testing.T) {
|
||||
|
||||
res = append(res, item)
|
||||
|
||||
pos += 1
|
||||
pos++
|
||||
}
|
||||
|
||||
So(res, ShouldHaveLength, len(arr))
|
||||
@@ -96,6 +96,8 @@ func TestSliceIterator(t *testing.T) {
|
||||
|
||||
_, err := collections.ToSlice(ctx, scope, iter)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
item, err := iter.Next(ctx, scope)
|
||||
|
||||
So(item, ShouldBeNil)
|
||||
|
||||
@@ -54,7 +54,7 @@ func NewSorter(fn Comparator, direction SortDirection) (*Sorter, error) {
|
||||
return nil, core.Error(core.ErrMissedArgument, "fn")
|
||||
}
|
||||
|
||||
if IsValidSortDirection(direction) == false {
|
||||
if !IsValidSortDirection(direction) {
|
||||
return nil, core.Error(core.ErrInvalidArgument, "direction")
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func NewSortIterator(
|
||||
return nil, core.Error(core.ErrMissedArgument, "values")
|
||||
}
|
||||
|
||||
if comparators == nil || len(comparators) == 0 {
|
||||
if len(comparators) == 0 {
|
||||
return nil, core.Error(core.ErrMissedArgument, "comparator")
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func NewSortIterator(
|
||||
|
||||
func (iterator *SortIterator) Next(ctx context.Context, scope *core.Scope) (*core.Scope, error) {
|
||||
// we need to initialize the iterator
|
||||
if iterator.ready == false {
|
||||
if !iterator.ready {
|
||||
iterator.ready = true
|
||||
sorted, err := iterator.sort(ctx, scope)
|
||||
|
||||
|
||||
@@ -8,16 +8,8 @@ import (
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
type DummyInterface interface {
|
||||
DummyFunc() string
|
||||
}
|
||||
|
||||
type DummyStruct struct{}
|
||||
|
||||
func (d DummyStruct) DummyFunc() string {
|
||||
return "testing"
|
||||
}
|
||||
|
||||
func TestIsNil(t *testing.T) {
|
||||
Convey("Should match", t, func() {
|
||||
// nil == invalid
|
||||
|
||||
@@ -23,8 +23,6 @@ func (b *BodyExpression) Add(exp core.Expression) error {
|
||||
}
|
||||
|
||||
b.expression = exp
|
||||
|
||||
break
|
||||
default:
|
||||
b.statements = append(b.statements, exp)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ func NewBooleanLiteral(val bool) BooleanLiteral {
|
||||
}
|
||||
|
||||
func (l BooleanLiteral) Exec(_ context.Context, _ *core.Scope) (core.Value, error) {
|
||||
if l == true {
|
||||
if l {
|
||||
return values.True, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ func NewMemberExpression(src core.SourceMap, variableName string, path []core.Ex
|
||||
return nil, core.Error(core.ErrMissedArgument, "variable name")
|
||||
}
|
||||
|
||||
if path == nil || len(path) == 0 {
|
||||
if len(path) == 0 {
|
||||
return nil, core.Error(core.ErrMissedArgument, "path expressions")
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ func NewArrayOperator(
|
||||
return nil, core.Error(core.ErrMissedArgument, "right expression")
|
||||
}
|
||||
|
||||
if IsValidArrayOperatorType(aotype) == false {
|
||||
if !IsValidArrayOperatorType(aotype) {
|
||||
return nil, core.Error(core.ErrInvalidArgument, "operator")
|
||||
}
|
||||
|
||||
|
||||
@@ -58,8 +58,8 @@ func (operator *InOperator) Eval(_ context.Context, left, right core.Value) (cor
|
||||
found := arr.IndexOf(left) > -1
|
||||
|
||||
if operator.not {
|
||||
return values.NewBoolean(found == false), nil
|
||||
return values.NewBoolean(!found), nil
|
||||
}
|
||||
|
||||
return values.NewBoolean(found == true), nil
|
||||
return values.NewBoolean(found), nil
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ func TestParameterExpressionExec(t *testing.T) {
|
||||
sourceMap := core.NewSourceMap("test", 1, 10)
|
||||
existExp, err := expressions.NewParameterExpression(sourceMap, "param1")
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
params := make(map[string]core.Value)
|
||||
params["param1"] = values.NewInt(1)
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ func (t *Array) Length() Int {
|
||||
|
||||
func (t *Array) ForEach(predicate ArrayPredicate) {
|
||||
for idx, val := range t.items {
|
||||
if predicate(val, idx) == false {
|
||||
if !predicate(val, idx) {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func (t *Array) ForEach(predicate ArrayPredicate) {
|
||||
|
||||
func (t *Array) Find(predicate ArrayPredicate) (core.Value, Boolean) {
|
||||
for idx, val := range t.items {
|
||||
if predicate(val, idx) == true {
|
||||
if predicate(val, idx) {
|
||||
return val, True
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ func TestArray(t *testing.T) {
|
||||
counter := 0
|
||||
|
||||
arr.ForEach(func(value core.Value, idx int) bool {
|
||||
counter += 1
|
||||
counter++
|
||||
|
||||
return true
|
||||
})
|
||||
@@ -303,7 +303,7 @@ func TestArray(t *testing.T) {
|
||||
counter := 0
|
||||
|
||||
arr.ForEach(func(value core.Value, idx int) bool {
|
||||
counter += 1
|
||||
counter++
|
||||
|
||||
return true
|
||||
})
|
||||
@@ -323,7 +323,7 @@ func TestArray(t *testing.T) {
|
||||
counter := 0
|
||||
|
||||
arr.ForEach(func(value core.Value, idx int) bool {
|
||||
counter += 1
|
||||
counter++
|
||||
|
||||
return value.Compare(values.NewInt(threshold)) == -1
|
||||
})
|
||||
|
||||
@@ -84,7 +84,7 @@ func (t Boolean) Compare(other core.Value) int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
if raw == false && i == true {
|
||||
if !raw && i {
|
||||
return -1
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func GetIn(ctx context.Context, from core.Value, byPath []core.Value) (core.Value, error) {
|
||||
if byPath == nil || len(byPath) == 0 {
|
||||
if len(byPath) == 0 {
|
||||
return None, nil
|
||||
}
|
||||
|
||||
@@ -35,16 +35,12 @@ func GetIn(ctx context.Context, from core.Value, byPath []core.Value) (core.Valu
|
||||
}
|
||||
|
||||
result, _ = segVal.Get(segment.(String))
|
||||
|
||||
break
|
||||
case *Array:
|
||||
if segType != types.Int {
|
||||
return nil, core.TypeError(segType, types.Int)
|
||||
}
|
||||
|
||||
result = segVal.Get(segment.(Int))
|
||||
|
||||
break
|
||||
case core.Getter:
|
||||
return segVal.GetIn(ctx, byPath[i:])
|
||||
default:
|
||||
@@ -61,7 +57,7 @@ func GetIn(ctx context.Context, from core.Value, byPath []core.Value) (core.Valu
|
||||
}
|
||||
|
||||
func SetIn(ctx context.Context, to core.Value, byPath []core.Value, value core.Value) error {
|
||||
if byPath == nil || len(byPath) == 0 {
|
||||
if len(byPath) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -80,27 +76,23 @@ func SetIn(ctx context.Context, to core.Value, byPath []core.Value, value core.V
|
||||
return core.TypeError(segmentType, types.String)
|
||||
}
|
||||
|
||||
if isTarget == false {
|
||||
if !isTarget {
|
||||
current, _ = parVal.Get(segment.(String))
|
||||
} else {
|
||||
parVal.Set(segment.(String), value)
|
||||
}
|
||||
|
||||
break
|
||||
case *Array:
|
||||
if segmentType != types.Int {
|
||||
return core.TypeError(segmentType, types.Int)
|
||||
}
|
||||
|
||||
if isTarget == false {
|
||||
if !isTarget {
|
||||
current = parVal.Get(segment.(Int))
|
||||
} else {
|
||||
if err := parVal.Set(segment.(Int), value); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
break
|
||||
case core.Setter:
|
||||
return parVal.SetIn(ctx, byPath[idx:], value)
|
||||
default:
|
||||
@@ -108,7 +100,7 @@ func SetIn(ctx context.Context, to core.Value, byPath []core.Value, value core.V
|
||||
isArray := segmentType.Equals(types.Int)
|
||||
|
||||
// it's not an index
|
||||
if isArray == false {
|
||||
if !isArray {
|
||||
obj := NewObject()
|
||||
parent = obj
|
||||
|
||||
@@ -135,11 +127,9 @@ func SetIn(ctx context.Context, to core.Value, byPath []core.Value, value core.V
|
||||
return err
|
||||
}
|
||||
|
||||
if isTarget == false {
|
||||
if !isTarget {
|
||||
current = None
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ func (t *CustomValue) Copy() core.Value {
|
||||
}
|
||||
|
||||
func (t *CustomValue) GetIn(ctx context.Context, path []core.Value) (core.Value, error) {
|
||||
if path == nil || len(path) == 0 {
|
||||
if len(path) == 0 {
|
||||
return values.None, nil
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func (t *CustomValue) GetIn(ctx context.Context, path []core.Value) (core.Value,
|
||||
}
|
||||
|
||||
func (t *CustomValue) SetIn(ctx context.Context, path []core.Value, value core.Value) error {
|
||||
if path == nil || len(path) == 0 {
|
||||
if len(path) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ func (t *Object) Values() []core.Value {
|
||||
|
||||
func (t *Object) ForEach(predicate ObjectPredicate) {
|
||||
for key, val := range t.value {
|
||||
if predicate(val, key) == false {
|
||||
if !predicate(val, key) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ func TestObject(t *testing.T) {
|
||||
counter := 0
|
||||
|
||||
obj.ForEach(func(value core.Value, key string) bool {
|
||||
counter += 1
|
||||
counter++
|
||||
|
||||
return true
|
||||
})
|
||||
@@ -300,7 +300,7 @@ func TestObject(t *testing.T) {
|
||||
counter := 0
|
||||
|
||||
obj.ForEach(func(value core.Value, key string) bool {
|
||||
counter += 1
|
||||
counter++
|
||||
|
||||
return true
|
||||
})
|
||||
@@ -320,7 +320,7 @@ func TestObject(t *testing.T) {
|
||||
counter := 0
|
||||
|
||||
obj.ForEach(func(value core.Value, key string) bool {
|
||||
counter += 1
|
||||
counter++
|
||||
|
||||
return counter < threshold
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user