-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcodeclimate-govet.go
81 lines (67 loc) · 1.82 KB
/
codeclimate-govet.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
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"github.com/codeclimate/cc-engine-go/engine"
"strings"
"os"
"os/exec"
"strconv"
"fmt"
)
func main() {
rootPath := "/code/"
config, err := engine.LoadConfig()
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading config: %v\n", err)
os.Exit(1)
}
analysisFiles, err := engine.GoFileWalk(rootPath, engine.IncludePaths(rootPath, config))
if err != nil {
fmt.Fprintf(os.Stderr, "Error initializing: %v\n", err)
os.Exit(1)
}
for _, path := range analysisFiles {
cmd := exec.Command("go", "vet", path)
out, err := cmd.CombinedOutput()
if err != nil && err.Error() != "exit status 1" {
fmt.Fprintf(os.Stderr, "Error analyzing path: %v\n", path)
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
if out != nil {
s := string(out[:])
fmt.Fprintf(os.Stderr, "Govet output: %v\n", s)
}
return
}
lines := strings.Split(string(out), "\n")
if len(lines) > 1 {
for _, line := range lines[:len(lines)-1] {
pieces := strings.Split(line, ":")
if len(pieces) < 3 {
fmt.Fprintf(os.Stderr, "Unexpected format for the following output: %v\n", line)
return
} else {
lineNo, err := strconv.Atoi(pieces[1])
if err != nil {
fmt.Fprintf(os.Stderr, "Unexpected format for the following output: %v\n", line)
fmt.Fprintf(os.Stderr, "\nError: %v\n", err)
return
}
issue := &engine.Issue{
Type: "issue",
Check: "GoVet/BugRisk",
Description: strings.Join(pieces[2:], ":"),
RemediationPoints: 50000,
Categories: []string{"Bug Risk"},
Location: &engine.Location{
Path: strings.SplitAfter(path, rootPath)[1],
Lines: &engine.LinesOnlyPosition{
Begin: lineNo,
End: lineNo,
},
},
}
engine.PrintIssue(issue)
}
}
}
}
}