From 5fc5366972c874b919f93165bb4ed4e2bcb7c350 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:40:11 +0000 Subject: mod: bump github.com/golangci/golangci-lint from 1.55.2 to 1.56.2 Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.55.2 to 1.56.2. - [Release notes](https://github.com/golangci/golangci-lint/releases) - [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md) - [Commits](https://github.com/golangci/golangci-lint/compare/v1.55.2...v1.56.2) --- updated-dependencies: - dependency-name: github.com/golangci/golangci-lint dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../github.com/OpenPeeDeeP/depguard/v2/.gitignore | 1 + .../github.com/OpenPeeDeeP/depguard/v2/README.md | 25 ++++++++-- .../github.com/OpenPeeDeeP/depguard/v2/settings.go | 53 ++++++++++++++++++---- 3 files changed, 65 insertions(+), 14 deletions(-) (limited to 'vendor/github.com/OpenPeeDeeP/depguard') diff --git a/vendor/github.com/OpenPeeDeeP/depguard/v2/.gitignore b/vendor/github.com/OpenPeeDeeP/depguard/v2/.gitignore index 97cca67c6..e189bdb22 100644 --- a/vendor/github.com/OpenPeeDeeP/depguard/v2/.gitignore +++ b/vendor/github.com/OpenPeeDeeP/depguard/v2/.gitignore @@ -12,3 +12,4 @@ *.out .idea +.null-ls*.go diff --git a/vendor/github.com/OpenPeeDeeP/depguard/v2/README.md b/vendor/github.com/OpenPeeDeeP/depguard/v2/README.md index 3de3f6317..2ccfa22c5 100644 --- a/vendor/github.com/OpenPeeDeeP/depguard/v2/README.md +++ b/vendor/github.com/OpenPeeDeeP/depguard/v2/README.md @@ -7,13 +7,12 @@ allow specific packages within a repository. ## Install ```bash -go get github.com/OpenPeeDeeP/depguard/v2 +go install github.com/OpenPeeDeeP/depguard@latest ``` ## Config -The Depguard binary looks for a file named `^\.?depguard\.(yaml|yml|json|toml)$` in the current -current working directory. Examples include (`.depguard.yml` or `depguard.toml`). +The Depguard binary looks for a file named `^\.?depguard\.(yaml|yml|json|toml)$` in the current working directory. Examples include (`.depguard.yml` or `depguard.toml`). The following is an example configuration file. @@ -24,6 +23,7 @@ The following is an example configuration file. "$all", "!$test" ], + "listMode": "Strict", "allow": [ "$gostd", "github.com/OpenPeeDeeP" @@ -36,6 +36,7 @@ The following is an example configuration file. "files": [ "$test" ], + "listMode": "Lax", "deny": { "github.com/stretchr/testify": "Please use standard library for tests" } @@ -48,6 +49,7 @@ the linter's output. - `files` - list of file globs that will match this list of settings to compare against - `allow` - list of allowed packages - `deny` - map of packages that are not allowed where the value is a suggestion += `listMode` - the mode to use for package matching Files are matched using [Globs](https://github.com/gobwas/glob). If the files list is empty, then all files will match that list. Prefixing a file @@ -67,6 +69,21 @@ A Prefix List just means that a package will match a value, if the value is a prefix of the package. Example `github.com/OpenPeeDeeP/depguard` package will match a value of `github.com/OpenPeeDeeP` but won't match `github.com/OpenPeeDeeP/depguard/v2`. +ListMode is used to determine the package matching priority. There are three +different modes; Original, Strict, and Lax. + +Original is the original way that the package was written to use. It is not recommended +to stay with this and is only here for backwards compatibility. + +Strict, at its roots, is everything is denied unless in allowed. + +Lax, at its roots, is everything is allowed unless it is denied. + +There are cases where a package can be matched in both the allow and denied lists. +You may allow a subpackage but deny the root or vice versa. The `settings_tests.go` file +has many scenarios listed out under `TestListImportAllowed`. These tests will stay +up to date as features are added. + ### Variables There are variable replacements for each type of list (file or package). This is @@ -74,7 +91,7 @@ to reduce repetition and tedious behaviors. #### File Variables -> you can still use and exclamation mark `!` in front of a variable to say not to +> you can still use an exclamation mark `!` in front of a variable to say not to use it. Example `!$test` will match any file that is not a go test file. - `$all` - matches all go files diff --git a/vendor/github.com/OpenPeeDeeP/depguard/v2/settings.go b/vendor/github.com/OpenPeeDeeP/depguard/v2/settings.go index 440f32985..311cacc88 100644 --- a/vendor/github.com/OpenPeeDeeP/depguard/v2/settings.go +++ b/vendor/github.com/OpenPeeDeeP/depguard/v2/settings.go @@ -11,12 +11,22 @@ import ( ) type List struct { - Files []string `json:"files" yaml:"files" toml:"files" mapstructure:"files"` - Allow []string `json:"allow" yaml:"allow" toml:"allow" mapstructure:"allow"` - Deny map[string]string `json:"deny" yaml:"deny" toml:"deny" mapstructure:"deny"` + ListMode string `json:"listMode" yaml:"listMode" toml:"listMode" mapstructure:"listMode"` + Files []string `json:"files" yaml:"files" toml:"files" mapstructure:"files"` + Allow []string `json:"allow" yaml:"allow" toml:"allow" mapstructure:"allow"` + Deny map[string]string `json:"deny" yaml:"deny" toml:"deny" mapstructure:"deny"` } +type listMode int + +const ( + listModeOriginal listMode = iota + listModeStrict + listModeLax +) + type list struct { + listMode listMode name string files []glob.Glob negFiles []glob.Glob @@ -33,6 +43,20 @@ func (l *List) compile() (*list, error) { var errs utils.MultiError var err error + // Determine List Mode + switch strings.ToLower(l.ListMode) { + case "": + li.listMode = listModeOriginal + case "original": + li.listMode = listModeOriginal + case "strict": + li.listMode = listModeStrict + case "lax": + li.listMode = listModeLax + default: + errs = append(errs, fmt.Errorf("%s is not a known list mode", l.ListMode)) + } + // Compile Files for _, f := range l.Files { var negate bool @@ -113,16 +137,25 @@ func (l *list) fileMatch(fileName string) bool { } func (l *list) importAllowed(imp string) (bool, string) { - inAllowed := len(l.allow) == 0 - if !inAllowed { - inAllowed, _ = strInPrefixList(imp, l.allow) + inAllowed, aIdx := strInPrefixList(imp, l.allow) + inDenied, dIdx := strInPrefixList(imp, l.deny) + var allowed bool + switch l.listMode { + case listModeOriginal: + inAllowed = len(l.allow) == 0 || inAllowed + allowed = inAllowed && !inDenied + case listModeStrict: + allowed = inAllowed && (!inDenied || len(l.allow[aIdx]) > len(l.deny[dIdx])) + case listModeLax: + allowed = !inDenied || (inAllowed && len(l.allow[aIdx]) > len(l.deny[dIdx])) + default: + allowed = false } - inDenied, suggIdx := strInPrefixList(imp, l.deny) sugg := "" - if inDenied && suggIdx != -1 { - sugg = l.suggestions[suggIdx] + if !allowed && inDenied && dIdx != -1 { + sugg = l.suggestions[dIdx] } - return inAllowed && !inDenied, sugg + return allowed, sugg } type LinterSettings map[string]*List -- cgit mrf-deployment