Open niccolocast opened 1 month ago
Hi @niccolocast, I have looked at your question and checked in the nikunjy/rules
what was possible to do to validate a rule.
I came to this simple solution that works partially:
func eval(rule string) error {
ev, err := parser.NewEvaluator(rule)
if err != nil {
return err
}
_, err = ev.Process(map[string]interface{}{})
return err
}
If the eval
function error it means that the rule is invalid.
That being said it does not catch all the use-cases, your example is considered valid while it should not.
To have a bit more info, I have opened this issue https://github.com/nikunjy/rules/issues/41 on the nikunjy/rules
repository. If I know more about it I will let you know.
Your question
Is query syntax validation without evaluation possible? For example calling a function that returns an error if a user tries to add a malformed rule query like
((env eq "pro") and (company eq "go-feature-flag")