MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Validate

Method Validate

cel/validator.go:291–307  ·  view source on GitHub ↗

Validate searches the AST for uses of a given function name with a constant argument and performs a check on whether the argument is a valid literal value.

(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues)

Source from the content-addressed store, hash-verified

289// Validate searches the AST for uses of a given function name with a constant argument and performs a check
290// on whether the argument is a valid literal value.
291func (v formatValidator) Validate(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues) {
292 root := ast.NavigateAST(a)
293 funcCalls := ast.MatchDescendants(root, ast.FunctionMatcher(v.funcName))
294 for _, call := range funcCalls {
295 callArgs := call.AsCall().Args()
296 if len(callArgs) <= v.argNum {
297 continue
298 }
299 litArg := callArgs[v.argNum]
300 if litArg.Kind() != ast.LiteralKind {
301 continue
302 }
303 if err := v.check(e, call, litArg); err != nil {
304 iss.ReportErrorAtID(litArg.ID(), "invalid %s argument", v.funcName)
305 }
306 }
307}
308
309func evalCall(env *Env, call, arg ast.Expr) error {
310 ast := &Ast{impl: ast.NewAST(call, ast.NewSourceInfo(nil))}

Callers

nothing calls this directly

Calls 9

NavigateASTFunction · 0.92
MatchDescendantsFunction · 0.92
FunctionMatcherFunction · 0.92
checkMethod · 0.80
ArgsMethod · 0.65
AsCallMethod · 0.65
KindMethod · 0.65
ReportErrorAtIDMethod · 0.65
IDMethod · 0.65

Tested by

no test coverage detected