matchConstantFormatStringWithListLiteralArgs matches all valid expression nodes for string format checking.
(a *ast.AST)
| 471 | // matchConstantFormatStringWithListLiteralArgs matches all valid expression nodes for string |
| 472 | // format checking. |
| 473 | func 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 |
| 509 | type stringFormatChecker struct { |
no test coverage detected