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)
| 289 | // Validate searches the AST for uses of a given function name with a constant argument and performs a check |
| 290 | // on whether the argument is a valid literal value. |
| 291 | func (v formatValidator) Validate(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues) { |
| 292 | root := ast.NavigateAST(a) |
| 293 | funcCalls := ast.MatchDescendants(root, ast.FunctionMatcher(v.funcName)) |
| 294 | for _, call := range funcCalls { |
| 295 | callArgs := call.AsCall().Args() |
| 296 | if len(callArgs) <= v.argNum { |
| 297 | continue |
| 298 | } |
| 299 | litArg := callArgs[v.argNum] |
| 300 | if litArg.Kind() != ast.LiteralKind { |
| 301 | continue |
| 302 | } |
| 303 | if err := v.check(e, call, litArg); err != nil { |
| 304 | iss.ReportErrorAtID(litArg.ID(), "invalid %s argument", v.funcName) |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | func evalCall(env *Env, call, arg ast.Expr) error { |
| 310 | ast := &Ast{impl: ast.NewAST(call, ast.NewSourceInfo(nil))} |
nothing calls this directly
no test coverage detected