Skip to content

Commit

Permalink
Merge pull request #527 from dgonyeo/pretty-reports
Browse files Browse the repository at this point in the history
add highlights to reports coming from Validate and ValidateFoo functions
  • Loading branch information
Derek Gonyeo authored Mar 22, 2018
2 parents b100f31 + 9860289 commit 427ec4e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions config/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,25 +174,26 @@ func validateStruct(vObj reflect.Value, ast astnode.AstNode, source io.ReadSeeke
// Default to deepest node if the node's type isn't an object,
// such as when a json string actually unmarshal to structs (like with version)
line, col := 0, 0
highlight := ""
if ast != nil {
line, col, _ = ast.ValueLineCol(src)
line, col, highlight = ast.ValueLineCol(src)
}

// If there's a Validate<Name> func for the given field, call it
funct := vObj.MethodByName("Validate" + f.Type.Name)
if funct.IsValid() {
if sub_node != nil {
// if sub_node is non-nil, we can get better line/col info
line, col, _ = sub_node.ValueLineCol(src)
line, col, highlight = sub_node.ValueLineCol(src)
}
res := funct.Call(nil)
sub_report := res[0].Interface().(report.Report)
sub_report.AddPosition(line, col, "")
sub_report.AddPosition(line, col, highlight)
r.Merge(sub_report)
}

sub_report := Validate(f.Value, sub_node, src, checkUnusedKeys)
sub_report.AddPosition(line, col, "")
sub_report.AddPosition(line, col, highlight)
r.Merge(sub_report)
}
if !isFromObject || !checkUnusedKeys {
Expand Down

0 comments on commit 427ec4e

Please sign in to comment.