Skip to content

Commit

Permalink
disabled one linter and then fixed all that golangci-lint reported
Browse files Browse the repository at this point in the history
  • Loading branch information
refaktor committed Dec 7, 2023
1 parent af18452 commit 22382ba
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 33 deletions.
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ linters:
# - stylecheck
- typecheck
- unconvert
- unparam
# l1 - unparam
# - unused
# - whitespace

Expand All @@ -136,6 +136,8 @@ issues:
exclude-rules:
- text: "evaldo"
linters: typecheck
- text: "net/http/cgi" # REASON: only important for Go 1.6 and lower, Rye requires go1.8 or higher as defined in go.mod
linters: gosec

# - path: _test\.go
# linters:
Expand Down
23 changes: 14 additions & 9 deletions evaldo/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (
"strconv"
"strings"
"time"

"golang.org/x/text/cases"
"golang.org/x/text/language"
)

func ss() {
Expand Down Expand Up @@ -4802,7 +4805,9 @@ var builtins = 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 s1 := arg0.(type) {
case env.String:
return *env.NewString(strings.Title(s1.Value))

english := cases.Title(language.English)
return *env.NewString(english.String(s1.Value))
default:
return MakeArgError(ps, 1, []env.Type{env.StringType}, "capitalize")
}
Expand Down Expand Up @@ -5204,24 +5209,24 @@ var builtins = map[string]*env.Builtin{
if len(s1.Series.S) < numVal {
numVal = len(s1.Series.S)
}
return *env.NewBlock(*env.NewTSeries(s1.Series.S[len(s1.Series.S)-int(numVal):]))
return *env.NewBlock(*env.NewTSeries(s1.Series.S[len(s1.Series.S)-numVal:]))
case env.List:
if len(s1.Data) == 0 {
return *env.NewList([]interface{}{})
}
if len(s1.Data) < int(numVal) {
if len(s1.Data) < numVal {
numVal = len(s1.Data)
}
return *env.NewList(s1.Data[len(s1.Data)-int(numVal):])
return *env.NewList(s1.Data[len(s1.Data)-numVal:])
case env.String:
str := []rune(s1.Value)
if len(str) == 0 {
return *env.NewString("")
}
if len(str) < int(numVal) {
if len(str) < numVal {
numVal = len(str)
}
return *env.NewString(string(str[len(str)-int(numVal):]))
return *env.NewString(string(str[len(str)-numVal:]))
default:
return MakeArgError(ps, 1, []env.Type{env.BlockType, env.ListType, env.StringType}, "tail")
}
Expand Down Expand Up @@ -5331,7 +5336,7 @@ var builtins = map[string]*env.Builtin{
if len(s1.Data) == 0 {
return *env.NewList([]interface{}{})
}
if len(s1.Data) < int(numVal) {
if len(s1.Data) < numVal {
numVal = len(s1.Data)
}
return *env.NewList(s1.Data[0:numVal])
Expand All @@ -5340,7 +5345,7 @@ var builtins = map[string]*env.Builtin{
if len(str) == 0 {
return *env.NewString("")
}
if len(str) < int(numVal) {
if len(str) < numVal {
numVal = len(str)
}
return *env.NewString(string(str[0:numVal]))
Expand Down Expand Up @@ -6189,7 +6194,7 @@ var builtins = map[string]*env.Builtin{
}
fmt.Println("out:", outb.String(), "err:", errb.String()) */

r := exec.Command("/bin/bash", "-c", s0.Value)
r := exec.Command("/bin/bash", "-c", s0.Value) //nolint: gosec
// stdout, stderr := r.Output()
var outb, errb bytes.Buffer
r.Stdout = &outb
Expand Down
4 changes: 2 additions & 2 deletions evaldo/builtins_eyr.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ 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 := env.Object(bi.Cur0) //env.Object(bi.Cur0)
arg1 := env.Object(bi.Cur1)
arg0 := bi.Cur0 //env.Object(bi.Cur0)
arg1 := bi.Cur1

if bi.Argsn > 0 && bi.Cur0 == nil {
//fmt.Println(" ARG 1 ")
Expand Down
31 changes: 26 additions & 5 deletions evaldo/builtins_io.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package evaldo
import (
"bufio"
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
Expand All @@ -14,6 +15,7 @@ import (
"path/filepath"
"rye/env"
"strings"
"time"

"net/http"
"net/http/cgi"
Expand Down Expand Up @@ -221,7 +223,7 @@ func __fs_write(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env
}
return arg1
case env.Native:
err := ioutil.WriteFile(f.GetPath(), []byte(s.Value.([]byte)), 0600)
err := ioutil.WriteFile(f.GetPath(), s.Value.([]byte), 0600)
if err != nil {
ps.FailureFlag = true
return MakeBuiltinError(ps, err.Error(), "__fs_write")
Expand Down Expand Up @@ -277,7 +279,14 @@ func __stat(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Obj
func __https_s_get(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch f := arg0.(type) {
case env.Uri:
resp, err := http.Get(f.GetProtocol() + "://" + f.GetPath())
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Second*10))
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, f.GetProtocol()+"://"+f.GetPath(), nil)
if err != nil {
ps.FailureFlag = true
return *env.NewError(err.Error())
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
ps.FailureFlag = true
return *env.NewError(err.Error())
Expand Down Expand Up @@ -324,12 +333,23 @@ func __http_s_post(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2
// TODO -- add other cases
// fmt.Println("BEFORE")

resp, err := http.Post(f.GetProtocol()+"://"+f.GetPath(), tt, bytes.NewBufferString(d.Value))
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Second*10))
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, f.GetProtocol()+"://"+f.GetPath(), bytes.NewBufferString(d.Value))
if err != nil {
// fmt.Println("ERR")
ps.FailureFlag = true
return MakeBuiltinError(ps, err.Error(), "__http_s_post")
return *env.NewError(err.Error())
}
req.Header.Set("Content-Type", tt)
resp, err := http.DefaultClient.Do(req)
if err != nil {
ps.FailureFlag = true
return *env.NewError(err.Error())
}
// Print the HTTP Status Code and Status Name
//mt.Println("HTTP Response Status:", resp.StatusCode, http.StatusText(resp.StatusCode))

// resp, err := http.Post(f.GetProtocol()+"://"+f.GetPath(), tt, bytes.NewBufferString(d.Value))

// Print the HTTP Status Code and Status Name
// fmt.Println("HTTP Response Status:", resp.StatusCode, http.StatusText(resp.StatusCode))
Expand Down Expand Up @@ -504,6 +524,7 @@ func __https_request__do(ps *env.ProgramState, arg0 env.Object, arg1 env.Object,
case env.Native:
client := &http.Client{}
resp, err := client.Do(req.Value.(*http.Request))
defer resp.Body.Close()
if err != nil {
return MakeBuiltinError(ps, err.Error(), "__https_request__do")
}
Expand Down
4 changes: 2 additions & 2 deletions evaldo/builtins_stackless.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
func Stck_CallBuiltin(bi env.Builtin, ps *env.ProgramState, arg0_ env.Object, toLeft bool) *env.ProgramState {

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

if bi.Argsn > 0 && bi.Cur0 == nil {
//fmt.Println(" ARG 1 ")
Expand Down
4 changes: 2 additions & 2 deletions evaldo/builtins_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ func evalDecimal(val interface{}) (interface{}, env.Object) {
if e != nil {
return val, *env.NewString("not decimal")
} else {
return *env.NewDecimal(float64(v)), nil
return *env.NewDecimal(v), nil
}
case env.String:
v, e := strconv.ParseFloat(val1.Value, 64)
if e != nil {
return val, *env.NewString("not decimal")
} else {
return *env.NewDecimal(float64(v)), nil
return *env.NewDecimal(v), nil
}
default:
return val, *env.NewString("not decimal")
Expand Down
22 changes: 11 additions & 11 deletions evaldo/evaldo.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,11 +727,11 @@ func CallBuiltin(bi env.Builtin, ps *env.ProgramState, arg0_ env.Object, toLeft
ps.Ser.SetPos(pospos)*/

// let's try to make it without array allocation and without variadic arguments that also maybe actualizes splice
arg0 := env.Object(bi.Cur0) //env.Object(bi.Cur0)
arg1 := env.Object(bi.Cur1)
arg2 := env.Object(bi.Cur2)
arg3 := env.Object(bi.Cur3)
arg4 := env.Object(bi.Cur4)
arg0 := bi.Cur0 //env.Object(bi.Cur0)
arg1 := bi.Cur1
arg2 := bi.Cur2
arg3 := bi.Cur3
arg4 := bi.Cur4

// This is just experiment if we could at currying provide ?fn or ?builtin and
// with arity of 0 and it would get executed at call time. So closure would become
Expand Down Expand Up @@ -875,23 +875,23 @@ func DirectlyCallBuiltin(ps *env.ProgramState, bi env.Builtin, a0 env.Object, a1
var arg1 env.Object

if bi.Cur0 != nil {
arg0 = env.Object(bi.Cur0)
arg0 = bi.Cur0
if bi.Cur1 != nil {
arg1 = env.Object(bi.Cur1)
arg1 = bi.Cur1
} else {
arg1 = a0
}
} else {
arg0 = a0
if bi.Cur1 != nil {
arg1 = env.Object(bi.Cur1)
arg1 = bi.Cur1
} else {
arg1 = a1
}
}
arg2 := env.Object(bi.Cur2)
arg3 := env.Object(bi.Cur3)
arg4 := env.Object(bi.Cur4)
arg2 := bi.Cur2
arg3 := bi.Cur3
arg4 := bi.Cur4
return bi.Fn(ps, arg0, arg1, arg2, arg3, arg4)
}

Expand Down
2 changes: 1 addition & 1 deletion evaldo/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func DoRyeRepl(es *env.ProgramState, showResults bool) {
//fmt.Println(lineReal)
block, genv := loader.LoadString(line2, false)
block1 := block.(env.Block)
es := env.AddToProgramState(es, block1.Series, genv)
es = env.AddToProgramState(es, block1.Series, genv)
EvalBlockInj(es, prevResult, true)

if arg != "" {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ require (
go.mongodb.org/mongo-driver v1.13.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
Expand Down

0 comments on commit 22382ba

Please sign in to comment.