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

Function matchConstantFormatStringWithListLiteralArgs

ext/formatting.go:473–506  ·  view source on GitHub ↗

matchConstantFormatStringWithListLiteralArgs matches all valid expression nodes for string format checking.

(a *ast.AST)

Source from the content-addressed store, hash-verified

471// matchConstantFormatStringWithListLiteralArgs matches all valid expression nodes for string
472// format checking.
473func matchConstantFormatStringWithListLiteralArgs(a *ast.AST) ast.ExprMatcher {
474 return func(e ast.NavigableExpr) bool {
475 if e.Kind() != ast.CallKind {
476 return false
477 }
478 call := e.AsCall()
479 if !call.IsMemberFunction() || call.FunctionName() != "format" {
480 return false
481 }
482 overloadIDs := a.GetOverloadIDs(e.ID())
483 if len(overloadIDs) != 0 {
484 found := false
485 for _, overload := range overloadIDs {
486 if overload == overloads.ExtFormatString {
487 found = true
488 break
489 }
490 }
491 if !found {
492 return false
493 }
494 }
495 formatString := call.Target()
496 if formatString.Kind() != ast.LiteralKind || formatString.AsLiteral().Type() != cel.StringType {
497 return false
498 }
499 args := call.Args()
500 if len(args) != 1 {
501 return false
502 }
503 formatArgs := args[0]
504 return formatArgs.Kind() == ast.ListKind
505 }
506}
507
508// stringFormatChecker implements the formatStringInterpolater interface
509type stringFormatChecker struct {

Callers 2

ValidateMethod · 0.85
ValidateMethod · 0.85

Calls 10

GetOverloadIDsMethod · 0.80
KindMethod · 0.65
AsCallMethod · 0.65
IsMemberFunctionMethod · 0.65
FunctionNameMethod · 0.65
IDMethod · 0.65
TargetMethod · 0.65
TypeMethod · 0.65
AsLiteralMethod · 0.65
ArgsMethod · 0.65

Tested by

no test coverage detected