Skip to content

Commit a5a1099

Browse files
committed
chore: update linter
1 parent 4e91555 commit a5a1099

6 files changed

Lines changed: 37 additions & 2 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
env:
1717
GO_VERSION: stable
18-
GOLANGCI_LINT_VERSION: v2.0.1
18+
GOLANGCI_LINT_VERSION: v2.2.2
1919
CGO_ENABLED: 0
2020

2121
steps:

.golangci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ linters:
1616
- exhaustive
1717
- exhaustruct
1818
- forcetypeassert
19+
- funcorder
1920
- ireturn
2021
- lll
2122
- mnd
@@ -30,7 +31,7 @@ linters:
3031
- tparallel
3132
- varnamelen
3233
- wrapcheck
33-
- wsl
34+
- wsl # deprecated
3435
settings:
3536
depguard:
3637
rules:

builder/builder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (s StringsExpr) String() string {
6565
for _, val := range s {
6666
out = append(out, fmt.Sprintf("%q", val))
6767
}
68+
6869
return strings.Join(out, ",")
6970
}
7071

lib.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,21 @@ func GetStringMapValue(mapVal, keyVal interface{}) (interface{}, error) {
3232
if !ok {
3333
return nil, trace.BadParameter("only string keys are supported")
3434
}
35+
3536
switch m := mapVal.(type) {
3637
case map[string][]string:
3738
if len(m) == 0 {
3839
// to return nil with a proper type
3940
var n []string
4041
return n, nil
4142
}
43+
4244
return m[key], nil
4345
case map[string]string:
4446
if len(m) == 0 {
4547
return "", nil
4648
}
49+
4750
return m[key], nil
4851
default:
4952
return nil, trace.BadParameter("type %T is not supported", m)
@@ -67,14 +70,17 @@ func Equals(a interface{}, b interface{}) BoolPredicate {
6770
if !ok {
6871
return false
6972
}
73+
7074
if len(aval) != len(bval) {
7175
return false
7276
}
77+
7378
for i := range aval {
7479
if aval[i] != bval[i] {
7580
return false
7681
}
7782
}
83+
7884
return true
7985
default:
8086
return false
@@ -90,15 +96,18 @@ func Contains(a interface{}, b interface{}) BoolPredicate {
9096
if !ok {
9197
return false
9298
}
99+
93100
bval, ok := b.(string)
94101
if !ok {
95102
return false
96103
}
104+
97105
for _, v := range aval {
98106
if v == bval {
99107
return true
100108
}
101109
}
110+
102111
return false
103112
}
104113
}
@@ -141,6 +150,7 @@ func GetFieldByTag(ival interface{}, tagName string, fieldNames []string) (inter
141150
if val.Kind() != reflect.Struct {
142151
return nil, trace.NotFound("field name %v is not found", strings.Join(fieldNames, "."))
143152
}
153+
144154
fieldName := fieldNames[0]
145155
rest := fieldNames[1:]
146156

parse.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ func (p *predicateParser) evaluateArguments(nodes []ast.Expr) ([]interface{}, er
7272
if err != nil {
7373
return nil, trace.Wrap(err)
7474
}
75+
7576
out[i] = val
7677
}
78+
7779
return out, nil
7880
}
7981

@@ -123,6 +125,7 @@ func (p *predicateParser) evaluateExpr(n ast.Expr) (interface{}, error) {
123125
if err != nil {
124126
return nil, trace.Wrap(err)
125127
}
128+
126129
return val, nil
127130

128131
case *ast.Ident:
@@ -134,6 +137,7 @@ func (p *predicateParser) evaluateExpr(n ast.Expr) (interface{}, error) {
134137
if err != nil {
135138
return nil, trace.Wrap(err)
136139
}
140+
137141
return val, nil
138142

139143
case *ast.CallExpr:
@@ -181,6 +185,7 @@ func (p *predicateParser) getFunction(name string) (interface{}, error) {
181185
if !ok {
182186
return nil, trace.BadParameter("unsupported function: %s", name)
183187
}
188+
184189
return v, nil
185190
}
186191

@@ -195,6 +200,7 @@ func (p *predicateParser) joinPredicates(op token.Token, a, b interface{}) (inte
195200

196201
func (p *predicateParser) getJoinFunction(op token.Token) (interface{}, error) {
197202
var fn interface{}
203+
198204
switch op {
199205
case token.NOT:
200206
fn = p.d.Operators.NOT
@@ -215,9 +221,11 @@ func (p *predicateParser) getJoinFunction(op token.Token) (interface{}, error) {
215221
case token.NEQ:
216222
fn = p.d.Operators.NEQ
217223
}
224+
218225
if fn == nil {
219226
return nil, trace.BadParameter("%v is not supported", op)
220227
}
228+
221229
return fn, nil
222230
}
223231

@@ -228,13 +236,15 @@ func getIdentifier(node ast.Node) (string, error) {
228236
if !okIdent {
229237
return "", trace.BadParameter("expected selector identifier, got: %T", sexpr.X)
230238
}
239+
231240
return fmt.Sprintf("%s.%s", id.Name, sexpr.Sel.Name), nil
232241
}
233242

234243
id, ok := node.(*ast.Ident)
235244
if !ok {
236245
return "", trace.BadParameter("expected identifier, got: %T", node)
237246
}
247+
238248
return id.Name, nil
239249
}
240250

@@ -245,20 +255,23 @@ func literalToValue(a *ast.BasicLit) (interface{}, error) {
245255
if err != nil {
246256
return nil, trace.BadParameter("failed to parse argument: %s, error: %s", a.Value, err)
247257
}
258+
248259
return value, nil
249260

250261
case token.INT:
251262
value, err := strconv.Atoi(a.Value)
252263
if err != nil {
253264
return nil, trace.BadParameter("failed to parse argument: %s, error: %s", a.Value, err)
254265
}
266+
255267
return value, nil
256268

257269
case token.STRING:
258270
value, err := strconv.Unquote(a.Value)
259271
if err != nil {
260272
return nil, trace.BadParameter("failed to parse argument: %s, error: %s", a.Value, err)
261273
}
274+
262275
return value, nil
263276
}
264277

@@ -289,10 +302,12 @@ func callFunction(f interface{}, args []interface{}) (v interface{}, err error)
289302
if e == nil {
290303
return v, nil
291304
}
305+
292306
err, ok := e.(error)
293307
if !ok {
294308
return nil, trace.BadParameter("expected error as a second return value, got %T", e)
295309
}
310+
296311
return v, err
297312

298313
default:

parse_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ func (s *PredicateSuite) TestIndexExpr() {
320320
getProperty := func(mapVal, keyVal interface{}) (interface{}, error) {
321321
m := mapVal.(map[string]int)
322322
k := keyVal.(string)
323+
323324
return m[k], nil
324325
}
325326

@@ -360,17 +361,20 @@ func (s *PredicateSuite) TestIdentifierExpr() {
360361
case "num":
361362
return 2, nil
362363
}
364+
363365
return nil, nil
364366
}
365367
p := s.getParserWithOpts(getID, nil)
366368

367369
pr, err := p.Parse("Equals(firstSlice, firstSlice)")
368370
s.NoError(err)
371+
369372
fn := pr.(BoolPredicate)
370373
s.True(fn())
371374

372375
pr, err = p.Parse("Equals(a, a)")
373376
s.NoError(err)
377+
374378
fn = pr.(BoolPredicate)
375379
s.True(fn())
376380

@@ -382,6 +386,7 @@ func (s *PredicateSuite) TestIdentifierExpr() {
382386

383387
pr, err = p.Parse("Remainder(4) <= num")
384388
s.NoError(err)
389+
385390
fn2 := pr.(numberPredicate)
386391
s.True(fn2(2))
387392
s.False(fn2(3))
@@ -454,6 +459,7 @@ func (s *PredicateSuite) TestGetTagField() {
454459
expect interface{}
455460
err error
456461
}
462+
457463
testCases := []testCase{
458464
// nested field
459465
{tag: "json", val: val, fields: []string{"param", "key1"}, expect: val.Param.Key1},
@@ -492,6 +498,7 @@ func (s *PredicateSuite) TestUnhappyCases() {
492498
"Remainder(3) >> 3", // unsupported operator
493499
`Remainder(3) > "banana"`, // unsupported comparison type
494500
}
501+
495502
p := s.getParser()
496503
for _, expr := range cases {
497504
pr, err := p.Parse(expr)
@@ -542,6 +549,7 @@ func numberGT(m numberMapper, value interface{}) (numberPredicate, error) {
542549
default:
543550
return nil, fmt.Errorf("GT: unsupported argument type: %T", value)
544551
}
552+
545553
return func(v int) bool {
546554
switch val := value.(type) {
547555
case int:

0 commit comments

Comments
 (0)