From 6e704239a6518c28d703daa0bd6696694ae6ec62 Mon Sep 17 00:00:00 2001 From: Teppei Fukuda Date: Wed, 20 Sep 2023 09:23:39 +0300 Subject: [PATCH] chore: enable more linters (#241) Signed-off-by: knqyf263 Co-authored-by: DmitriyLewen <91113035+DmitriyLewen@users.noreply.github.com> --- .github/workflows/go.yml | 15 ++++++------- .golangci.yml | 32 ++++++++++++++++++++++++---- Makefile | 23 ++++++++++++++++++++ alma/alma.go | 3 ++- alma/alma_test.go | 3 ++- amazon/amazon.go | 8 ++++--- amazon/amazon_test.go | 2 +- arch/archlinux.go | 4 ++-- arch/archlinux_test.go | 3 ++- chainguard/chainguard_test.go | 3 ++- cwe/cwe.go | 3 ++- cwe/cwe_test.go | 3 +-- ghsa/ghsa.go | 3 ++- git/git.go | 3 ++- kevc/kevc.go | 8 ++++--- kevc/kevc_test.go | 8 ++++--- nvd/nvd.go | 3 ++- oracle/oval/oval.go | 3 ++- oracle/oval/oval_test.go | 4 ++-- oracle/oval/types_test.go | 3 ++- osv/osv_test.go | 3 ++- photon/photon.go | 3 ++- redhat/oval/redhat_test.go | 3 +-- redhat/securitydataapi/types_test.go | 3 ++- rocky/rocky.go | 3 ++- rocky/rocky_test.go | 3 ++- suse/cvrf/cvrf.go | 3 ++- suse/cvrf/cvrf_test.go | 3 +-- ubuntu/ubuntu.go | 4 +--- ubuntu/ubuntu_test.go | 1 - wolfi/wolfi_test.go | 3 ++- 31 files changed, 116 insertions(+), 53 deletions(-) create mode 100644 Makefile diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 32ad61a..bc318d6 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -6,22 +6,21 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: 1.18 - id: go - - name: Check out code into the Go module directory uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: go.mod + - name: Lint uses: golangci/golangci-lint-action@v3.7.0 with: - version: v1.45 + version: v1.54 args : --verbose - name: Test run: | - go test -v ./... + make test diff --git a/.golangci.yml b/.golangci.yml index ea96083..0612a0f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,11 +4,35 @@ run: linters: enable: - gofmt - disable: - - errcheck + - bodyclose + - staticcheck + - unused + - gci + - gomodguard + - tenv - gosimple - govet + disable: + - errcheck - ineffassign - - staticcheck - structcheck - - unused +linters-settings: + gci: + sections: + - standard + - default + - prefix(github.com/aquasecurity/) + - blank + - dot + gomodguard: + blocked: + modules: + - github.com/hashicorp/go-version: + recommendations: + - github.com/aquasecurity/go-version + reason: "`aquasecurity/go-version` is degisned for our use-cases" + - github.com/Masterminds/semver: + recommendations: + - github.com/aquasecurity/go-version + reason: "`aquasecurity/go-version` is degisned for our use-cases" + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6a64b4a --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +export SHELL := /bin/bash +export SHELLOPTS := errexit + +GOPATH ?= $(shell go env GOPATH) +BIN_DIR := $(GOPATH)/bin +GOLANGCI_LINT := $(BIN_DIR)/golangci-lint + +.PHONY: lint lintfix test build + +$(GOLANGCI_LINT): + curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(BIN_DIR) v1.54.2 + +lint: $(GOLANGCI_LINT) + @$(GOLANGCI_LINT) run + +lintfix: $(GOLANGCI_LINT) + @$(GOLANGCI_LINT) run --fix + +test: + go test -race ./... + +build: + go build -o vuln-list-update . diff --git a/alma/alma.go b/alma/alma.go index 39ae24f..174ec89 100644 --- a/alma/alma.go +++ b/alma/alma.go @@ -10,9 +10,10 @@ import ( "strings" "time" - "github.com/aquasecurity/vuln-list-update/utils" "github.com/cheggaaa/pb/v3" "golang.org/x/xerrors" + + "github.com/aquasecurity/vuln-list-update/utils" ) const ( diff --git a/alma/alma_test.go b/alma/alma_test.go index b8d78ca..4a81f10 100644 --- a/alma/alma_test.go +++ b/alma/alma_test.go @@ -8,10 +8,11 @@ import ( "path/filepath" "testing" - "github.com/aquasecurity/vuln-list-update/alma" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/xerrors" + + "github.com/aquasecurity/vuln-list-update/alma" ) func TestUpdate(t *testing.T) { diff --git a/amazon/amazon.go b/amazon/amazon.go index 9d4724f..3f4b37a 100644 --- a/amazon/amazon.go +++ b/amazon/amazon.go @@ -6,14 +6,16 @@ import ( "compress/gzip" "encoding/xml" "fmt" - "github.com/aquasecurity/vuln-list-update/utils" - "golang.org/x/xerrors" - "gopkg.in/cheggaaa/pb.v1" "log" "net/url" "os" "path" "path/filepath" + + "golang.org/x/xerrors" + "gopkg.in/cheggaaa/pb.v1" + + "github.com/aquasecurity/vuln-list-update/utils" ) const ( diff --git a/amazon/amazon_test.go b/amazon/amazon_test.go index f73344a..2258830 100644 --- a/amazon/amazon_test.go +++ b/amazon/amazon_test.go @@ -10,10 +10,10 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "golang.org/x/xerrors" "github.com/aquasecurity/vuln-list-update/amazon" - "github.com/stretchr/testify/assert" ) func TestConfig_Update(t *testing.T) { diff --git a/arch/archlinux.go b/arch/archlinux.go index 75ebf18..6258f3c 100644 --- a/arch/archlinux.go +++ b/arch/archlinux.go @@ -7,10 +7,10 @@ import ( "os" "path/filepath" - "github.com/aquasecurity/vuln-list-update/utils" - "github.com/cheggaaa/pb/v3" "golang.org/x/xerrors" + + "github.com/aquasecurity/vuln-list-update/utils" ) const ( diff --git a/arch/archlinux_test.go b/arch/archlinux_test.go index c8b2139..073e6c3 100644 --- a/arch/archlinux_test.go +++ b/arch/archlinux_test.go @@ -1,7 +1,6 @@ package arch_test import ( - "github.com/aquasecurity/vuln-list-update/arch" "io" "net/http" "net/http/httptest" @@ -11,6 +10,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/aquasecurity/vuln-list-update/arch" ) func TestUpdate(t *testing.T) { diff --git a/chainguard/chainguard_test.go b/chainguard/chainguard_test.go index fc31589..c2998c0 100644 --- a/chainguard/chainguard_test.go +++ b/chainguard/chainguard_test.go @@ -9,10 +9,11 @@ import ( "os" "testing" - "github.com/aquasecurity/vuln-list-update/chainguard" "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/aquasecurity/vuln-list-update/chainguard" ) var update = flag.Bool("update", false, "update golden files") diff --git a/cwe/cwe.go b/cwe/cwe.go index aee990c..2b93939 100644 --- a/cwe/cwe.go +++ b/cwe/cwe.go @@ -11,8 +11,9 @@ import ( "os" "path/filepath" - "github.com/aquasecurity/vuln-list-update/utils" "golang.org/x/xerrors" + + "github.com/aquasecurity/vuln-list-update/utils" ) type CWEConfig struct { diff --git a/cwe/cwe_test.go b/cwe/cwe_test.go index 82c308d..c410b99 100644 --- a/cwe/cwe_test.go +++ b/cwe/cwe_test.go @@ -9,9 +9,8 @@ import ( "path/filepath" "testing" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestUpdate(t *testing.T) { diff --git a/ghsa/ghsa.go b/ghsa/ghsa.go index 0102d82..6fb244d 100644 --- a/ghsa/ghsa.go +++ b/ghsa/ghsa.go @@ -10,12 +10,13 @@ import ( "strings" "time" - "github.com/aquasecurity/vuln-list-update/utils" "github.com/cheggaaa/pb" githubql "github.com/shurcooL/githubv4" "github.com/shurcooL/graphql" "github.com/spf13/afero" "golang.org/x/xerrors" + + "github.com/aquasecurity/vuln-list-update/utils" ) // https://developer.github.com/v4/enum/securityadvisoryecosystem/ diff --git a/git/git.go b/git/git.go index f89a3c5..0a7729b 100644 --- a/git/git.go +++ b/git/git.go @@ -7,8 +7,9 @@ import ( "path/filepath" "strings" - "github.com/aquasecurity/vuln-list-update/utils" "golang.org/x/xerrors" + + "github.com/aquasecurity/vuln-list-update/utils" ) type Operations interface { diff --git a/kevc/kevc.go b/kevc/kevc.go index 396b67e..a478f93 100644 --- a/kevc/kevc.go +++ b/kevc/kevc.go @@ -2,11 +2,13 @@ package kevc import ( "encoding/json" - "github.com/aquasecurity/vuln-list-update/utils" - "github.com/cheggaaa/pb" - "golang.org/x/xerrors" "log" "path/filepath" + + "github.com/cheggaaa/pb" + "golang.org/x/xerrors" + + "github.com/aquasecurity/vuln-list-update/utils" ) const ( diff --git a/kevc/kevc_test.go b/kevc/kevc_test.go index 2ecbca0..a2afaf6 100644 --- a/kevc/kevc_test.go +++ b/kevc/kevc_test.go @@ -1,14 +1,16 @@ package kevc_test import ( - "github.com/aquasecurity/vuln-list-update/kevc" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "net/http" "net/http/httptest" "os" "path/filepath" "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/aquasecurity/vuln-list-update/kevc" ) func TestUpdate(t *testing.T) { diff --git a/nvd/nvd.go b/nvd/nvd.go index be4f39d..d756bc0 100644 --- a/nvd/nvd.go +++ b/nvd/nvd.go @@ -11,10 +11,11 @@ import ( "strings" "time" - "github.com/aquasecurity/vuln-list-update/utils" jsonpointer "github.com/mattn/go-jsonpointer" "golang.org/x/xerrors" pb "gopkg.in/cheggaaa/pb.v1" + + "github.com/aquasecurity/vuln-list-update/utils" ) type NVD struct { diff --git a/oracle/oval/oval.go b/oracle/oval/oval.go index cbdf1f7..b74aa80 100644 --- a/oracle/oval/oval.go +++ b/oracle/oval/oval.go @@ -9,10 +9,11 @@ import ( "path/filepath" "strings" - "github.com/aquasecurity/vuln-list-update/utils" "github.com/spf13/afero" "golang.org/x/xerrors" pb "gopkg.in/cheggaaa/pb.v1" + + "github.com/aquasecurity/vuln-list-update/utils" ) var ( diff --git a/oracle/oval/oval_test.go b/oracle/oval/oval_test.go index edf4a95..0aecbc1 100644 --- a/oracle/oval/oval_test.go +++ b/oracle/oval/oval_test.go @@ -8,10 +8,10 @@ import ( "os" "testing" - "github.com/aquasecurity/vuln-list-update/oracle/oval" + "github.com/spf13/afero" "github.com/stretchr/testify/assert" - "github.com/spf13/afero" + "github.com/aquasecurity/vuln-list-update/oracle/oval" ) var update = flag.Bool("update", false, "update golden files") diff --git a/oracle/oval/types_test.go b/oracle/oval/types_test.go index 950188e..a26a7dc 100644 --- a/oracle/oval/types_test.go +++ b/oracle/oval/types_test.go @@ -5,10 +5,11 @@ import ( "io/ioutil" "testing" - "github.com/aquasecurity/vuln-list-update/oracle/oval" "github.com/kylelemons/godebug/pretty" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/aquasecurity/vuln-list-update/oracle/oval" ) func TestRedhatCVEJSON_UnmarshalJSON(t *testing.T) { diff --git a/osv/osv_test.go b/osv/osv_test.go index 32d50fb..ed43eec 100644 --- a/osv/osv_test.go +++ b/osv/osv_test.go @@ -8,9 +8,10 @@ import ( "path/filepath" "testing" - "github.com/aquasecurity/vuln-list-update/osv" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/aquasecurity/vuln-list-update/osv" ) func Test_Update(t *testing.T) { diff --git a/photon/photon.go b/photon/photon.go index ca543c9..5410af7 100644 --- a/photon/photon.go +++ b/photon/photon.go @@ -7,10 +7,11 @@ import ( "path/filepath" "strings" - "github.com/aquasecurity/vuln-list-update/utils" "github.com/cheggaaa/pb" "github.com/spf13/afero" "golang.org/x/xerrors" + + "github.com/aquasecurity/vuln-list-update/utils" ) const ( diff --git a/redhat/oval/redhat_test.go b/redhat/oval/redhat_test.go index dca2a01..ff14891 100644 --- a/redhat/oval/redhat_test.go +++ b/redhat/oval/redhat_test.go @@ -10,10 +10,9 @@ import ( "strings" "testing" + "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "github.com/spf13/afero" ) var update = flag.Bool("update", false, "update golden files") diff --git a/redhat/securitydataapi/types_test.go b/redhat/securitydataapi/types_test.go index 8e50e01..a9d0d12 100644 --- a/redhat/securitydataapi/types_test.go +++ b/redhat/securitydataapi/types_test.go @@ -6,8 +6,9 @@ import ( "reflect" "testing" - "github.com/aquasecurity/vuln-list-update/redhat/securitydataapi" "github.com/kylelemons/godebug/pretty" + + "github.com/aquasecurity/vuln-list-update/redhat/securitydataapi" ) func TestRedhatCVEJSON_UnmarshalJSON(t *testing.T) { diff --git a/rocky/rocky.go b/rocky/rocky.go index cb570d9..07b17df 100644 --- a/rocky/rocky.go +++ b/rocky/rocky.go @@ -15,9 +15,10 @@ import ( "strings" "github.com/PuerkitoBio/goquery" - "github.com/aquasecurity/vuln-list-update/utils" "github.com/cheggaaa/pb/v3" "golang.org/x/xerrors" + + "github.com/aquasecurity/vuln-list-update/utils" ) const ( diff --git a/rocky/rocky_test.go b/rocky/rocky_test.go index 1886ce4..ba59561 100644 --- a/rocky/rocky_test.go +++ b/rocky/rocky_test.go @@ -7,9 +7,10 @@ import ( "path/filepath" "testing" - "github.com/aquasecurity/vuln-list-update/rocky" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/aquasecurity/vuln-list-update/rocky" ) func Test_Update(t *testing.T) { diff --git a/suse/cvrf/cvrf.go b/suse/cvrf/cvrf.go index 6f09c3b..d5cf003 100644 --- a/suse/cvrf/cvrf.go +++ b/suse/cvrf/cvrf.go @@ -11,10 +11,11 @@ import ( "strings" "unicode/utf8" - "github.com/aquasecurity/vuln-list-update/utils" "github.com/cheggaaa/pb" "github.com/spf13/afero" "golang.org/x/xerrors" + + "github.com/aquasecurity/vuln-list-update/utils" ) var ( diff --git a/suse/cvrf/cvrf_test.go b/suse/cvrf/cvrf_test.go index 7d96173..6066e0f 100644 --- a/suse/cvrf/cvrf_test.go +++ b/suse/cvrf/cvrf_test.go @@ -8,11 +8,10 @@ import ( "os" "testing" + "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/spf13/afero" - "github.com/aquasecurity/vuln-list-update/suse/cvrf" ) diff --git a/ubuntu/ubuntu.go b/ubuntu/ubuntu.go index bc215c4..b110220 100644 --- a/ubuntu/ubuntu.go +++ b/ubuntu/ubuntu.go @@ -9,12 +9,10 @@ import ( "strings" "time" - "github.com/aquasecurity/vuln-list-update/git" - "github.com/araddon/dateparse" - "golang.org/x/xerrors" + "github.com/aquasecurity/vuln-list-update/git" "github.com/aquasecurity/vuln-list-update/utils" ) diff --git a/ubuntu/ubuntu_test.go b/ubuntu/ubuntu_test.go index b2b2a15..9586a24 100644 --- a/ubuntu/ubuntu_test.go +++ b/ubuntu/ubuntu_test.go @@ -6,7 +6,6 @@ import ( "time" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) diff --git a/wolfi/wolfi_test.go b/wolfi/wolfi_test.go index 790e871..81a8897 100644 --- a/wolfi/wolfi_test.go +++ b/wolfi/wolfi_test.go @@ -9,10 +9,11 @@ import ( "os" "testing" - "github.com/aquasecurity/vuln-list-update/wolfi" "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/aquasecurity/vuln-list-update/wolfi" ) var update = flag.Bool("update", false, "update golden files")