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

Method Validate

ext/formatting_v2.go:424–447  ·  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

422// Validate parses all literal format strings and type checks the format clause against the argument
423// at the corresponding ordinal within the list literal argument to the function, if one is specified.
424func (v stringFormatValidatorV2) Validate(env *cel.Env, _ cel.ValidatorConfig, a *ast.AST, iss *cel.Issues) {
425 root := ast.NavigateAST(a)
426 formatCallExprs := ast.MatchDescendants(root, matchConstantFormatStringWithListLiteralArgs(a))
427 for _, e := range formatCallExprs {
428 call := e.AsCall()
429 formatStr := call.Target().AsLiteral().Value().(string)
430 args := call.Args()[0].AsList().Elements()
431 formatCheck := &stringFormatCheckerV2{
432 args: args,
433 ast: a,
434 }
435 // use a placeholder locale, since locale doesn't affect syntax
436 _, err := parseFormatStringV2(formatStr, formatCheck, formatCheck, v.maxPrecision)
437 if err != nil {
438 iss.ReportErrorAtID(getErrorExprID(e.ID(), err), "%v", err)
439 continue
440 }
441 seenArgs := formatCheck.argsRequested
442 if len(args) > seenArgs {
443 iss.ReportErrorAtID(e.ID(),
444 "too many arguments supplied to string.format (expected %d, got %d)", seenArgs, len(args))
445 }
446 }
447}
448
449// stringFormatCheckerV2 implements the formatStringInterpolater interface
450type stringFormatCheckerV2 struct {

Callers

nothing calls this directly

Calls 14

NavigateASTFunction · 0.92
MatchDescendantsFunction · 0.92
parseFormatStringV2Function · 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