Julie Qiu | ba98bfe | 2021-11-01 18:00:04 -0400 | [diff] [blame] | 1 | // Copyright 2021 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // Package vlint contains functionality for linting reports in x/vulndb. |
| 6 | package vlint |
| 7 | |
| 8 | import ( |
| 9 | "fmt" |
| 10 | "io/ioutil" |
| 11 | |
| 12 | "golang.org/x/vuln/internal/derrors" |
| 13 | "golang.org/x/vuln/internal/report" |
| 14 | "gopkg.in/yaml.v2" |
| 15 | ) |
| 16 | |
| 17 | // LintReport is used to lint the x/vulndb/reports/ directory. It is run by |
Jonathan Amsterdam | 4ce6bdd | 2021-12-14 06:38:21 -0500 | [diff] [blame] | 18 | // TestLintReports (in the vulndb repo) to ensure that there are no errors in |
| 19 | // the YAML reports. |
Julie Qiu | ba98bfe | 2021-11-01 18:00:04 -0400 | [diff] [blame] | 20 | func LintReport(filename string) (_ []string, err error) { |
| 21 | defer derrors.Wrap(&err, "Lint(%q)", filename) |
| 22 | b, err := ioutil.ReadFile(filename) |
| 23 | if err != nil { |
| 24 | return nil, fmt.Errorf("ioutil.ReadDir(%q): %v", filename, err) |
| 25 | } |
| 26 | var r report.Report |
| 27 | if err := yaml.UnmarshalStrict(b, &r); err != nil { |
| 28 | return nil, fmt.Errorf("yaml.UnmarshalStrict(b, &r): %v (%q)", err, filename) |
| 29 | } |
| 30 | return r.Lint(), nil |
| 31 | } |