forked from dbraley/example-linter
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
example.go
36 lines (30 loc) · 741 Bytes
/
example.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
package linters
import (
"go/ast"
"strings"
"golang.org/x/tools/go/analysis"
)
var TodoAnalyzer = &analysis.Analyzer{
Name: "todo",
Doc: "finds todos without author",
Run: run,
}
func run(pass *analysis.Pass) (interface{}, error) {
for _, file := range pass.Files {
ast.Inspect(file, func(n ast.Node) bool {
if comment, ok := n.(*ast.Comment); ok {
if strings.HasPrefix(comment.Text, "// TODO:") || strings.HasPrefix(comment.Text, "// TODO():") {
pass.Report(analysis.Diagnostic{
Pos: comment.Pos(),
End: 0,
Category: "todo",
Message: "TODO comment has no author",
SuggestedFixes: nil,
})
}
}
return true
})
}
return nil, nil
}