-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
57 lines (47 loc) · 1.25 KB
/
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
package main
import (
"encoding/json"
"flag"
"fmt"
"github.com/mirecl/golimiter/analysis"
"github.com/mirecl/golimiter/config"
"github.com/mirecl/golimiter/linters"
)
// Version golimiter linter.
const Version string = "0.4.3"
func main() {
jsonFlag := flag.Bool("json", false, "format report")
versionFlag := flag.Bool("version", false, "version golimiter")
configFlag := flag.String("config", ".golimiter.yaml", "path config file")
flag.Parse()
if *versionFlag {
fmt.Printf("golimiter %s\n", Version)
return
}
cfg, err := config.ReadFromFile(*configFlag)
if err != nil {
panic(err)
}
allIssues := analysis.Run(cfg,
linters.NewNoGeneric(),
linters.NewNoInit(),
linters.NewNoGoroutine(),
linters.NewNoNoLint(),
linters.NewNoDefer(),
linters.NewNoLength(),
linters.NewNoPrefix(),
linters.NewNoUnderscore(),
)
if *jsonFlag {
if allIssuesBytes, err := json.Marshal(allIssues); err == nil {
fmt.Println(string(allIssuesBytes))
}
return
}
for linter, issues := range allIssues {
for _, issue := range issues {
position := fmt.Sprintf("%s:%v", analysis.GetPathRelative(issue.Filename), issue.Line)
fmt.Printf("%s \033[31m%s: %s. \033[0m\033[30m(%s)\033[0m\n", position, linter, issue.Message, issue.Hash)
}
}
}