/
tagdoctor.go
69 lines (59 loc) · 1.27 KB
/
tagdoctor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright 2020 bigpigeon. All rights reserved.
* Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file.
*
*/
package main
import (
"go/ast"
"go/token"
)
const tagDockerMaxErr = 5
type tagDockerErr []error
func (e tagDockerErr) Error() string {
s := "detect error: \n"
for _, _e := range e {
s += " " + _e.Error() + "\n"
}
return s
}
type tagDoctor struct {
f *ast.File
fs *token.FileSet
Err tagDockerErr
}
func (s *tagDoctor) Visit(node ast.Node) ast.Visitor {
cmap := ast.NewCommentMap(s.fs, node, s.f.Comments)
visit := newTopVisit(cmap, s.executor)
return visit.Visit(node)
}
func (t *tagDoctor) executor(name string, comments []*ast.CommentGroup, n *ast.StructType) {
if n.Fields != nil {
for _, field := range n.Fields.List {
fieldName := getFieldOrTypeName(field)
if fieldFilter(fieldName) == false {
continue
}
if field.Tag != nil {
_, _, err := ParseTag(field.Tag.Value)
if err != nil {
if len(t.Err) < tagDockerMaxErr {
t.Err = append(t.Err, NewAstError(t.fs, field.Tag, err))
}
}
}
}
}
return
}
func (t *tagDoctor) Scan() error {
ast.Walk(t, t.f)
if len(t.Err) != 0 {
return t.Err
}
return nil
}
func (t *tagDoctor) Execute() error {
return nil
}