Skip to content

Commit

Permalink
internal/report: remove lint from ToReport
Browse files Browse the repository at this point in the history
Remove call to Lint from ToReport, but continue to record lints in
tests. To support this, add a function LintAsNotes which can be used
to add lint notes to a report.

Change-Id: I92e561d805d49c7f7af857e7dcbacee4f380ff2a
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/529838
Reviewed-by: Damien Neil <[email protected]>
Reviewed-by: Jonathan Amsterdam <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
tatianab committed Oct 11, 2023
1 parent bc2ff59 commit 1d60841
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
10 changes: 1 addition & 9 deletions internal/genericosv/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,8 @@ func (osv *Entry) ToReport(goID string, pc *proxy.Client) *report.Report {
fixRefs(r)

r.Credits = convertCredits(osv.Credits)

r.Fix(pc)
if lints := r.Lint(pc); len(lints) > 0 {
slices.Sort(lints)
for _, lint := range lints {
r.Notes = append(r.Notes, &report.Note{
Body: lint,
Type: report.NoteTypeLint,
})
}
}
return r
}

Expand Down
3 changes: 3 additions & 0 deletions internal/genericosv/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func TestToReport(t *testing.T) {
}

got := osv.ToReport("GO-TEST-ID", pc)
// Keep record of what lints would apply to each generated report.
got.LintAsNotes(pc)

yamlFile := filepath.Join(testYAMLDir, ghsaID+".yaml")
if *update {
if err := got.Write(yamlFile); err != nil {
Expand Down
23 changes: 23 additions & 0 deletions internal/report/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,29 @@ func (r *Report) Lint(pc *proxy.Client) []string {
return result
}

// LintAsNotes works like Lint, but modifies r by adding any lints found
// to the notes section, instead of returning them.
// Removes any pre-existing lint notes.
// Returns true if any lints were found.
func (r *Report) LintAsNotes(pc *proxy.Client) bool {
r.Notes = slices.DeleteFunc(r.Notes, func(n *Note) bool {
return n.Type == NoteTypeLint
})

if lints := r.Lint(pc); len(lints) > 0 {
slices.Sort(lints)
for _, lint := range lints {
r.Notes = append(r.Notes, &Note{
Body: lint,
Type: NoteTypeLint,
})
}
return true
}

return false
}

// LintOffline performs all lint checks that don't require a network connection.
func (r *Report) LintOffline() []string {
return r.lint(nil)
Expand Down

0 comments on commit 1d60841

Please sign in to comment.