Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
strategy:
matrix:
go-version:
- '1.23' # named in go.mod
- 'oldstable'
- 'stable'
env:
Expand All @@ -48,7 +47,7 @@ jobs:
go-version: ${{ matrix.go-version }}
cache: true
- name: Run golangci-lint
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20
- uses: autero1/action-gotestsum@7263b9d73912eec65f46337689e59fac865c425f # v2.0.0
with:
gotestsum_version: 1.9.0
Expand All @@ -65,4 +64,3 @@ jobs:
run: go tool cover -func=/tmp/coverage.out
- name: Build go
run: go build ./...

2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.23
1.24
22 changes: 19 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
# Copyright IBM Corp. 2019, 2025
# SPDX-License-Identifier: MPL-2.0

version: "2"
linters:
enable:
- errcheck
output_format: colored-line-number
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
10 changes: 5 additions & 5 deletions evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func derefType(rtype reflect.Type) reflect.Type {

func doMatchMatches(expression *grammar.MatchExpression, value reflect.Value) (bool, error) {
if !value.Type().ConvertibleTo(byteSliceTyp) {
return false, fmt.Errorf("Value of type %s is not convertible to []byte", value.Type())
return false, fmt.Errorf("value of type %s is not convertible to []byte", value.Type())
}

var re *regexp.Regexp
Expand All @@ -83,7 +83,7 @@ func doMatchMatches(expression *grammar.MatchExpression, value reflect.Value) (b
var err error
re, err = regexp.Compile(expression.Value.Raw)
if err != nil {
return false, fmt.Errorf("Failed to compile regular expression %q: %v", expression.Value.Raw, err)
return false, fmt.Errorf("failed to compile regular expression %q: %v", expression.Value.Raw, err)
}
expression.Value.Converted = re
}
Expand Down Expand Up @@ -181,7 +181,7 @@ func doMatchIn(expression *grammar.MatchExpression, value reflect.Value) (bool,
return strings.Contains(value.String(), matchValue.(string)), nil

default:
return false, fmt.Errorf("Cannot perform in/contains operations on type %s for selector: %q", kind, expression.Selector)
return false, fmt.Errorf("cannot perform in/contains operations on type %s for selector: %q", kind, expression.Selector)
}
}

Expand Down Expand Up @@ -370,7 +370,7 @@ func evaluateMatchExpression(expression *grammar.MatchExpression, datum interfac
}
return false, err
default:
return false, fmt.Errorf("Invalid match operation: %d", expression.Operator)
return false, fmt.Errorf("invalid match operation: %d", expression.Operator)
}
}

Expand Down Expand Up @@ -484,5 +484,5 @@ func evaluate(ast grammar.Expression, datum interface{}, opt ...Option) (bool, e
case *grammar.CollectionExpression:
return evaluateCollectionExpression(node, datum, opt...)
}
return false, fmt.Errorf("Invalid AST node")
return false, fmt.Errorf("invalid AST node")
}
4 changes: 1 addition & 3 deletions evaluate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ var evaluateTests map[string]expressionTest = map[string]expressionTest{
{expression: "Nested.MapOfStructs is empty or (Nested.SliceOfInts contains 7 and 9 in Nested.SliceOfInts)", result: true, benchQuick: true},
{expression: "Nested.SliceOfStructs.0.X == 1", result: true},
{expression: "Nested.SliceOfStructs.0.Y == 4", result: false},
{expression: "Map in Nested", result: false, err: "Cannot perform in/contains operations on type struct for selector: \"Nested\""},
{expression: "Map in Nested", result: false, err: "cannot perform in/contains operations on type struct for selector: \"Nested\""},
{expression: `"foobar" in "/Nested/SliceOfInfs"`, result: true},
{expression: `"1" in "/Nested/SliceOfInfs"`, result: true},
{expression: `"2" in "/Nested/SliceOfInfs"`, result: false},
Expand Down Expand Up @@ -365,14 +365,12 @@ func TestEvaluate(t *testing.T) {
t.Parallel()
for name, tcase := range evaluateTests {
// capture these values in the closure
name := name
tcase := tcase
t.Run(name, func(t *testing.T) {
t.Parallel()

for i, expTest := range tcase.expressions {
// capture these values in the closure
expTest := expTest
t.Run(fmt.Sprintf("#%d - %s", i, expTest.expression), func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion examples/expr-eval/expr-eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Internal struct {
Hidden int `bexpr:"-"`

// Unexported fields are not available for use by the evaluator
unexported int
unexported int //nolint:unused
}

type Matchable struct {
Expand Down
6 changes: 3 additions & 3 deletions filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func CreateFilter(expression string) (*Filter, error) {
}
exp, err := CreateEvaluator(expression)
if err != nil {
return nil, fmt.Errorf("Failed to create boolean expression evaluator: %v", err)
return nil, fmt.Errorf("failed to create boolean expression evaluator: %v", err)
}

return &Filter{
Expand Down Expand Up @@ -76,7 +76,7 @@ func (f *Filter) Execute(data interface{}) (interface{}, error) {
item := rvalue.MapIndex(mapKey)

if !item.CanInterface() {
return nil, fmt.Errorf("Map value cannot be used")
return nil, fmt.Errorf("map value cannot be used")
}

result, err := f.evaluator.Evaluate(item.Interface())
Expand All @@ -91,6 +91,6 @@ func (f *Filter) Execute(data interface{}) (interface{}, error) {

return newMap.Interface(), nil
default:
return nil, fmt.Errorf("Only slices, arrays and maps are filterable")
return nil, fmt.Errorf("only slices, arrays and maps are filterable")
}
}