blob: d17ce4825dec144a452e8662d44090fc34aa94f1 [file] [log] [blame]
Julie Qiuba98bfe2021-11-01 18:00:04 -04001// 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.
6package vlint
7
8import (
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 Amsterdam4ce6bdd2021-12-14 06:38:21 -050018// TestLintReports (in the vulndb repo) to ensure that there are no errors in
19// the YAML reports.
Julie Qiuba98bfe2021-11-01 18:00:04 -040020func 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}