/
main.go
58 lines (48 loc) · 1016 Bytes
/
main.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
package main
import (
"bytes"
"flag"
"fmt"
"github.com/luoxiaojun1992/go-missing-len/pkg"
"go/ast"
"go/format"
"go/parser"
"go/token"
)
func main() {
var filename string
flag.StringVar(&filename, "file", "", "")
var resultFormat string
flag.StringVar(&resultFormat, "format", "", "")
var showAst bool
flag.BoolVar(&showAst, "ast", false, "")
flag.Parse()
fileSet := token.NewFileSet()
file, err := parser.ParseFile(fileSet, filename, nil, 0)
if err != nil {
panic(err)
}
if showAst {
fmt.Println("Ast:")
fmt.Println()
if err := ast.Print(fileSet, file); err != nil {
panic(err)
}
fmt.Println()
}
linter := pkg.NewMissingLenLinter()
linter.Check(file)
fmt.Println("Result:")
fmt.Println()
pkg.SerializeHints(linter.Hints, resultFormat)
fmt.Println()
fmt.Println("Suggested code:")
fmt.Println()
rawCode := bytes.NewBuffer(nil)
err = format.Node(rawCode, token.NewFileSet(), file)
if err != nil {
panic(err)
}
fmt.Println(rawCode.String())
fmt.Println()
}