Validate implements the ASTValidator interface method.
(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues)
| 497 | |
| 498 | // Validate implements the ASTValidator interface method. |
| 499 | func (v bindNestingLimitValidator) Validate(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues) { |
| 500 | root := ast.NavigateAST(a) |
| 501 | comprehensions := ast.MatchDescendants(root, ast.KindMatcher(ast.ComprehensionKind)) |
| 502 | var celBinds []ast.NavigableExpr |
| 503 | for _, comp := range comprehensions { |
| 504 | if isCelBind(comp) { |
| 505 | celBinds = append(celBinds, comp) |
| 506 | } |
| 507 | } |
| 508 | if len(celBinds) <= v.limit { |
| 509 | return |
| 510 | } |
| 511 | for _, comp := range celBinds { |
| 512 | count := 0 |
| 513 | e := comp |
| 514 | hasParent := true |
| 515 | for hasParent { |
| 516 | if isCelBind(e) { |
| 517 | count++ |
| 518 | if count > v.limit { |
| 519 | iss.ReportErrorAtID(comp.ID(), "cel.bind exceeds nesting limit") |
| 520 | break |
| 521 | } |
| 522 | } |
| 523 | e, hasParent = e.Parent() |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | func isEmptyRangeComprehension(e ast.NavigableExpr) bool { |
| 529 | if e.Kind() != ast.ComprehensionKind { |
nothing calls this directly
no test coverage detected