Skip to content

Commit 883cf35

Browse files
author
Itay Donanhirsh
committed
remove govaluate
1 parent 913e680 commit 883cf35

File tree

5 files changed

+6
-99
lines changed

5 files changed

+6
-99
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/cluttercode/clutter
33
go 1.15
44

55
require (
6-
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible
76
github.com/fsnotify/fsnotify v1.4.9
87
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
98
github.com/go-git/go-git v4.7.0+incompatible

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1+
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
12
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
2-
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw=
3-
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
43
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
54
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
65
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
@@ -14,8 +13,6 @@ github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3
1413
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
1514
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
1615
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
17-
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
18-
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
1916
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ERFA1PUxfmGpolnw2v0bKOREu5ew=
2017
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
2118
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
@@ -67,6 +64,7 @@ go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
6764
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
6865
go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
6966
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
67+
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
7068
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
7169
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
7270
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
@@ -75,6 +73,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
7573
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
7674
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
7775
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
76+
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
7877
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
7978
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
8079
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
@@ -121,4 +120,5 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
121120
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
122121
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
123122
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
123+
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
124124
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=

internal/pkg/index/attrs.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,10 @@ import (
66

77
type Attrs map[string]string
88

9-
// used for [# govaluate-params #].
10-
type AttrsStruct struct{ as Attrs }
11-
12-
func (a Attrs) ToStruct() *AttrsStruct {
13-
return &AttrsStruct{as: a}
14-
}
15-
169
func AttrToString(k, v string) string {
1710
if v == "" {
1811
return k
1912
}
2013

2114
return fmt.Sprintf("%s=%s", k, v)
2215
}
23-
24-
func (a AttrsStruct) Has(k string) bool {
25-
_, ok := a.as[k]
26-
return ok
27-
}

internal/pkg/linter/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ type Rule struct {
55
PathGlob string `json:"path-glob"`
66
PathRegexp string `json:"path-re"`
77
Shell []string `json:"shell"`
8-
Expr string `json:"expr"`
98
}
109

1110
type Config struct {

internal/pkg/linter/linter.go

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"regexp"
99
"strings"
1010

11-
"github.com/Knetic/govaluate"
1211
"github.com/gobwas/glob"
1312
"go.uber.org/zap"
1413

@@ -35,12 +34,8 @@ func (ir *internalRule) init(l *Linter, r Rule) error {
3534
return fmt.Errorf("path-pattern and path-re are mutuallye exclusive")
3635
}
3736

38-
if len(r.Shell) != 0 && r.Expr != "" {
39-
return fmt.Errorf("shell and expr are mutually exclusive")
40-
}
41-
42-
if len(r.Shell) == 0 && r.Expr == "" {
43-
return fmt.Errorf("either shell or expr are required")
37+
if len(r.Shell) == 0 {
38+
return fmt.Errorf("shell is expected")
4439
}
4540

4641
ir.checkPath = func(string) bool { return true }
@@ -75,59 +70,6 @@ func (ir *internalRule) init(l *Linter, r Rule) error {
7570
}
7671
}
7772

78-
if expr := r.Expr; expr != "" {
79-
funcs := map[string]govaluate.ExpressionFunction{
80-
"re_match": func(vs ...interface{}) (interface{}, error) {
81-
if len(vs) != 2 {
82-
return nil, fmt.Errorf("expecting two arguments")
83-
}
84-
85-
p, ok := vs[0].(string)
86-
if !ok {
87-
return nil, fmt.Errorf("pattern argument must be a string")
88-
}
89-
90-
s, ok := vs[1].(string)
91-
if !ok {
92-
return nil, fmt.Errorf("text argument must be a string")
93-
}
94-
95-
return regexp.MatchString(p, s)
96-
},
97-
"glob_match": func(vs ...interface{}) (interface{}, error) {
98-
if len(vs) != 2 {
99-
return nil, fmt.Errorf("expecting two arguments")
100-
}
101-
102-
p, ok := vs[0].(string)
103-
if !ok {
104-
return nil, fmt.Errorf("pattern argument must be a string")
105-
}
106-
107-
s, ok := vs[1].(string)
108-
if !ok {
109-
return nil, fmt.Errorf("text argument must be a string")
110-
}
111-
112-
g, err := glob.Compile(p)
113-
if err != nil {
114-
return nil, err
115-
}
116-
117-
return g.Match(s), nil
118-
},
119-
}
120-
121-
evalexpr, err := govaluate.NewEvaluableExpressionWithFunctions(expr, funcs)
122-
if err != nil {
123-
return fmt.Errorf("expr: %w", err)
124-
}
125-
126-
ir.eval = func(_ context.Context, ent *index.Entry) (bool, error) {
127-
return l.eval(evalexpr, ent)
128-
}
129-
}
130-
13173
if cmd := r.Shell; len(cmd) > 0 {
13274
ir.eval = func(ctx context.Context, ent *index.Entry) (bool, error) {
13375
return l.shell(ctx, cmd, ent)
@@ -245,24 +187,3 @@ func (l *Linter) shell(ctx context.Context, cmdParts []string, ent *index.Entry)
245187

246188
return true, nil
247189
}
248-
249-
func (l *Linter) eval(eval *govaluate.EvaluableExpression, ent *index.Entry) (bool, error) {
250-
l.z.Infow("checking expression")
251-
252-
res, err := eval.Evaluate(map[string]interface{}{"name": ent.Name, "path": ent.Loc.Path, "attrs": ent.Attrs.ToStruct()}) // [# govaluate-params #]
253-
if err != nil {
254-
l.z.Errorw("eval error", "err", err)
255-
return false, err
256-
}
257-
258-
l.z.Infow("returned", "res", res)
259-
260-
pass, ok := res.(bool)
261-
262-
if !ok {
263-
l.z.Errorw("non-boolean result", "res", res)
264-
return false, fmt.Errorf("expression result is not a boolean: %v", res)
265-
}
266-
267-
return pass, nil
268-
}

0 commit comments

Comments
 (0)