Skip to content

Commit

Permalink
Merge pull request #48 from rokostik/golangci-lint
Browse files Browse the repository at this point in the history
Add new linters
  • Loading branch information
refaktor authored Dec 8, 2023
2 parents 9ab617d + 3bd9f8d commit cf39455
Show file tree
Hide file tree
Showing 30 changed files with 141 additions and 162 deletions.
10 changes: 5 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ linters:
- depguard
- dogsled
# - dupl
# - errcheck
- errcheck
- exportloopref
# - funlen
- gocheckcompilerdirectives
Expand All @@ -99,9 +99,9 @@ linters:
- goprintffuncname
- gosec
# - gosec -exclude=G504
# - gosimple
- gosimple
- govet
# - ineffassign
- ineffassign
# - lll
- misspell
# - nakedret
Expand All @@ -114,7 +114,7 @@ linters:
- unconvert
# l1 - unparam
# - unused
# - whitespace
- whitespace

# don't enable:
# - asciicheck
Expand Down Expand Up @@ -168,4 +168,4 @@ run:
# - internal/cache # extracted from Go code
# - internal/renameio # extracted from Go code
# - internal/robustio # extracted from Go code


2 changes: 1 addition & 1 deletion env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (i RyeCtx) GetKind() int {
func (e RyeCtx) GetWords(idxs Idxs) Block {
objs := make([]Object, len(e.state))
idx := 0
for k, _ := range e.state {
for k := range e.state {
objs[idx] = String{idxs.GetWord(k)}
idx += 1
}
Expand Down
13 changes: 6 additions & 7 deletions env/object.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ func (i Tagword) Trace(msg string) {
}

func (i Tagword) ToWord() Word {
return Word{i.Index}
return Word(i)
}

func (i Tagword) GetKind() int {
Expand Down Expand Up @@ -646,7 +646,7 @@ func (i Xword) Trace(msg string) {
}

func (i Xword) ToWord() Word {
return Word{i.Index}
return Word(i)
}

func (i Xword) GetKind() int {
Expand Down Expand Up @@ -688,7 +688,7 @@ func (i EXword) Trace(msg string) {
}

func (i EXword) ToWord() Word {
return Word{i.Index}
return Word(i)
}

func (i EXword) GetKind() int {
Expand Down Expand Up @@ -730,7 +730,7 @@ func (i Kindword) Trace(msg string) {
}

func (i Kindword) ToWord() Word {
return Word{i.Index}
return Word(i)
}

func (i Kindword) GetKind() int {
Expand Down Expand Up @@ -772,7 +772,7 @@ func (i Getword) Trace(msg string) {
}

func (i Getword) ToWord() Word {
return Word{i.Index}
return Word(i)
}

func (i Getword) GetKind() int {
Expand Down Expand Up @@ -814,7 +814,7 @@ func (i Genword) Trace(msg string) {
}

func (i Genword) ToWord() Word {
return Word{i.Index}
return Word(i)
}

func (i Genword) GetKind() int {
Expand Down Expand Up @@ -1202,7 +1202,6 @@ func NewCPath2(w1 Word, w2 Word) *CPath {
cp.Word1 = w1
cp.Word2 = w2
return &cp

}
func NewCPath3(w1 Word, w2 Word, w3 Word) *CPath {
var cp CPath
Expand Down
5 changes: 0 additions & 5 deletions env/spreadsheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,10 @@ func (s Spreadsheet) Sum_Just(name string) (float64, error) {
sumf += v
case int64:
sum += v
break
case Integer:
sum += v.Value
break
case Decimal:
sumf += v.Value
break
default:
fmt.Println("row--->")
fmt.Println(reflect.TypeOf(v))
Expand All @@ -198,15 +195,13 @@ func (s Spreadsheet) NRows() int {
}

func (s Spreadsheet) Columns(ps *ProgramState, names []string) Object {

idxs := make([]int, len(names))
for name := range names {
idx := IndexOfString(names[name], s.Cols)
if idx == -1 {
return makeError(ps, "Col not found")
}
idxs[name] = idx

}
nspr := NewSpreadsheet(names)
if s.RawMode {
Expand Down
21 changes: 14 additions & 7 deletions evaldo/builtins.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"strings"
"time"

"golang.org/x/sync/errgroup"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
Expand Down Expand Up @@ -1711,7 +1712,7 @@ var builtins = map[string]*env.Builtin{
foundany = true
}
case env.Void:
if foundany == false {
if !foundany {
doblk = true
}
default:
Expand Down Expand Up @@ -1949,24 +1950,31 @@ var builtins = map[string]*env.Builtin{
r, w, _ := os.Pipe()
os.Stdout = w

// print()

ser := ps.Ser
ps.Ser = bloc.Series
EvalBlock(ps)
ps.Ser = ser

outC := make(chan string)
g := errgroup.Group{}
// copy the output in a separate goroutine so printing can't block indefinitely
go func() {
g.Go(func() error {
var buf bytes.Buffer
io.Copy(&buf, r)
_, err := io.Copy(&buf, r)
if err != nil {
return err
}
outC <- buf.String()
}()
return nil
})

// back to normal state
w.Close()
os.Stdout = old // restoring the real stdout

if err := g.Wait(); err != nil {
return MakeBuiltinError(ps, fmt.Sprintf("Error reading stdout: %v", err), "capture-stdout")
}
out := <-outC

// reading our temp stdout
Expand Down Expand Up @@ -6413,7 +6421,6 @@ func registerBuiltin(ps *env.ProgramState, word string, builtin env.Builtin) {
if builtin.Pure {
ps.PCtx.Set(idxw, builtin)
}

} else {
ps.Gen.Set(idxk, idxw, builtin)
}
Expand Down
4 changes: 1 addition & 3 deletions evaldo/builtins_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func CopyMap(m map[string]interface{}) map[string]interface{} {
}

func Conversion_EvalBlockCtx(ps *env.ProgramState, vals env.RyeCtx) env.Object {

var key int

out := env.NewEnv(nil)
Expand All @@ -46,7 +45,6 @@ func Conversion_EvalBlockCtx(ps *env.ProgramState, vals env.RyeCtx) env.Object {
}

func Conversion_EvalBlockDict(ps *env.ProgramState, vals env.Dict) env.Object {

//var outD map[string]interface{}
outD := make(map[string]interface{})
object := ps.Ser.Peek()
Expand Down Expand Up @@ -83,7 +81,7 @@ func Conversion_EvalBlockDict(ps *env.ProgramState, vals env.Dict) env.Object {
val = nil
case env.Tagword:
srcKey := ps.Idx.GetWord(obj.Index)
valY, _ := vals.Data[ps.Idx.GetWord(obj.Index)]
valY := vals.Data[ps.Idx.GetWord(obj.Index)]
val = JsonToRye(valY)
if srcKey != key {
delete(outD, srcKey)
Expand Down
4 changes: 1 addition & 3 deletions evaldo/builtins_eyr.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func (s *EyrStack) Pop() env.Object {
}

func Eyr_CallBuiltin(bi env.Builtin, ps *env.ProgramState, arg0_ env.Object, toLeft bool, stack *EyrStack) *env.ProgramState {

arg0 := bi.Cur0 //env.Object(bi.Cur0)
arg1 := bi.Cur1

Expand All @@ -83,7 +82,6 @@ func Eyr_CallBuiltin(bi env.Builtin, ps *env.ProgramState, arg0_ env.Object, toL
//fmt.Println(ps.Res)

arg1 = stack.Pop()

}
ps.Res = bi.Fn(ps, arg0, arg1, nil, nil, nil)

Expand Down Expand Up @@ -132,7 +130,7 @@ func Eyr_EvalWord(es *env.ProgramState, word env.Object, leftVal env.Object, toL
} else {
trace("****34")
es.ErrorFlag = true
if es.FailureFlag == false {
if !es.FailureFlag {
es.Res = *env.NewError2(5, "Word not found: "+word.Inspect(*es.Idx))
}
return es
Expand Down
35 changes: 29 additions & 6 deletions evaldo/builtins_goroutines.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/jinzhu/copier"
"golang.org/x/sync/errgroup"
)

func strimpg() { fmt.Println("") }
Expand Down Expand Up @@ -39,15 +40,26 @@ var Builtins_goroutines = map[string]*env.Builtin{
case env.Object:
switch handler := arg1.(type) {
case env.Function:
go func() {
g := errgroup.Group{}
g.Go(func() error {
ps.FailureFlag = false
ps.ErrorFlag = false
ps.ReturnFlag = false
psTemp := env.ProgramState{}
copier.Copy(&psTemp, &ps)
err := copier.Copy(&psTemp, &ps)
if err != nil {
ps.FailureFlag = true
ps.ErrorFlag = true
ps.ReturnFlag = true
return fmt.Errorf("failed to copy ps: %w", err)
}
CallFunction(handler, &psTemp, arg, false, nil)
// CallFunctionArgs2(handler, &psTemp, arg, *env.NewNative(psTemp.Idx, "asd", "Go-server-context"), nil)
}()
return nil
})
if err := g.Wait(); err != nil {
return MakeBuiltinError(ps, err.Error(), "go-with")
}
return arg0
default:
ps.FailureFlag = true
Expand All @@ -66,15 +78,26 @@ var Builtins_goroutines = map[string]*env.Builtin{
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch handler := arg0.(type) {
case env.Function:
go func() {
g := errgroup.Group{}
g.Go(func() error {
ps.FailureFlag = false
ps.ErrorFlag = false
ps.ReturnFlag = false
psTemp := env.ProgramState{}
copier.Copy(&psTemp, &ps)
err := copier.Copy(&psTemp, &ps)
if err != nil {
ps.FailureFlag = true
ps.ErrorFlag = true
ps.ReturnFlag = true
return fmt.Errorf("failed to copy ps: %w", err)
}
CallFunction(handler, &psTemp, nil, false, nil)
// CallFunctionArgs2(handler, &psTemp, arg, *env.NewNative(psTemp.Idx, "asd", "Go-server-context"), nil)
}()
return nil
})
if err := g.Wait(); err != nil {
return MakeBuiltinError(ps, err.Error(), "go")
}
return arg0
default:
ps.FailureFlag = true
Expand Down
1 change: 0 additions & 1 deletion evaldo/builtins_io.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ func __stat(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Obj
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "__stat")

}
}

Expand Down
1 change: 1 addition & 0 deletions evaldo/builtins_nats_not.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !b_nats
// +build !b_nats

package evaldo
Expand Down
4 changes: 0 additions & 4 deletions evaldo/builtins_spreadsheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,27 +409,23 @@ func AddIndex(ps *env.ProgramState, s env.Spreadsheet, column env.Word) env.Obje
}

func SortByColumn(ps *env.ProgramState, s *env.Spreadsheet, name string) {

idx := env.IndexOfString(name, s.Cols)

compareCol := func(i, j int) bool {
return greaterThanNew(s.Rows[j].Values[idx].(env.Object), s.Rows[i].Values[idx].(env.Object))
}

sort.Slice(s.Rows, compareCol)

}

func SortByColumnDesc(ps *env.ProgramState, s *env.Spreadsheet, name string) {

idx := env.IndexOfString(name, s.Cols)

compareCol := func(i, j int) bool {
return greaterThanNew(s.Rows[i].Values[idx].(env.Object), s.Rows[j].Values[idx].(env.Object))
}

sort.Slice(s.Rows, compareCol)

}

func WhereEquals(ps *env.ProgramState, s env.Spreadsheet, name string, val interface{}) env.Object {
Expand Down
5 changes: 1 addition & 4 deletions evaldo/builtins_stackless.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
// če je builtin potem pusha trenuten frame na stack in kreira novega

func Stck_CallBuiltin(bi env.Builtin, ps *env.ProgramState, arg0_ env.Object, toLeft bool) *env.ProgramState {

evalExprFn := EvalExpression2
arg0 := bi.Cur0 //env.Object(bi.Cur0)
arg1 := bi.Cur1
Expand All @@ -32,7 +31,6 @@ func Stck_CallBuiltin(bi env.Builtin, ps *env.ProgramState, arg0_ env.Object, to
arg0 = ps.Res
}
if bi.Argsn > 1 && bi.Cur1 == nil {

evalExprFn(ps, true) // <---- THESE DETERMINE IF IT CONSUMES WHOLE EXPRESSION OR NOT IN CASE OF PIPEWORDS .. HM*... MAYBE WOULD COULD HAVE A WORD MODIFIER?? a: 2 |add 5 a:: 2 |add 5 print* --TODO

if checkFlagsBi(bi, ps, 1) {
Expand All @@ -44,7 +42,6 @@ func Stck_CallBuiltin(bi env.Builtin, ps *env.ProgramState, arg0_ env.Object, to
//fmt.Println(ps.Res)

arg1 = ps.Res

}
ps.Res = bi.Fn(ps, arg0, arg1, nil, nil, nil)
return ps
Expand Down Expand Up @@ -88,7 +85,7 @@ func Stck_EvalWord(ps *env.ProgramState, word env.Object, leftVal env.Object, to
} else {
trace("****34")
ps.ErrorFlag = true
if ps.FailureFlag == false {
if !ps.FailureFlag {
ps.Res = *env.NewError2(5, "Word not found: "+word.Inspect(*ps.Idx))
fmt.Println("Error: Not known type")
}
Expand Down
1 change: 0 additions & 1 deletion evaldo/builtins_structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
// { _ { <person> { * [ -> 1 |print , -> 2 |print ] } } }

func load_structures_Dict(ps *env.ProgramState, block env.Block) (env.Dict, *env.Error) {

var keys []string

data := make(map[string]interface{})
Expand Down
Loading

0 comments on commit cf39455

Please sign in to comment.