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

Method Validate

cel/validator.go:301–317  ·  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

299// Validate searches the AST for uses of a given function name with a constant argument and performs a check
300// on whether the argument is a valid literal value.
301func (v formatValidator) Validate(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues) {
302 root := ast.NavigateAST(a)
303 funcCalls := ast.MatchDescendants(root, ast.FunctionMatcher(v.funcName))
304 for _, call := range funcCalls {
305 callArgs := call.AsCall().Args()
306 if len(callArgs) <= v.argNum {
307 continue
308 }
309 litArg := callArgs[v.argNum]
310 if litArg.Kind() != ast.LiteralKind {
311 continue
312 }
313 if err := v.check(e, call, litArg); err != nil {
314 iss.ReportErrorAtID(litArg.ID(), "invalid %s argument", v.funcName)
315 }
316 }
317}
318
319func evalCall(env *Env, call, arg ast.Expr) error {
320 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