Skip to content

Commit 2f2ef3b

Browse files
committed
improvu vuln output
1 parent 9b60aa7 commit 2f2ef3b

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

pkg/golinters/vulncheck.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package golinters
22

33
import (
4+
"fmt"
5+
"strings"
46
"sync"
57

68
"golang.org/x/net/context"
@@ -71,13 +73,34 @@ func vulncheckRun(lintCtx *linter.Context, pass *analysis.Pass, settings *config
7173
return nil, err
7274
}
7375

76+
imports := vulncheck.ImportChains(r)
7477
issues := make([]goanalysis.Issue, 0, len(r.Vulns))
7578

76-
for _, vuln := range r.Vulns {
79+
for idx, vuln := range r.Vulns {
7780
issues = append(issues, goanalysis.NewIssue(&result.Issue{
78-
Text: vuln.OSV.ID,
81+
Text: writeVulnerability(idx, vuln.OSV.ID, vuln.OSV.Details, writeImorts(imports[vuln])),
7982
}, pass))
8083
}
8184

8285
return issues, nil
8386
}
87+
88+
func writeImorts(imports []vulncheck.ImportChain) string {
89+
var s strings.Builder
90+
for _, i := range imports {
91+
indent := 0
92+
for _, pkg := range i {
93+
s.WriteString(fmt.Sprintf("%s|_ %s", strings.Repeat(" ", indent), pkg.Name))
94+
}
95+
}
96+
97+
return s.String()
98+
}
99+
100+
func writeVulnerability(idx int, id, details, imports string) string {
101+
return fmt.Sprintf(`Vulnerability #%d: %s
102+
%s
103+
%s
104+
More info: https://pkg.go.dev/vuln/%s
105+
`, idx, id, details, imports, id)
106+
}

0 commit comments

Comments
 (0)