Skip to content

Commit

Permalink
internal/report: move all logic related to linting description/summar…
Browse files Browse the repository at this point in the history
…y together

Change-Id: I1fae85db33ff869b053c0dfca344d4a1be20805e
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/542358
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
  • Loading branch information
tatianab committed Nov 17, 2023
1 parent 11844d7 commit d398ca7
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions internal/report/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,8 @@ func (r *Report) lintLinks(addIssue func(string)) {

func (d *Description) lint(addIssue func(string), r *Report) {
desc := d.String()
if desc == "" && r.CVEMetadata != nil {
addIssue("missing description (reports with Go CVEs must have a description)")
}

r.lintLineLength("description", desc, addIssue)
hasAdvisory := func() bool {
for _, ref := range r.References {
if ref.Type == osv.ReferenceTypeAdvisory {
Expand All @@ -290,14 +289,18 @@ func (d *Description) lint(addIssue func(string), r *Report) {
}
return false
}
if desc == "" && r.CVEMetadata == nil && !hasAdvisory() {
addIssue("missing advisory (reports without descriptions must have an advisory link)")
if !r.IsExcluded() && desc == "" {
if r.CVEMetadata != nil {
addIssue("missing description (reports with Go CVEs must have a description)")
} else if !hasAdvisory() {
addIssue("missing advisory (reports without descriptions must have an advisory link)")
}
}
}

func (s *Summary) lint(addIssue func(string)) {
func (s *Summary) lint(addIssue func(string), r *Report) {
summary := s.String()
if len(summary) == 0 {
if !r.IsExcluded() && len(summary) == 0 {
addIssue("missing summary")
}
if strings.HasPrefix(summary, "TODO") {
Expand Down Expand Up @@ -393,6 +396,8 @@ func (r *Report) lint(pc *proxy.Client) []string {
if r.ID == "" {
addIssue("missing ID")
}
r.Summary.lint(addIssue, r)
r.Description.lint(addIssue, r)

if r.IsExcluded() {
if !slices.Contains(ExcludedReasons, r.Excluded) {
Expand All @@ -408,8 +413,6 @@ func (r *Report) lint(pc *proxy.Client) []string {
if len(r.Modules) == 0 {
addIssue("no modules")
}
r.Description.lint(addIssue, r)
r.Summary.lint(addIssue)
}

isFirstParty := false
Expand Down Expand Up @@ -447,7 +450,6 @@ func (r *Report) lint(pc *proxy.Client) []string {
m.lintVersions(addPkgIssue)
}

r.lintLineLength("description", r.Description.String(), addIssue)
if r.CVEMetadata != nil {
r.lintLineLength("cve_metadata.description", r.CVEMetadata.Description, addIssue)
}
Expand Down

0 comments on commit d398ca7

Please # to comment.