From 2dc8079a0f7dd1160390e981af05825c4655711a Mon Sep 17 00:00:00 2001 From: sadhvi25 <66865551+sadhvi25@users.noreply.github.com> Date: Tue, 16 Jun 2020 23:43:28 -0600 Subject: [PATCH] [nvdtools] Fix golint findings and enable the golint pass (#149) * [nvdtools] Fix golint using golangci-lint and enable the golint pass * [nvdtools] Adding golint pass to CI --- .travis.yml | 2 +- providers/idefense/api/client.go | 8 ++++---- providers/redhat/check/check_cve.go | 17 +++++++++-------- providers/redhat/feed.go | 2 +- rpm/compare.go | 3 +-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index e94a6d5..fda8e5f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ env: script: - go get -v -t -u -d ./... -- 'golangci-lint run ./... --disable-all -E gosimple -E govet -E ineffassign -E staticcheck -E structcheck -E varcheck -e SA5011:' +- 'golangci-lint run ./... --disable-all -E golint -E gosimple -E govet -E ineffassign -E staticcheck -E structcheck -E varcheck -e SA5011:' - go test -v ./... before_deploy: diff --git a/providers/idefense/api/client.go b/providers/idefense/api/client.go index 156b277..a444b14 100644 --- a/providers/idefense/api/client.go +++ b/providers/idefense/api/client.go @@ -33,7 +33,7 @@ import ( // Client struct type Client struct { client.Client - baseUrl string + baseURL string apiKey string } @@ -43,10 +43,10 @@ const ( ) // NewClient creates an object which is used to query the iDefense API -func NewClient(c client.Client, baseUrl, apiKey string) *Client { +func NewClient(c client.Client, baseURL, apiKey string) *Client { return &Client{ Client: c, - baseUrl: baseUrl, + baseURL: baseURL, apiKey: apiKey, } } @@ -107,7 +107,7 @@ func (c *Client) FetchAllVulnerabilities(ctx context.Context, since int64) (<-ch } func (c *Client) queryVulnerabilities(ctx context.Context, params map[string]interface{}) (*schema.VulnerabilitySearchResults, error) { - u, err := url.Parse(c.baseUrl + vulnerabilityEndpoint) + u, err := url.Parse(c.baseURL + vulnerabilityEndpoint) if err != nil { return nil, errors.Wrap(err, "failed to parse url") } diff --git a/providers/redhat/check/check_cve.go b/providers/redhat/check/check_cve.go index fc1eedc..384df0a 100644 --- a/providers/redhat/check/check_cve.go +++ b/providers/redhat/check/check_cve.go @@ -23,25 +23,26 @@ import ( "github.com/facebookincubator/nvdtools/wfn" ) -var NoCheckers = errors.New("no applicable checkers") +var ErrCheckers = errors.New("no applicable checkers") func CVEChecker(cve *schema.CVE) (rpm.Checker, error) { var chks []rpm.Checker - if archks, err := affectedReleaseCheckers(cve); err != nil { + archks, err := affectedReleaseCheckers(cve) + if err != nil { return nil, fmt.Errorf("can't construct checkers for affected release: %v", err) - } else { - chks = archks } + chks = archks - if pschks, err := packageStateCheckers(cve); err != nil { + pschks, err := packageStateCheckers(cve) + if err != nil { return nil, fmt.Errorf("can't construct checkers for package state: %v", err) - } else { - chks = append(chks, pschks...) } + chks = append(chks, pschks...) + if len(chks) == 0 { - return nil, NoCheckers + return nil, ErrCheckers } return &cveChecker{cve.Name, chks}, nil diff --git a/providers/redhat/feed.go b/providers/redhat/feed.go index 14a0a4c..5398814 100644 --- a/providers/redhat/feed.go +++ b/providers/redhat/feed.go @@ -63,7 +63,7 @@ func (feed *Feed) Checker() (rpm.Checker, error) { var err error for cveid, cve := range feed.data { if mc[cveid], err = check.CVEChecker(cve); err != nil { - if err == check.NoCheckers { + if err == check.ErrCheckers { // no checkers could be created, just skip it delete(mc, cveid) continue diff --git a/rpm/compare.go b/rpm/compare.go index 2809404..1d26979 100644 --- a/rpm/compare.go +++ b/rpm/compare.go @@ -114,9 +114,8 @@ func versionCompare(v1, v2 string) int { if len(v2Seg) == 0 { if isNumeric { return 1 - } else { - return -1 } + return -1 } // here we know that they both start with either numbers or letters