Validate searches the AST for uses of a given function name with a constant argument and performs a check on whether the argument is a valid literal value.
(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues)
| 261 | // Validate searches the AST for uses of a given function name with a constant argument and performs a check |
| 262 | // on whether the argument is a valid literal value. |
| 263 | func (v formatValidator) Validate(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues) { |
| 264 | root := ast.NavigateAST(a) |
| 265 | funcCalls := ast.MatchDescendants(root, ast.FunctionMatcher(v.funcName)) |
| 266 | for _, call := range funcCalls { |
| 267 | callArgs := call.AsCall().Args() |
| 268 | if len(callArgs) <= v.argNum { |
| 269 | continue |
| 270 | } |
| 271 | litArg := callArgs[v.argNum] |
| 272 | if litArg.Kind() != ast.LiteralKind { |
| 273 | continue |
| 274 | } |
| 275 | if err := v.check(e, call, litArg); err != nil { |
| 276 | iss.ReportErrorAtID(litArg.ID(), "invalid %s argument", v.funcName) |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | func evalCall(env *Env, call, arg ast.Expr) error { |
| 282 | ast := &Ast{impl: ast.NewAST(call, ast.NewSourceInfo(nil))} |
nothing calls this directly
no test coverage detected