Skip to content

Commit

Permalink
linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
0xor1 committed Jul 23, 2021
1 parent 22729c8 commit 8e10873
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 31 deletions.
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type ErrInvalidArgumentType struct {
// TNs is a shorthand alias for typenames
type TNs = []string

// AnyTn is a typename when any type can be accepted
// AnyTN is a typename when any type can be accepted
const AnyTN = "any"

func (e ErrInvalidArgumentType) Error() string {
Expand Down
4 changes: 4 additions & 0 deletions iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type ArrayIterator struct {
l int
}

// ArrayIteratorTN is the array iterator type name
const ArrayIteratorTN = "array-iterator"

// TypeName returns the name of the type.
Expand Down Expand Up @@ -83,6 +84,7 @@ type BytesIterator struct {
l int
}

// BytesIteratorTN is the bytes iterator type name
const BytesIteratorTN = "bytes-iterator"

// TypeName returns the name of the type.
Expand Down Expand Up @@ -140,6 +142,7 @@ type MapIterator struct {
l int
}

// MapIteratorTN is the map iterator type name
const MapIteratorTN = "map-iterator"

// TypeName returns the name of the type.
Expand Down Expand Up @@ -203,6 +206,7 @@ type StringIterator struct {
l int
}

// StringIteratorTN is the string iterator type name
const StringIteratorTN = "string-iterator"

// TypeName returns the name of the type.
Expand Down
16 changes: 14 additions & 2 deletions objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ type Object interface {
Len() int
}

// TypeString converts a type name into the standard
// type string be wrapping it in angle brackets.
func TypeString(typeStr string) string {
return fmt.Sprintf("<%s>", typeStr)
}
Expand Down Expand Up @@ -340,9 +342,8 @@ func (o *Bool) GobDecode(b []byte) error {
func (o *Bool) GobEncode() ([]byte, error) {
if o.value {
return []byte{1}, nil
} else {
return []byte{0}, nil
}
return []byte{0}, nil
}

// BuiltinFunction represents a builtin function.
Expand Down Expand Up @@ -408,6 +409,7 @@ type Bytes struct {
Value []byte
}

// BytesTN is the bytes type name
const BytesTN = "bytes"

// TypeName returns the name of the type.
Expand Down Expand Up @@ -497,6 +499,7 @@ type Char struct {
Value rune
}

// CharTN is the char type name
const CharTN = "char"

// TypeName returns the name of the type.
Expand Down Expand Up @@ -617,6 +620,7 @@ type CompiledFunction struct {
Free []*ObjectPtr
}

// CompiledFunctionTN is the compiled function type name
const CompiledFunctionTN = "compiled-function"

// TypeName returns the name of the type.
Expand Down Expand Up @@ -667,6 +671,7 @@ type Error struct {
Value Object
}

// ErrorTN is the error type name
const ErrorTN = "error"

// TypeName returns the name of the type.
Expand Down Expand Up @@ -711,6 +716,7 @@ type Float struct {
Value float64
}

// FloatTN is the float type name
const FloatTN = "float"

// TypeName returns the name of the type.
Expand Down Expand Up @@ -850,6 +856,7 @@ type ImmutableArray struct {
Value []Object
}

// ImmutableArrayTN is the immutable array type name
const ImmutableArrayTN = "immutable-array"

// TypeName returns the name of the type.
Expand Down Expand Up @@ -956,6 +963,7 @@ type ImmutableMap struct {
Value map[string]Object
}

// ImmutableMapTN is the immutable map type name
const ImmutableMapTN = "immutable-map"

// TypeName returns the name of the type.
Expand Down Expand Up @@ -1056,6 +1064,7 @@ type Int struct {
Value int64
}

// IntTN is the int type name
const IntTN = "int"

func (o *Int) String() string {
Expand Down Expand Up @@ -1248,6 +1257,7 @@ type Map struct {
Value map[string]Object
}

// MapTN is the map type name
const MapTN = "map"

// TypeName returns the name of the type.
Expand Down Expand Up @@ -1358,6 +1368,7 @@ type ObjectPtr struct {
Value *Object
}

// ObjectPtrTN is the object ptr type name
const ObjectPtrTN = "free-var"

// TypeName returns the name of the type.
Expand Down Expand Up @@ -1392,6 +1403,7 @@ type String struct {
runeStr []rune
}

// StringTN is the string type name
const StringTN = "string"

// TypeName returns the name of the type.
Expand Down
27 changes: 10 additions & 17 deletions stdlib/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,8 @@ var textREMatch = tengo.CheckAnyArgs(func(args ...tengo.Object) (tengo.Object, e

if matched {
return tengo.TrueValue, nil
} else {
return tengo.FalseValue, nil
}
return tengo.FalseValue, nil
}, 2)

var textREFind = tengo.CheckAnyArgs(func(args ...tengo.Object) (tengo.Object, error) {
Expand Down Expand Up @@ -306,14 +305,13 @@ var textREReplace = tengo.CheckAnyArgs(func(args ...tengo.Object) (tengo.Object,
re, err := regexp.Compile(s1)
if err != nil {
return wrapError(err), nil
} else {
s, ok := doTextRegexpReplace(re, s2, s3)
if !ok {
return nil, tengo.ErrStringLimit
}

return &tengo.String{Value: s}, nil
}
s, ok := doTextRegexpReplace(re, s2, s3)
if !ok {
return nil, tengo.ErrStringLimit
}

return &tengo.String{Value: s}, nil
}, 3)

var textRESplit = tengo.CheckAnyArgs(func(args ...tengo.Object) (tengo.Object, error) {
Expand Down Expand Up @@ -359,9 +357,8 @@ var textRECompile = tengo.CheckAnyArgs(func(args ...tengo.Object) (tengo.Object,
re, err := regexp.Compile(s1)
if err != nil {
return wrapError(err), nil
} else {
return makeTextRegexp(re), nil
}
return makeTextRegexp(re), nil
}, 1)

var textReplace = tengo.CheckAnyArgs(func(args ...tengo.Object) (tengo.Object, error) {
Expand Down Expand Up @@ -578,10 +575,8 @@ var textFormatBool = tengo.CheckStrictArgs(func(args ...tengo.Object) (tengo.Obj

if b1 == tengo.TrueValue {
return &tengo.String{Value: "true"}, nil
} else {
return &tengo.String{Value: "false"}, nil
}

return &tengo.String{Value: "false"}, nil
}, tengo.BoolTN)

var textFormatFloat = tengo.CheckArgs(func(args ...tengo.Object) (tengo.Object, error) {
Expand Down Expand Up @@ -637,10 +632,8 @@ var textParseBool = tengo.CheckStrictArgs(func(args ...tengo.Object) (tengo.Obje

if parsed {
return tengo.TrueValue, nil
} else {
return tengo.FalseValue, nil
}

return tengo.FalseValue, nil
}, tengo.StringTN)

var textParseFloat = tengo.CheckArgs(func(args ...tengo.Object) (tengo.Object, error) {
Expand Down
3 changes: 1 addition & 2 deletions stdlib/text_regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ func makeTextRegexp(re *regexp.Regexp) *tengo.ImmutableMap {

if re.MatchString(s1) {
return tengo.TrueValue, nil
} else {
return tengo.FalseValue, nil
}
return tengo.FalseValue, nil
}, 1),
},

Expand Down
9 changes: 3 additions & 6 deletions stdlib/times.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,8 @@ var timesAfter = tengo.CheckAnyArgs(func(args ...tengo.Object) (tengo.Object, er

if t1.After(t2) {
return tengo.TrueValue, nil
} else {
return tengo.FalseValue, nil
}
return tengo.FalseValue, nil
}, 2)

var timesBefore = tengo.CheckAnyArgs(func(args ...tengo.Object) (tengo.Object, error) {
Expand All @@ -465,9 +464,8 @@ var timesBefore = tengo.CheckAnyArgs(func(args ...tengo.Object) (tengo.Object, e

if t1.Before(t2) {
return tengo.TrueValue, nil
} else {
return tengo.FalseValue, nil
}
return tengo.FalseValue, nil
}, 2)

var timesTimeYear = tengo.CheckAnyArgs(func(args ...tengo.Object) (tengo.Object, error) {
Expand Down Expand Up @@ -593,9 +591,8 @@ var timesIsZero = tengo.CheckAnyArgs(func(args ...tengo.Object) (tengo.Object, e

if t1.IsZero() {
return tengo.TrueValue, nil
} else {
return tengo.FalseValue, nil
}
return tengo.FalseValue, nil
}, 1)

var timesToLocal = tengo.CheckAnyArgs(func(args ...tengo.Object) (tengo.Object, error) {
Expand Down
3 changes: 1 addition & 2 deletions tengo.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ func ToString(i int, args ...Object) (string, error) {
}
if str, isStr := o.(*String); isStr {
return str.Value, nil
} else {
return o.String(), nil
}
return o.String(), nil
}

// ToStringSlice will try to convert object o to string slice value.
Expand Down
2 changes: 1 addition & 1 deletion vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (v *VM) Abort() {
}

// Run starts the execution.
func (v *VM) Run() (error) {
func (v *VM) Run() error {
// reset VM states
v.sp = 0
v.curFrame = &(v.frames[0])
Expand Down

0 comments on commit 8e10873

Please sign in to comment.