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

Method Validate

ext/formatting.go:432–455  ·  view source on GitHub ↗

Validate parses all literal format strings and type checks the format clause against the argument at the corresponding ordinal within the list literal argument to the function, if one is specified.

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

Source from the content-addressed store, hash-verified

430// Validate parses all literal format strings and type checks the format clause against the argument
431// at the corresponding ordinal within the list literal argument to the function, if one is specified.
432func (v stringFormatValidator) Validate(env *cel.Env, _ cel.ValidatorConfig, a *ast.AST, iss *cel.Issues) {
433 root := ast.NavigateAST(a)
434 formatCallExprs := ast.MatchDescendants(root, matchConstantFormatStringWithListLiteralArgs(a))
435 for _, e := range formatCallExprs {
436 call := e.AsCall()
437 formatStr := call.Target().AsLiteral().Value().(string)
438 args := call.Args()[0].AsList().Elements()
439 formatCheck := &stringFormatChecker{
440 args: args,
441 ast: a,
442 }
443 // use a placeholder locale, since locale doesn't affect syntax
444 _, err := parseFormatString(formatStr, formatCheck, formatCheck, "en_US", v.maxPrecision)
445 if err != nil {
446 iss.ReportErrorAtID(getErrorExprID(e.ID(), err), "%v", err)
447 continue
448 }
449 seenArgs := formatCheck.argsRequested
450 if len(args) > seenArgs {
451 iss.ReportErrorAtID(e.ID(),
452 "too many arguments supplied to string.format (expected %d, got %d)", seenArgs, len(args))
453 }
454 }
455}
456
457// getErrorExprID determines which list literal argument triggered a type-disagreement for the
458// purposes of more accurate error message reports.

Callers

nothing calls this directly

Calls 14

NavigateASTFunction · 0.92
MatchDescendantsFunction · 0.92
parseFormatStringFunction · 0.85
getErrorExprIDFunction · 0.85
AsCallMethod · 0.65
ValueMethod · 0.65
AsLiteralMethod · 0.65
TargetMethod · 0.65
ElementsMethod · 0.65
AsListMethod · 0.65
ArgsMethod · 0.65

Tested by

no test coverage detected