aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ryancurrah
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2022-09-05 14:27:54 +0200
committerGitHub <noreply@github.com>2022-09-05 12:27:54 +0000
commitb2f2446b46bf02821d90ebedadae2bf7ae0e880e (patch)
tree923cf42842918d6bebca1d6bbdc08abed54d274d /vendor/github.com/ryancurrah
parente6654faff4bcca4be92e9a8596fd4b77f747c39e (diff)
go.mod, vendor: update (#3358)
* go.mod, vendor: remove unnecessary dependencies Commands: 1. go mod tidy 2. go mod vendor * go.mod, vendor: update cloud.google.com/go Commands: 1. go get -u cloud.google.com/go 2. go mod tidy 3. go mod vendor * go.mod, vendor: update cloud.google.com/* Commands: 1. go get -u cloud.google.com/storage cloud.google.com/logging 2. go mod tidy 3. go mod vendor * go.mod, .golangci.yml, vendor: update *lint* Commands: 1. go get -u golang.org/x/tools github.com/golangci/golangci-lint@v1.47.0 2. go mod tidy 3. go mod vendor 4. edit .golangci.yml to suppress new errors (resolved in the same PR later) * all: fix lint errors hash.go: copy() recommended by gosimple parse.go: ent is never nil verifier.go: signal.Notify() with unbuffered channel is bad. Have no idea why. * .golangci.yml: adjust godot rules check-all is deprecated, but still work if you're hesitating too - I'll remove this commit
Diffstat (limited to 'vendor/github.com/ryancurrah')
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/.gitignore4
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/.golangci.yml118
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/.goreleaser.yml2
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/Makefile29
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/VERSION1
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/cmd.go9
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/go.mod6
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/go.sum4
-rw-r--r--vendor/github.com/ryancurrah/gomodguard/gomodguard.go112
9 files changed, 209 insertions, 76 deletions
diff --git a/vendor/github.com/ryancurrah/gomodguard/.gitignore b/vendor/github.com/ryancurrah/gomodguard/.gitignore
index 030056d46..4ebc79c5d 100644
--- a/vendor/github.com/ryancurrah/gomodguard/.gitignore
+++ b/vendor/github.com/ryancurrah/gomodguard/.gitignore
@@ -20,4 +20,6 @@
dist/
-coverage.* \ No newline at end of file
+coverage.*
+
+.idea/
diff --git a/vendor/github.com/ryancurrah/gomodguard/.golangci.yml b/vendor/github.com/ryancurrah/gomodguard/.golangci.yml
index 9c19e63a1..0fbf6c04a 100644
--- a/vendor/github.com/ryancurrah/gomodguard/.golangci.yml
+++ b/vendor/github.com/ryancurrah/gomodguard/.golangci.yml
@@ -1,6 +1,114 @@
+# See https://golangci-lint.run/usage/configuration/
+
+linters-settings:
+ revive:
+ # see https://github.com/mgechev/revive#available-rules for details.
+ ignore-generated-header: true
+ severity: warning
+ rules:
+ - name: atomic
+ - name: blank-imports
+ - name: bool-literal-in-expr
+ - name: call-to-gc
+ - name: confusing-naming
+ - name: confusing-results
+ - name: constant-logical-expr
+ - name: context-as-argument
+ - name: context-keys-type
+ - name: deep-exit
+ - name: defer
+ - name: dot-imports
+ - name: duplicated-imports
+ - name: early-return
+ - name: empty-block
+ - name: empty-lines
+ - name: error-naming
+ - name: error-return
+ - name: error-strings
+ - name: errorf
+ - name: exported
+ - name: get-return
+ - name: identical-branches
+ - name: if-return
+ - name: import-shadowing
+ - name: increment-decrement
+ - name: indent-error-flow
+ - name: modifies-parameter
+ - name: modifies-value-receiver
+ - name: package-comments
+ - name: range
+ - name: range-val-address
+ - name: range-val-in-closure
+ - name: receiver-naming
+ - name: redefines-builtin-id
+ - name: string-of-int
+ - name: struct-tag
+ - name: superfluous-else
+ - name: time-naming
+ - name: unconditional-recursion
+ - name: unexported-naming
+ - name: unexported-return
+ - name: unnecessary-stmt
+ - name: unreachable-code
+ - name: unused-parameter
+ - name: var-declaration
+ - name: var-naming
+ - name: waitgroup-by-value
+
linters:
- enable-all: true
- disable:
- - funlen
- - gochecknoglobals
- - lll
+ disable-all: true
+ enable:
+ - asciicheck
+ - bodyclose
+ - deadcode
+ - dogsled
+ - dupl
+ - durationcheck
+ - errcheck
+ - errorlint
+ - exhaustive
+ - exportloopref
+ - forcetypeassert
+ - funlen
+ - gochecknoinits
+ - gocognit
+ - goconst
+ - gocritic
+ - gocyclo
+ - godot
+ - godox
+ - goimports
+ - gomoddirectives
+ - gomodguard
+ - goprintffuncname
+ - gosec
+ - gosimple
+ - govet
+ - importas
+ - ineffassign
+ - lll
+ - makezero
+ - misspell
+ - nakedret
+ - nestif
+ - nilerr
+ - noctx
+ - nolintlint
+ - prealloc
+ - predeclared
+ - revive
+ - rowserrcheck
+ - sqlclosecheck
+ - staticcheck
+ - structcheck
+ - stylecheck
+ - testpackage
+ - thelper
+ - tparallel
+ - typecheck
+ - 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 20d834992..3daecfd79 100644
--- a/vendor/github.com/ryancurrah/gomodguard/.goreleaser.yml
+++ b/vendor/github.com/ryancurrah/gomodguard/.goreleaser.yml
@@ -14,8 +14,6 @@ checksum:
dockers:
- goos: linux
goarch: amd64
- binaries:
- - gomodguard
image_templates:
- "ryancurrah/gomodguard:latest"
- "ryancurrah/gomodguard:{{.Tag}}"
diff --git a/vendor/github.com/ryancurrah/gomodguard/Makefile b/vendor/github.com/ryancurrah/gomodguard/Makefile
index 9af2f76e4..766675799 100644
--- a/vendor/github.com/ryancurrah/gomodguard/Makefile
+++ b/vendor/github.com/ryancurrah/gomodguard/Makefile
@@ -1,49 +1,42 @@
current_dir = $(shell pwd)
-version = $(shell printf '%s' $$(cat VERSION))
-.PHONEY: lint
+.PHONY: lint
lint:
golangci-lint run ./...
-.PHONEY: build
+.PHONY: build
build:
go build -o gomodguard cmd/gomodguard/main.go
-.PHONEY: dockerbuild
-dockerbuild:
- docker build --build-arg GOMODGUARD_VERSION=${version} --tag ryancurrah/gomodguard:${version} .
-
-.PHONEY: run
+.PHONY: run
run: build
./gomodguard
-.PHONEY: test
+.PHONY: test
test:
go test -v -coverprofile coverage.out
-.PHONEY: cover
+.PHONY: cover
cover:
gocover-cobertura < coverage.out > coverage.xml
-.PHONEY: dockerrun
+.PHONY: dockerrun
dockerrun: dockerbuild
docker run -v "${current_dir}/.gomodguard.yaml:/.gomodguard.yaml" ryancurrah/gomodguard:latest
-.PHONEY: release
+.PHONY: release
release:
- git tag ${version}
- git push --tags
- goreleaser --skip-validate --rm-dist
+ goreleaser --rm-dist
-.PHONEY: clean
+.PHONY: clean
clean:
rm -rf dist/
rm -f gomodguard coverage.xml coverage.out
-.PHONEY: install-tools-mac
+.PHONY: install-mac-tools
install-tools-mac:
brew install goreleaser/tap/goreleaser
-.PHONEY: install-go-tools
+.PHONY: install-go-tools
install-go-tools:
go get github.com/t-yuki/gocover-cobertura
diff --git a/vendor/github.com/ryancurrah/gomodguard/VERSION b/vendor/github.com/ryancurrah/gomodguard/VERSION
deleted file mode 100644
index 795460fce..000000000
--- a/vendor/github.com/ryancurrah/gomodguard/VERSION
+++ /dev/null
@@ -1 +0,0 @@
-v1.1.0
diff --git a/vendor/github.com/ryancurrah/gomodguard/cmd.go b/vendor/github.com/ryancurrah/gomodguard/cmd.go
index 89a22aeb6..a26fac890 100644
--- a/vendor/github.com/ryancurrah/gomodguard/cmd.go
+++ b/vendor/github.com/ryancurrah/gomodguard/cmd.go
@@ -28,6 +28,7 @@ var (
)
// Run the gomodguard linter. Returns the exit code to use.
+//nolint:funlen
func Run() int {
var (
args []string
@@ -43,7 +44,8 @@ func Run() int {
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, "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", "", "")
@@ -197,12 +199,13 @@ Flags:`
}
// WriteCheckstyle takes the results and writes them to a checkstyle formated file.
-func WriteCheckstyle(checkstyleFilePath string, results []Result) error {
+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"))
+ 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())
diff --git a/vendor/github.com/ryancurrah/gomodguard/go.mod b/vendor/github.com/ryancurrah/gomodguard/go.mod
index 1f1748355..3db75853a 100644
--- a/vendor/github.com/ryancurrah/gomodguard/go.mod
+++ b/vendor/github.com/ryancurrah/gomodguard/go.mod
@@ -1,12 +1,14 @@
module github.com/ryancurrah/gomodguard
-go 1.14
+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.4.0
+ 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
index ccbc5e032..df976547e 100644
--- a/vendor/github.com/ryancurrah/gomodguard/go.sum
+++ b/vendor/github.com/ryancurrah/gomodguard/go.sum
@@ -8,8 +8,8 @@ github.com/phayes/checkstyle v0.0.0-20170904204023-bfd46e6a821d h1:CdDQnGF8Nq9oc
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.4.0 h1:8pl+sMODzuvGJkmj2W4kZihvVb5mKm8pB/X44PIQHv8=
-golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+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=
diff --git a/vendor/github.com/ryancurrah/gomodguard/gomodguard.go b/vendor/github.com/ryancurrah/gomodguard/gomodguard.go
index 3f2cc0d86..efd0d17ef 100644
--- a/vendor/github.com/ryancurrah/gomodguard/gomodguard.go
+++ b/vendor/github.com/ryancurrah/gomodguard/gomodguard.go
@@ -3,12 +3,14 @@ package gomodguard
import (
"bytes"
"encoding/json"
+ "errors"
"fmt"
"go/parser"
"go/token"
"io/ioutil"
"os"
"os/exec"
+ "regexp"
"strings"
"github.com/Masterminds/semver"
@@ -18,14 +20,22 @@ import (
const (
goModFilename = "go.mod"
- errReadingGoModFile = "unable to read go mod file %s: %w"
- errParsingGoModFile = "unable to parsing go mod file %s: %w"
+ errReadingGoModFile = "unable to read module file %s: %w"
+ errParsingGoModFile = "unable to parse module file %s: %w"
)
var (
- blockReasonNotInAllowedList = "import of package `%s` is blocked because the module is not in the allowed modules list."
- blockReasonInBlockedList = "import of package `%s` is blocked because the module is in the blocked modules list."
- blockReasonHasLocalReplaceDirective = "import of package `%s` is blocked because the module has a local replace directive."
+ blockReasonNotInAllowedList = "import of package `%s` is blocked because the module is not in the " +
+ "allowed modules list."
+ blockReasonInBlockedList = "import of package `%s` is blocked because the module is in the " +
+ "blocked modules list."
+ blockReasonHasLocalReplaceDirective = "import of package `%s` is blocked because the module has a " +
+ "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"
+ // probably indicates that the module is actually github.com/foo/bar/v2, not github.com/foo/bar.
+ startsWithVersion = regexp.MustCompile(`^\/v[0-9]+`)
)
// BlockedVersion has a version constraint a reason why the the module version is blocked.
@@ -58,19 +68,20 @@ func (r *BlockedVersion) IsLintedModuleVersionBlocked(lintedModuleVersion string
// Message returns the reason why the module version is blocked.
func (r *BlockedVersion) Message(lintedModuleVersion string) string {
- msg := ""
+ var sb strings.Builder
// Add version contraint to message.
- msg += fmt.Sprintf("version `%s` is blocked because it does not meet the version constraint `%s`.", lintedModuleVersion, r.Version)
+ _, _ = fmt.Fprintf(&sb, "version `%s` is blocked because it does not meet the version constraint `%s`.",
+ lintedModuleVersion, r.Version)
if r.Reason == "" {
- return msg
+ return sb.String()
}
// Add reason to message.
- msg += fmt.Sprintf(" %s.", strings.TrimRight(r.Reason, "."))
+ _, _ = fmt.Fprintf(&sb, " %s.", strings.TrimRight(r.Reason, "."))
- return msg
+ return sb.String()
}
// BlockedModule has alternative modules to use and a reason why the module is blocked.
@@ -100,34 +111,34 @@ func (r *BlockedModule) IsCurrentModuleARecommendation(currentModuleName string)
// Message returns the reason why the module is blocked and a list of recommended modules if provided.
func (r *BlockedModule) Message() string {
- msg := ""
+ var sb strings.Builder
// Add recommendations to message
for i := range r.Recommendations {
switch {
case len(r.Recommendations) == 1:
- msg += fmt.Sprintf("`%s` is a recommended module.", r.Recommendations[i])
+ _, _ = fmt.Fprintf(&sb, "`%s` is a recommended module.", r.Recommendations[i])
case (i+1) != len(r.Recommendations) && (i+1) == (len(r.Recommendations)-1):
- msg += fmt.Sprintf("`%s` ", r.Recommendations[i])
+ _, _ = fmt.Fprintf(&sb, "`%s` ", r.Recommendations[i])
case (i + 1) != len(r.Recommendations):
- msg += fmt.Sprintf("`%s`, ", r.Recommendations[i])
+ _, _ = fmt.Fprintf(&sb, "`%s`, ", r.Recommendations[i])
default:
- msg += fmt.Sprintf("and `%s` are recommended modules.", r.Recommendations[i])
+ _, _ = fmt.Fprintf(&sb, "and `%s` are recommended modules.", r.Recommendations[i])
}
}
if r.Reason == "" {
- return msg
+ return sb.String()
}
// Add reason to message
- if msg == "" {
- msg = fmt.Sprintf("%s.", strings.TrimRight(r.Reason, "."))
+ if sb.Len() == 0 {
+ _, _ = fmt.Fprintf(&sb, "%s.", strings.TrimRight(r.Reason, "."))
} else {
- msg += fmt.Sprintf(" %s.", strings.TrimRight(r.Reason, "."))
+ _, _ = fmt.Fprintf(&sb, " %s.", strings.TrimRight(r.Reason, "."))
}
- return msg
+ return sb.String()
}
// HasRecommendations returns true if the blocked package has
@@ -227,7 +238,8 @@ 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]))) {
+ if strings.HasPrefix(strings.TrimSpace(strings.ToLower(moduleName)),
+ strings.TrimSpace(strings.ToLower(allowedDomains[i]))) {
return true
}
}
@@ -249,8 +261,8 @@ type Configuration struct {
Blocked Blocked `yaml:"blocked"`
}
-// Result represents the result of one error.
-type Result struct {
+// Issue represents the result of one error.
+type Issue struct {
FileName string
LineNumber int
Position token.Position
@@ -258,8 +270,8 @@ type Result struct {
}
// String returns the filename, line
-// number and reason of a Result.
-func (r *Result) String() string {
+// number and reason of a Issue.
+func (r *Issue) String() string {
return fmt.Sprintf("%s:%d:1 %s", r.FileName, r.LineNumber, r.Reason)
}
@@ -268,7 +280,6 @@ type Processor struct {
Config *Configuration
Modfile *modfile.File
blockedModulesFromModFile map[string][]string
- Result []Result
}
// NewProcessor will create a Processor to lint blocked packages.
@@ -286,7 +297,6 @@ func NewProcessor(config *Configuration) (*Processor, error) {
p := &Processor{
Config: config,
Modfile: modFile,
- Result: []Result{},
}
p.SetBlockedModules()
@@ -296,30 +306,32 @@ func NewProcessor(config *Configuration) (*Processor, error) {
// ProcessFiles takes a string slice with file names (full paths)
// and lints them.
-func (p *Processor) ProcessFiles(filenames []string) []Result {
+func (p *Processor) ProcessFiles(filenames []string) (issues []Issue) {
for _, filename := range filenames {
data, err := ioutil.ReadFile(filename)
if err != nil {
- p.Result = append(p.Result, Result{
+ issues = append(issues, Issue{
FileName: filename,
LineNumber: 0,
Reason: fmt.Sprintf("unable to read file, file cannot be linted (%s)", err.Error()),
})
+
+ continue
}
- p.process(filename, data)
+ issues = append(issues, p.process(filename, data)...)
}
- return p.Result
+ return issues
}
// process file imports and add lint error if blocked package is imported.
-func (p *Processor) process(filename string, data []byte) {
+func (p *Processor) process(filename string, data []byte) (issues []Issue) {
fileSet := token.NewFileSet()
file, err := parser.ParseFile(fileSet, filename, data, parser.ParseComments)
if err != nil {
- p.Result = append(p.Result, Result{
+ issues = append(issues, Issue{
FileName: filename,
LineNumber: 0,
Reason: fmt.Sprintf("invalid syntax, file cannot be linted (%s)", err.Error()),
@@ -338,22 +350,24 @@ func (p *Processor) process(filename string, data []byte) {
}
for _, blockReason := range blockReasons {
- p.addError(fileSet, imports[n].Pos(), blockReason)
+ issues = append(issues, p.addError(fileSet, imports[n].Pos(), blockReason))
}
}
+
+ return issues
}
// addError adds an error for the file and line number for the current token.Pos
// with the given reason.
-func (p *Processor) addError(fileset *token.FileSet, pos token.Pos, reason string) {
+func (p *Processor) addError(fileset *token.FileSet, pos token.Pos, reason string) Issue {
position := fileset.Position(pos)
- p.Result = append(p.Result, Result{
+ return Issue{
FileName: position.Filename,
LineNumber: position.Line,
Position: position,
Reason: reason,
- })
+ }
}
// SetBlockedModules determines and sets which modules are blocked by reading
@@ -361,7 +375,7 @@ func (p *Processor) addError(fileset *token.FileSet, pos token.Pos, reason strin
//
// It works by iterating over the dependant modules specified in the require
// directive, checking if the module domain or full name is in the allowed list.
-func (p *Processor) SetBlockedModules() { //nolint:gocognit
+func (p *Processor) SetBlockedModules() { //nolint:gocognit,funlen
blockedModules := make(map[string][]string, len(p.Modfile.Require))
currentModuleName := p.Modfile.Module.Mod.Path
lintedModules := p.Modfile.Require
@@ -397,11 +411,13 @@ func (p *Processor) SetBlockedModules() { //nolint:gocognit
}
if blockModuleReason != nil && !blockModuleReason.IsCurrentModuleARecommendation(currentModuleName) {
- blockedModules[lintedModuleName] = append(blockedModules[lintedModuleName], fmt.Sprintf("%s %s", blockReasonInBlockedList, blockModuleReason.Message()))
+ blockedModules[lintedModuleName] = append(blockedModules[lintedModuleName],
+ fmt.Sprintf("%s %s", blockReasonInBlockedList, blockModuleReason.Message()))
}
if blockVersionReason != nil && blockVersionReason.IsLintedModuleVersionBlocked(lintedModuleVersion) {
- blockedModules[lintedModuleName] = append(blockedModules[lintedModuleName], fmt.Sprintf("%s %s", blockReasonInBlockedList, blockVersionReason.Message(lintedModuleVersion)))
+ blockedModules[lintedModuleName] = append(blockedModules[lintedModuleName],
+ fmt.Sprintf("%s %s", blockReasonInBlockedList, blockVersionReason.Message(lintedModuleVersion)))
}
}
@@ -415,7 +431,8 @@ func (p *Processor) SetBlockedModules() { //nolint:gocognit
replacedModuleNewVersion := strings.TrimSpace(replacedModules[i].New.Version)
if replacedModuleNewName != "" && replacedModuleNewVersion == "" {
- blockedModules[replacedModuleOldName] = append(blockedModules[replacedModuleOldName], blockReasonHasLocalReplaceDirective)
+ blockedModules[replacedModuleOldName] = append(blockedModules[replacedModuleOldName],
+ blockReasonHasLocalReplaceDirective)
}
}
}
@@ -427,6 +444,13 @@ func (p *Processor) SetBlockedModules() { //nolint:gocognit
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
+ }
+
formattedReasons := make([]string, 0, len(blockReasons))
for _, blockReason := range blockReasons {
@@ -463,9 +487,13 @@ func loadGoModFile() ([]byte, error) {
return ioutil.ReadFile(goModFilename)
}
- if _, err := os.Stat(goEnv["GOMOD"]); os.IsNotExist(err) {
+ if _, err = os.Stat(goEnv["GOMOD"]); os.IsNotExist(err) {
return ioutil.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"])
}