aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ryancurrah
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2023-02-22 22:16:50 +0100
committerTaras Madan <tarasmadan@google.com>2023-02-24 12:47:23 +0100
commit4165372ec8fd142475a4e35fd0cf4f8042132208 (patch)
tree21cd62211b4dd80bee469054c5b65db77342333c /vendor/github.com/ryancurrah
parent2b3ed821a493b8936c8bacfa6f8b4f1c90a00855 (diff)
dependencies: update
set go min requirements to 1.19 update dependencies update vendor
Diffstat (limited to 'vendor/github.com/ryancurrah')
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/.golangci.yml3
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/.goreleaser.yml13
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/Dockerfile8
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/Dockerfile.goreleaser6
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/Makefile6
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/README.md2
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/allowed.go39
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/blocked.go189
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/cmd.go247
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/go.mod14
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/go.sum26
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/issue.go20
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/processor.go (renamed from vendor/github.com/ryancurrah/gomodguard/gomodguard.go)292
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/tools.go5
14 files changed, 310 insertions, 560 deletions
diff --git a/vendor/github.com/ryancurrah/gomodguard/.golangci.yml b/vendor/github.com/ryancurrah/gomodguard/.golangci.yml
index 0fbf6c04a..a0e6fd55e 100644
--- a/vendor/github.com/ryancurrah/gomodguard/.golangci.yml
+++ b/vendor/github.com/ryancurrah/gomodguard/.golangci.yml
@@ -60,7 +60,6 @@ linters:
enable:
- asciicheck
- bodyclose
- - deadcode
- dogsled
- dupl
- durationcheck
@@ -100,7 +99,6 @@ linters:
- rowserrcheck
- sqlclosecheck
- staticcheck
- - structcheck
- stylecheck
- testpackage
- thelper
@@ -109,6 +107,5 @@ linters:
- unconvert
- unparam
- unused
- - varcheck
- whitespace
- wsl
diff --git a/vendor/github.com/ryancurrah/gomodguard/.goreleaser.yml b/vendor/github.com/ryancurrah/gomodguard/.goreleaser.yml
index 3daecfd79..f3675a9c2 100644
--- a/vendor/github.com/ryancurrah/gomodguard/.goreleaser.yml
+++ b/vendor/github.com/ryancurrah/gomodguard/.goreleaser.yml
@@ -3,12 +3,12 @@ builds:
env:
- CGO_ENABLED=0
archives:
-- replacements:
- darwin: Darwin
- linux: Linux
- windows: Windows
- 386: i386
- amd64: x86_64
+- name_template: >-
+ {{ .ProjectName }}_
+ {{- title .Os }}_
+ {{- if eq .Arch "amd64" }}x86_64
+ {{- else if eq .Arch "386" }}i386
+ {{- else }}{{ .Arch }}{{ end }}
checksum:
name_template: 'checksums.txt'
dockers:
@@ -21,7 +21,6 @@ dockers:
dockerfile: Dockerfile.goreleaser
build_flag_templates:
- "--pull"
- - "--build-arg=gomodguard_VERSION={{.Version}}"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
diff --git a/vendor/github.com/ryancurrah/gomodguard/Dockerfile b/vendor/github.com/ryancurrah/gomodguard/Dockerfile
index 719a0ebdb..2f1d3340c 100644
--- a/vendor/github.com/ryancurrah/gomodguard/Dockerfile
+++ b/vendor/github.com/ryancurrah/gomodguard/Dockerfile
@@ -1,16 +1,12 @@
-ARG GO_VERSION=1.14.2
-ARG ALPINE_VERSION=3.11
-ARG gomodguard_VERSION=
-
# ---- Build container
-FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS builder
+FROM golang:alpine AS builder
WORKDIR /gomodguard
COPY . .
RUN apk add --no-cache git
RUN go build -o gomodguard cmd/gomodguard/main.go
# ---- App container
-FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION}
+FROM golang:alpine
WORKDIR /
RUN apk --no-cache add ca-certificates
COPY --from=builder gomodguard/gomodguard /
diff --git a/vendor/github.com/ryancurrah/gomodguard/Dockerfile.goreleaser b/vendor/github.com/ryancurrah/gomodguard/Dockerfile.goreleaser
index 57a042a67..ccaaa8959 100644
--- a/vendor/github.com/ryancurrah/gomodguard/Dockerfile.goreleaser
+++ b/vendor/github.com/ryancurrah/gomodguard/Dockerfile.goreleaser
@@ -1,9 +1,5 @@
-ARG GO_VERSION=1.14.2
-ARG ALPINE_VERSION=3.11
-ARG gomodguard_VERSION=
-
# ---- App container
-FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION}
+FROM golang:alpine
WORKDIR /
RUN apk --no-cache add ca-certificates
COPY gomodguard /gomodguard
diff --git a/vendor/github.com/ryancurrah/gomodguard/Makefile b/vendor/github.com/ryancurrah/gomodguard/Makefile
index 766675799..5235d5aad 100644
--- a/vendor/github.com/ryancurrah/gomodguard/Makefile
+++ b/vendor/github.com/ryancurrah/gomodguard/Makefile
@@ -24,6 +24,10 @@ cover:
dockerrun: dockerbuild
docker run -v "${current_dir}/.gomodguard.yaml:/.gomodguard.yaml" ryancurrah/gomodguard:latest
+.PHONY: snapshot
+snapshot:
+ goreleaser --rm-dist --snapshot
+
.PHONY: release
release:
goreleaser --rm-dist
@@ -39,4 +43,4 @@ install-tools-mac:
.PHONY: install-go-tools
install-go-tools:
- go get github.com/t-yuki/gocover-cobertura
+ go install -v github.com/t-yuki/gocover-cobertura
diff --git a/vendor/github.com/ryancurrah/gomodguard/README.md b/vendor/github.com/ryancurrah/gomodguard/README.md
index 8e2e41688..4945f0101 100644
--- a/vendor/github.com/ryancurrah/gomodguard/README.md
+++ b/vendor/github.com/ryancurrah/gomodguard/README.md
@@ -115,7 +115,7 @@ Resulting checkstyle file
## Install
```
-go get -u github.com/ryancurrah/gomodguard/cmd/gomodguard
+go install github.com/ryancurrah/gomodguard/cmd/gomodguard
```
## Develop
diff --git a/vendor/github.com/ryancurrah/gomodguard/allowed.go b/vendor/github.com/ryancurrah/gomodguard/allowed.go
new file mode 100644
index 000000000..5b0d26f83
--- /dev/null
+++ b/vendor/github.com/ryancurrah/gomodguard/allowed.go
@@ -0,0 +1,39 @@
+package gomodguard
+
+import "strings"
+
+// Allowed is a list of modules and module
+// domains that are allowed to be used.
+type Allowed struct {
+ Modules []string `yaml:"modules"`
+ Domains []string `yaml:"domains"`
+}
+
+// IsAllowedModule returns true if the given module
+// name is in the allowed modules list.
+func (a *Allowed) IsAllowedModule(moduleName string) bool {
+ allowedModules := a.Modules
+
+ for i := range allowedModules {
+ if strings.TrimSpace(moduleName) == strings.TrimSpace(allowedModules[i]) {
+ return true
+ }
+ }
+
+ return false
+}
+
+// IsAllowedModuleDomain returns true if the given modules domain is
+// in the allowed module domains list.
+func (a *Allowed) IsAllowedModuleDomain(moduleName string) bool {
+ allowedDomains := a.Domains
+
+ for i := range allowedDomains {
+ if strings.HasPrefix(strings.TrimSpace(strings.ToLower(moduleName)),
+ strings.TrimSpace(strings.ToLower(allowedDomains[i]))) {
+ return true
+ }
+ }
+
+ return false
+}
diff --git a/vendor/github.com/ryancurrah/gomodguard/blocked.go b/vendor/github.com/ryancurrah/gomodguard/blocked.go
new file mode 100644
index 000000000..2a6e5c215
--- /dev/null
+++ b/vendor/github.com/ryancurrah/gomodguard/blocked.go
@@ -0,0 +1,189 @@
+package gomodguard
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/Masterminds/semver"
+)
+
+// Blocked is a list of modules that are
+// blocked and not to be used.
+type Blocked struct {
+ Modules BlockedModules `yaml:"modules"`
+ Versions BlockedVersions `yaml:"versions"`
+ LocalReplaceDirectives bool `yaml:"local_replace_directives"`
+}
+
+// BlockedVersion has a version constraint a reason why the the module version is blocked.
+type BlockedVersion struct {
+ Version string `yaml:"version"`
+ Reason string `yaml:"reason"`
+}
+
+// IsLintedModuleVersionBlocked returns true if a version constraint is specified and the
+// linted module version matches the constraint.
+func (r *BlockedVersion) IsLintedModuleVersionBlocked(lintedModuleVersion string) bool {
+ if r.Version == "" {
+ return false
+ }
+
+ constraint, err := semver.NewConstraint(r.Version)
+ if err != nil {
+ return false
+ }
+
+ version, err := semver.NewVersion(lintedModuleVersion)
+ if err != nil {
+ return false
+ }
+
+ meet := constraint.Check(version)
+
+ return meet
+}
+
+// Message returns the reason why the module version is blocked.
+func (r *BlockedVersion) Message(lintedModuleVersion string) string {
+ var sb strings.Builder
+
+ // Add version contraint to message.
+ _, _ = fmt.Fprintf(&sb, "version `%s` is blocked because it does not meet the version constraint `%s`.",
+ lintedModuleVersion, r.Version)
+
+ if r.Reason == "" {
+ return sb.String()
+ }
+
+ // Add reason to message.
+ _, _ = fmt.Fprintf(&sb, " %s.", strings.TrimRight(r.Reason, "."))
+
+ return sb.String()
+}
+
+// BlockedModule has alternative modules to use and a reason why the module is blocked.
+type BlockedModule struct {
+ Recommendations []string `yaml:"recommendations"`
+ Reason string `yaml:"reason"`
+}
+
+// IsCurrentModuleARecommendation returns true if the current module is in the Recommendations list.
+//
+// If the current go.mod file being linted is a recommended module of a
+// blocked module and it imports that blocked module, do not set as blocked.
+// This could mean that the linted module is a wrapper for that blocked module.
+func (r *BlockedModule) IsCurrentModuleARecommendation(currentModuleName string) bool {
+ if r == nil {
+ return false
+ }
+
+ for n := range r.Recommendations {
+ if strings.TrimSpace(currentModuleName) == strings.TrimSpace(r.Recommendations[n]) {
+ return true
+ }
+ }
+
+ return false
+}
+
+// Message returns the reason why the module is blocked and a list of recommended modules if provided.
+func (r *BlockedModule) Message() string {
+ var sb strings.Builder
+
+ // Add recommendations to message
+ for i := range r.Recommendations {
+ switch {
+ case len(r.Recommendations) == 1:
+ _, _ = fmt.Fprintf(&sb, "`%s` is a recommended module.", r.Recommendations[i])
+ case (i+1) != len(r.Recommendations) && (i+1) == (len(r.Recommendations)-1):
+ _, _ = fmt.Fprintf(&sb, "`%s` ", r.Recommendations[i])
+ case (i + 1) != len(r.Recommendations):
+ _, _ = fmt.Fprintf(&sb, "`%s`, ", r.Recommendations[i])
+ default:
+ _, _ = fmt.Fprintf(&sb, "and `%s` are recommended modules.", r.Recommendations[i])
+ }
+ }
+
+ if r.Reason == "" {
+ return sb.String()
+ }
+
+ // Add reason to message
+ if sb.Len() == 0 {
+ _, _ = fmt.Fprintf(&sb, "%s.", strings.TrimRight(r.Reason, "."))
+ } else {
+ _, _ = fmt.Fprintf(&sb, " %s.", strings.TrimRight(r.Reason, "."))
+ }
+
+ return sb.String()
+}
+
+// HasRecommendations returns true if the blocked package has
+// recommended modules.
+func (r *BlockedModule) HasRecommendations() bool {
+ if r == nil {
+ return false
+ }
+
+ return len(r.Recommendations) > 0
+}
+
+// BlockedVersions a list of blocked modules by a version constraint.
+type BlockedVersions []map[string]BlockedVersion
+
+// Get returns the module names that are blocked.
+func (b BlockedVersions) Get() []string {
+ modules := make([]string, len(b))
+
+ for n := range b {
+ for module := range b[n] {
+ modules[n] = module
+ break
+ }
+ }
+
+ return modules
+}
+
+// GetBlockReason returns a block version if one is set for the provided linted module name.
+func (b BlockedVersions) GetBlockReason(lintedModuleName string) *BlockedVersion {
+ for _, blockedModule := range b {
+ for blockedModuleName, blockedVersion := range blockedModule {
+ if strings.TrimSpace(lintedModuleName) == strings.TrimSpace(blockedModuleName) {
+ return &blockedVersion
+ }
+ }
+ }
+
+ return nil
+}
+
+// BlockedModules a list of blocked modules.
+type BlockedModules []map[string]BlockedModule
+
+// Get returns the module names that are blocked.
+func (b BlockedModules) Get() []string {
+ modules := make([]string, len(b))
+
+ for n := range b {
+ for module := range b[n] {
+ modules[n] = module
+ break
+ }
+ }
+
+ return modules
+}
+
+// GetBlockReason returns a block module if one is set for the provided linted module name.
+func (b BlockedModules) GetBlockReason(lintedModuleName string) *BlockedModule {
+ for _, blockedModule := range b {
+ for blockedModuleName, blockedModule := range blockedModule {
+ if strings.TrimSpace(lintedModuleName) == strings.TrimSpace(blockedModuleName) {
+ return &blockedModule
+ }
+ }
+ }
+
+ return nil
+}
diff --git a/vendor/github.com/ryancurrah/gomodguard/cmd.go b/vendor/github.com/ryancurrah/gomodguard/cmd.go
deleted file mode 100644
index a26fac890..000000000
--- a/vendor/github.com/ryancurrah/gomodguard/cmd.go
+++ /dev/null
@@ -1,247 +0,0 @@
-package gomodguard
-
-import (
- "flag"
- "fmt"
- "io/ioutil"
- "log"
- "os"
- "path/filepath"
- "strings"
-
- "github.com/go-xmlfmt/xmlfmt"
- "github.com/mitchellh/go-homedir"
- "github.com/phayes/checkstyle"
- "gopkg.in/yaml.v2"
-)
-
-const (
- errFindingHomedir = "unable to find home directory, %w"
- errReadingConfigFile = "could not read config file: %w"
- errParsingConfigFile = "could not parse config file: %w"
-)
-
-var (
- configFile = ".gomodguard.yaml"
- logger = log.New(os.Stderr, "", 0)
- errFindingConfigFile = fmt.Errorf("could not find config file")
-)
-
-// Run the gomodguard linter. Returns the exit code to use.
-//nolint:funlen
-func Run() int {
- var (
- args []string
- help bool
- noTest bool
- report string
- reportFile string
- issuesExitCode int
- cwd, _ = os.Getwd()
- )
-
- flag.BoolVar(&help, "h", false, "Show this help text")
- flag.BoolVar(&help, "help", false, "")
- flag.BoolVar(&noTest, "n", false, "Don't lint test files")
- flag.BoolVar(&noTest, "no-test", false, "")
- flag.StringVar(&report, "r", "", "Report results to one of the following formats: checkstyle. "+
- "A report file destination must also be specified")
- flag.StringVar(&report, "report", "", "")
- flag.StringVar(&reportFile, "f", "", "Report results to the specified file. A report type must also be specified")
- flag.StringVar(&reportFile, "file", "", "")
- flag.IntVar(&issuesExitCode, "i", 2, "Exit code when issues were found")
- flag.IntVar(&issuesExitCode, "issues-exit-code", 2, "")
- flag.Parse()
-
- report = strings.TrimSpace(strings.ToLower(report))
-
- if help {
- showHelp()
- return 0
- }
-
- if report != "" && report != "checkstyle" {
- logger.Fatalf("error: invalid report type '%s'", report)
- }
-
- if report != "" && reportFile == "" {
- logger.Fatalf("error: a report file must be specified when a report is enabled")
- }
-
- if report == "" && reportFile != "" {
- logger.Fatalf("error: a report type must be specified when a report file is enabled")
- }
-
- args = flag.Args()
- if len(args) == 0 {
- args = []string{"./..."}
- }
-
- config, err := GetConfig(configFile)
- if err != nil {
- logger.Fatalf("error: %s", err)
- }
-
- filteredFiles := GetFilteredFiles(cwd, noTest, args)
-
- processor, err := NewProcessor(config)
- if err != nil {
- logger.Fatalf("error: %s", err)
- }
-
- logger.Printf("info: allowed modules, %+v", config.Allowed.Modules)
- logger.Printf("info: allowed module domains, %+v", config.Allowed.Domains)
- logger.Printf("info: blocked modules, %+v", config.Blocked.Modules.Get())
- logger.Printf("info: blocked modules with version constraints, %+v", config.Blocked.Versions.Get())
-
- results := processor.ProcessFiles(filteredFiles)
-
- if report == "checkstyle" {
- err := WriteCheckstyle(reportFile, results)
- if err != nil {
- logger.Fatalf("error: %s", err)
- }
- }
-
- for _, r := range results {
- fmt.Println(r.String())
- }
-
- if len(results) > 0 {
- return issuesExitCode
- }
-
- return 0
-}
-
-// GetConfig from YAML file.
-func GetConfig(configFile string) (*Configuration, error) {
- config := Configuration{}
-
- home, err := homedir.Dir()
- if err != nil {
- return nil, fmt.Errorf(errFindingHomedir, err)
- }
-
- cfgFile := ""
- homeDirCfgFile := filepath.Join(home, configFile)
-
- switch {
- case fileExists(configFile):
- cfgFile = configFile
- case fileExists(homeDirCfgFile):
- cfgFile = homeDirCfgFile
- default:
- return nil, fmt.Errorf("%w: %s %s", errFindingConfigFile, configFile, homeDirCfgFile)
- }
-
- data, err := ioutil.ReadFile(cfgFile)
- if err != nil {
- return nil, fmt.Errorf(errReadingConfigFile, err)
- }
-
- err = yaml.Unmarshal(data, &config)
- if err != nil {
- return nil, fmt.Errorf(errParsingConfigFile, err)
- }
-
- return &config, nil
-}
-
-// GetFilteredFiles returns files based on search string arguments and filters.
-func GetFilteredFiles(cwd string, skipTests bool, args []string) []string {
- var (
- foundFiles = []string{}
- filteredFiles = []string{}
- )
-
- for _, f := range args {
- if strings.HasSuffix(f, "/...") {
- dir, _ := filepath.Split(f)
-
- foundFiles = append(foundFiles, expandGoWildcard(dir)...)
-
- continue
- }
-
- if _, err := os.Stat(f); err == nil {
- foundFiles = append(foundFiles, f)
- }
- }
-
- // Use relative path to print shorter names, sort out test foundFiles if chosen.
- for _, f := range foundFiles {
- if skipTests {
- if strings.HasSuffix(f, "_test.go") {
- continue
- }
- }
-
- if relativePath, err := filepath.Rel(cwd, f); err == nil {
- filteredFiles = append(filteredFiles, relativePath)
-
- continue
- }
-
- filteredFiles = append(filteredFiles, f)
- }
-
- return filteredFiles
-}
-
-// showHelp text for command line.
-func showHelp() {
- helpText := `Usage: gomodguard <file> [files...]
-Also supports package syntax but will use it in relative path, i.e. ./pkg/...
-Flags:`
- fmt.Println(helpText)
- flag.PrintDefaults()
-}
-
-// WriteCheckstyle takes the results and writes them to a checkstyle formated file.
-func WriteCheckstyle(checkstyleFilePath string, results []Issue) error {
- check := checkstyle.New()
-
- for i := range results {
- file := check.EnsureFile(results[i].FileName)
- file.AddError(checkstyle.NewError(results[i].LineNumber, 1, checkstyle.SeverityError, results[i].Reason,
- "gomodguard"))
- }
-
- checkstyleXML := fmt.Sprintf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n%s", check.String())
-
- err := ioutil.WriteFile(checkstyleFilePath, []byte(xmlfmt.FormatXML(checkstyleXML, "", " ")), 0644) // nolint:gosec
- if err != nil {
- return err
- }
-
- return nil
-}
-
-// fileExists returns true if the file path provided exists.
-func fileExists(filename string) bool {
- info, err := os.Stat(filename)
- if os.IsNotExist(err) {
- return false
- }
-
- return !info.IsDir()
-}
-
-// expandGoWildcard path provided.
-func expandGoWildcard(root string) []string {
- foundFiles := []string{}
-
- _ = filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
- // Only append go foundFiles.
- if !strings.HasSuffix(info.Name(), ".go") {
- return nil
- }
-
- foundFiles = append(foundFiles, path)
-
- return nil
- })
-
- return foundFiles
-}
diff --git a/vendor/github.com/ryancurrah/gomodguard/go.mod b/vendor/github.com/ryancurrah/gomodguard/go.mod
deleted file mode 100644
index 3db75853a..000000000
--- a/vendor/github.com/ryancurrah/gomodguard/go.mod
+++ /dev/null
@@ -1,14 +0,0 @@
-module github.com/ryancurrah/gomodguard
-
-go 1.16
-
-require (
- github.com/Masterminds/semver v1.5.0
- github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b
- github.com/mitchellh/go-homedir v1.1.0
- github.com/phayes/checkstyle v0.0.0-20170904204023-bfd46e6a821d
- golang.org/x/mod v0.5.1
- gopkg.in/yaml.v2 v2.4.0
-)
-
-retract v1.2.1 // Originally tagged for commit hash that was subsequently removed, and replaced by another commit hash
diff --git a/vendor/github.com/ryancurrah/gomodguard/go.sum b/vendor/github.com/ryancurrah/gomodguard/go.sum
deleted file mode 100644
index df976547e..000000000
--- a/vendor/github.com/ryancurrah/gomodguard/go.sum
+++ /dev/null
@@ -1,26 +0,0 @@
-github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
-github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
-github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b h1:khEcpUM4yFcxg4/FHQWkvVRmgijNXRfzkIDHh23ggEo=
-github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM=
-github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
-github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
-github.com/phayes/checkstyle v0.0.0-20170904204023-bfd46e6a821d h1:CdDQnGF8Nq9ocOS/xlSptM1N3BbrA6/kmaep5ggwaIA=
-github.com/phayes/checkstyle v0.0.0-20170904204023-bfd46e6a821d/go.mod h1:3OzsM7FXDQlpCiw2j81fOmAwQLnZnLGXVKUzeKQXIAw=
-golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
-golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
-golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
-golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
-golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
-golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
-golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
-golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
-golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
-gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
diff --git a/vendor/github.com/ryancurrah/gomodguard/issue.go b/vendor/github.com/ryancurrah/gomodguard/issue.go
new file mode 100644
index 000000000..d60fc3a86
--- /dev/null
+++ b/vendor/github.com/ryancurrah/gomodguard/issue.go
@@ -0,0 +1,20 @@
+package gomodguard
+
+import (
+ "fmt"
+ "go/token"
+)
+
+// Issue represents the result of one error.
+type Issue struct {
+ FileName string
+ LineNumber int
+ Position token.Position
+ Reason string
+}
+
+// String returns the filename, line
+// number and reason of a Issue.
+func (r *Issue) String() string {
+ return fmt.Sprintf("%s:%d:1 %s", r.FileName, r.LineNumber, r.Reason)
+}
diff --git a/vendor/github.com/ryancurrah/gomodguard/gomodguard.go b/vendor/github.com/ryancurrah/gomodguard/processor.go
index efd0d17ef..8457e3b07 100644
--- a/vendor/github.com/ryancurrah/gomodguard/gomodguard.go
+++ b/vendor/github.com/ryancurrah/gomodguard/processor.go
@@ -7,14 +7,11 @@ import (
"fmt"
"go/parser"
"go/token"
- "io/ioutil"
"os"
"os/exec"
"regexp"
"strings"
- "github.com/Masterminds/semver"
-
"golang.org/x/mod/modfile"
)
@@ -33,248 +30,17 @@ var (
"local replace directive."
// startsWithVersion is used to test when a string begins with the version identifier of a module,
- // after having stripped the prefix base module name. IE "github.com/foo/bar/v2/baz" => "/v2/baz"
+ // after having stripped the prefix base module name. IE "github.com/foo/bar/v2/baz" => "v2/baz"
// probably indicates that the module is actually github.com/foo/bar/v2, not github.com/foo/bar.
- startsWithVersion = regexp.MustCompile(`^\/v[0-9]+`)
+ startsWithVersion = regexp.MustCompile(`^v[0-9]+`)
)
-// BlockedVersion has a version constraint a reason why the the module version is blocked.
-type BlockedVersion struct {
- Version string `yaml:"version"`
- Reason string `yaml:"reason"`
-}
-
-// IsLintedModuleVersionBlocked returns true if a version constraint is specified and the
-// linted module version matches the constraint.
-func (r *BlockedVersion) IsLintedModuleVersionBlocked(lintedModuleVersion string) bool {
- if r.Version == "" {
- return false
- }
-
- constraint, err := semver.NewConstraint(r.Version)
- if err != nil {
- return false
- }
-
- version, err := semver.NewVersion(lintedModuleVersion)
- if err != nil {
- return false
- }
-
- meet := constraint.Check(version)
-
- return meet
-}
-
-// Message returns the reason why the module version is blocked.
-func (r *BlockedVersion) Message(lintedModuleVersion string) string {
- var sb strings.Builder
-
- // Add version contraint to message.
- _, _ = fmt.Fprintf(&sb, "version `%s` is blocked because it does not meet the version constraint `%s`.",
- lintedModuleVersion, r.Version)
-
- if r.Reason == "" {
- return sb.String()
- }
-
- // Add reason to message.
- _, _ = fmt.Fprintf(&sb, " %s.", strings.TrimRight(r.Reason, "."))
-
- return sb.String()
-}
-
-// BlockedModule has alternative modules to use and a reason why the module is blocked.
-type BlockedModule struct {
- Recommendations []string `yaml:"recommendations"`
- Reason string `yaml:"reason"`
-}
-
-// IsCurrentModuleARecommendation returns true if the current module is in the Recommendations list.
-//
-// If the current go.mod file being linted is a recommended module of a
-// blocked module and it imports that blocked module, do not set as blocked.
-// This could mean that the linted module is a wrapper for that blocked module.
-func (r *BlockedModule) IsCurrentModuleARecommendation(currentModuleName string) bool {
- if r == nil {
- return false
- }
-
- for n := range r.Recommendations {
- if strings.TrimSpace(currentModuleName) == strings.TrimSpace(r.Recommendations[n]) {
- return true
- }
- }
-
- return false
-}
-
-// Message returns the reason why the module is blocked and a list of recommended modules if provided.
-func (r *BlockedModule) Message() string {
- var sb strings.Builder
-
- // Add recommendations to message
- for i := range r.Recommendations {
- switch {
- case len(r.Recommendations) == 1:
- _, _ = fmt.Fprintf(&sb, "`%s` is a recommended module.", r.Recommendations[i])
- case (i+1) != len(r.Recommendations) && (i+1) == (len(r.Recommendations)-1):
- _, _ = fmt.Fprintf(&sb, "`%s` ", r.Recommendations[i])
- case (i + 1) != len(r.Recommendations):
- _, _ = fmt.Fprintf(&sb, "`%s`, ", r.Recommendations[i])
- default:
- _, _ = fmt.Fprintf(&sb, "and `%s` are recommended modules.", r.Recommendations[i])
- }
- }
-
- if r.Reason == "" {
- return sb.String()
- }
-
- // Add reason to message
- if sb.Len() == 0 {
- _, _ = fmt.Fprintf(&sb, "%s.", strings.TrimRight(r.Reason, "."))
- } else {
- _, _ = fmt.Fprintf(&sb, " %s.", strings.TrimRight(r.Reason, "."))
- }
-
- return sb.String()
-}
-
-// HasRecommendations returns true if the blocked package has
-// recommended modules.
-func (r *BlockedModule) HasRecommendations() bool {
- if r == nil {
- return false
- }
-
- return len(r.Recommendations) > 0
-}
-
-// BlockedVersions a list of blocked modules by a version constraint.
-type BlockedVersions []map[string]BlockedVersion
-
-// Get returns the module names that are blocked.
-func (b BlockedVersions) Get() []string {
- modules := make([]string, len(b))
-
- for n := range b {
- for module := range b[n] {
- modules[n] = module
- break
- }
- }
-
- return modules
-}
-
-// GetBlockReason returns a block version if one is set for the provided linted module name.
-func (b BlockedVersions) GetBlockReason(lintedModuleName string) *BlockedVersion {
- for _, blockedModule := range b {
- for blockedModuleName, blockedVersion := range blockedModule {
- if strings.TrimSpace(lintedModuleName) == strings.TrimSpace(blockedModuleName) {
- return &blockedVersion
- }
- }
- }
-
- return nil
-}
-
-// BlockedModules a list of blocked modules.
-type BlockedModules []map[string]BlockedModule
-
-// Get returns the module names that are blocked.
-func (b BlockedModules) Get() []string {
- modules := make([]string, len(b))
-
- for n := range b {
- for module := range b[n] {
- modules[n] = module
- break
- }
- }
-
- return modules
-}
-
-// GetBlockReason returns a block module if one is set for the provided linted module name.
-func (b BlockedModules) GetBlockReason(lintedModuleName string) *BlockedModule {
- for _, blockedModule := range b {
- for blockedModuleName, blockedModule := range blockedModule {
- if strings.TrimSpace(lintedModuleName) == strings.TrimSpace(blockedModuleName) {
- return &blockedModule
- }
- }
- }
-
- return nil
-}
-
-// Allowed is a list of modules and module
-// domains that are allowed to be used.
-type Allowed struct {
- Modules []string `yaml:"modules"`
- Domains []string `yaml:"domains"`
-}
-
-// IsAllowedModule returns true if the given module
-// name is in the allowed modules list.
-func (a *Allowed) IsAllowedModule(moduleName string) bool {
- allowedModules := a.Modules
-
- for i := range allowedModules {
- if strings.TrimSpace(moduleName) == strings.TrimSpace(allowedModules[i]) {
- return true
- }
- }
-
- return false
-}
-
-// IsAllowedModuleDomain returns true if the given modules domain is
-// in the allowed module domains list.
-func (a *Allowed) IsAllowedModuleDomain(moduleName string) bool {
- allowedDomains := a.Domains
-
- for i := range allowedDomains {
- if strings.HasPrefix(strings.TrimSpace(strings.ToLower(moduleName)),
- strings.TrimSpace(strings.ToLower(allowedDomains[i]))) {
- return true
- }
- }
-
- return false
-}
-
-// Blocked is a list of modules that are
-// blocked and not to be used.
-type Blocked struct {
- Modules BlockedModules `yaml:"modules"`
- Versions BlockedVersions `yaml:"versions"`
- LocalReplaceDirectives bool `yaml:"local_replace_directives"`
-}
-
// Configuration of gomodguard allow and block lists.
type Configuration struct {
Allowed Allowed `yaml:"allowed"`
Blocked Blocked `yaml:"blocked"`
}
-// Issue represents the result of one error.
-type Issue struct {
- FileName string
- LineNumber int
- Position token.Position
- Reason string
-}
-
-// String returns the filename, line
-// number and reason of a Issue.
-func (r *Issue) String() string {
- return fmt.Sprintf("%s:%d:1 %s", r.FileName, r.LineNumber, r.Reason)
-}
-
// Processor processes Go files.
type Processor struct {
Config *Configuration
@@ -308,7 +74,7 @@ func NewProcessor(config *Configuration) (*Processor, error) {
// and lints them.
func (p *Processor) ProcessFiles(filenames []string) (issues []Issue) {
for _, filename := range filenames {
- data, err := ioutil.ReadFile(filename)
+ data, err := os.ReadFile(filename)
if err != nil {
issues = append(issues, Issue{
FileName: filename,
@@ -443,14 +209,7 @@ func (p *Processor) SetBlockedModules() { //nolint:gocognit,funlen
// isBlockedPackageFromModFile returns the block reason if the package is blocked.
func (p *Processor) isBlockedPackageFromModFile(packageName string) []string {
for blockedModuleName, blockReasons := range p.blockedModulesFromModFile {
- if strings.HasPrefix(strings.TrimSpace(packageName), strings.TrimSpace(blockedModuleName)) {
- // Test if a versioned module matched its base version
- // ie github.com/foo/bar/v2 matched github.com/foo/bar, even though the former may be allowed.
- suffix := strings.TrimPrefix(strings.TrimSpace(packageName), strings.TrimSpace(blockedModuleName))
- if startsWithVersion.MatchString(suffix) {
- continue
- }
-
+ if isPackageInModule(packageName, blockedModuleName) {
formattedReasons := make([]string, 0, len(blockReasons))
for _, blockReason := range blockReasons {
@@ -470,7 +229,7 @@ func loadGoModFile() ([]byte, error) {
_ = cmd.Start()
if stdout == nil {
- return ioutil.ReadFile(goModFilename)
+ return os.ReadFile(goModFilename)
}
buf := new(bytes.Buffer)
@@ -480,20 +239,53 @@ func loadGoModFile() ([]byte, error) {
err := json.Unmarshal(buf.Bytes(), &goEnv)
if err != nil {
- return ioutil.ReadFile(goModFilename)
+ return os.ReadFile(goModFilename)
}
if _, ok := goEnv["GOMOD"]; !ok {
- return ioutil.ReadFile(goModFilename)
+ return os.ReadFile(goModFilename)
}
if _, err = os.Stat(goEnv["GOMOD"]); os.IsNotExist(err) {
- return ioutil.ReadFile(goModFilename)
+ return os.ReadFile(goModFilename)
}
if goEnv["GOMOD"] == "/dev/null" {
return nil, errors.New("current working directory must have a go.mod file")
}
- return ioutil.ReadFile(goEnv["GOMOD"])
+ return os.ReadFile(goEnv["GOMOD"])
+}
+
+// isPackageInModule determines if a package is apart of the specified go module.
+func isPackageInModule(pkg, mod string) bool {
+ // Split pkg and mod paths into parts
+ pkgPart := strings.Split(pkg, "/")
+ modPart := strings.Split(mod, "/")
+
+ pkgPartMatches := 0
+
+ // Count number of times pkg path matches the mod path
+ for i, m := range modPart {
+ if len(pkgPart) > i && pkgPart[i] == m {
+ pkgPartMatches++
+ }
+ }
+
+ // If pkgPartMatches are not the same length as modPart
+ // than the package is not in this module
+ if pkgPartMatches != len(modPart) {
+ return false
+ }
+
+ if len(pkgPart) > len(modPart) {
+ // If pkgPart path starts with a major version
+ // than the package is not in this module as
+ // major versions are completely different modules
+ if startsWithVersion.MatchString(pkgPart[len(modPart)]) {
+ return false
+ }
+ }
+
+ return true
}
diff --git a/vendor/github.com/ryancurrah/gomodguard/tools.go b/vendor/github.com/ryancurrah/gomodguard/tools.go
new file mode 100644
index 000000000..d56bcc747
--- /dev/null
+++ b/vendor/github.com/ryancurrah/gomodguard/tools.go
@@ -0,0 +1,5 @@
+//go:build tools
+
+package gomodguard
+
+import _ "github.com/t-yuki/gocover-cobertura"