aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mgechev
diff options
context:
space:
mode:
authordependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2024-03-04 17:40:11 +0000
committerTaras Madan <tarasmadan@google.com>2024-03-04 18:34:55 +0000
commit5fc5366972c874b919f93165bb4ed4e2bcb7c350 (patch)
tree287c3361a0dee0c72af80d9a1a66714a06e98a62 /vendor/github.com/mgechev
parent1be5ce38a9059c356eb193a8c34d60d61c9fc31f (diff)
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] <support@github.com>
Diffstat (limited to 'vendor/github.com/mgechev')
-rw-r--r--vendor/github.com/mgechev/revive/config/config.go22
-rw-r--r--vendor/github.com/mgechev/revive/formatter/checkstyle.go4
-rw-r--r--vendor/github.com/mgechev/revive/formatter/default.go6
-rw-r--r--vendor/github.com/mgechev/revive/formatter/doc.go2
-rw-r--r--vendor/github.com/mgechev/revive/formatter/friendly.go46
-rw-r--r--vendor/github.com/mgechev/revive/formatter/ndjson.go7
-rw-r--r--vendor/github.com/mgechev/revive/formatter/plain.go6
-rw-r--r--vendor/github.com/mgechev/revive/formatter/unix.go9
-rw-r--r--vendor/github.com/mgechev/revive/lint/config.go5
-rw-r--r--vendor/github.com/mgechev/revive/lint/doc.go2
-rw-r--r--vendor/github.com/mgechev/revive/lint/utils.go11
-rw-r--r--vendor/github.com/mgechev/revive/rule/add-constant.go63
-rw-r--r--vendor/github.com/mgechev/revive/rule/comment-spacings.go4
-rw-r--r--vendor/github.com/mgechev/revive/rule/confusing-naming.go3
-rw-r--r--vendor/github.com/mgechev/revive/rule/constant-logical-expr.go8
-rw-r--r--vendor/github.com/mgechev/revive/rule/context-as-argument.go2
-rw-r--r--vendor/github.com/mgechev/revive/rule/datarace.go4
-rw-r--r--vendor/github.com/mgechev/revive/rule/defer.go4
-rw-r--r--vendor/github.com/mgechev/revive/rule/doc.go2
-rw-r--r--vendor/github.com/mgechev/revive/rule/dot-imports.go65
-rw-r--r--vendor/github.com/mgechev/revive/rule/early-return.go2
-rw-r--r--vendor/github.com/mgechev/revive/rule/enforce-map-style.go6
-rw-r--r--vendor/github.com/mgechev/revive/rule/enforce-repeated-arg-type-style.go191
-rw-r--r--vendor/github.com/mgechev/revive/rule/enforce-slice-style.go193
-rw-r--r--vendor/github.com/mgechev/revive/rule/flag-param.go2
-rw-r--r--vendor/github.com/mgechev/revive/rule/function-length.go2
-rw-r--r--vendor/github.com/mgechev/revive/rule/import-alias-naming.go79
-rw-r--r--vendor/github.com/mgechev/revive/rule/imports-blocklist.go (renamed from vendor/github.com/mgechev/revive/rule/imports-blacklist.go)36
-rw-r--r--vendor/github.com/mgechev/revive/rule/indent-error-flow.go2
-rw-r--r--vendor/github.com/mgechev/revive/rule/max-control-nesting.go128
-rw-r--r--vendor/github.com/mgechev/revive/rule/modifies-value-receiver.go7
-rw-r--r--vendor/github.com/mgechev/revive/rule/optimize-operands-order.go4
-rw-r--r--vendor/github.com/mgechev/revive/rule/string-format.go6
-rw-r--r--vendor/github.com/mgechev/revive/rule/struct-tag.go2
-rw-r--r--vendor/github.com/mgechev/revive/rule/superfluous-else.go2
-rw-r--r--vendor/github.com/mgechev/revive/rule/unconditional-recursion.go32
-rw-r--r--vendor/github.com/mgechev/revive/rule/unhandled-error.go2
-rw-r--r--vendor/github.com/mgechev/revive/rule/unused-param.go78
-rw-r--r--vendor/github.com/mgechev/revive/rule/unused-receiver.go4
-rw-r--r--vendor/github.com/mgechev/revive/rule/utils.go12
-rw-r--r--vendor/github.com/mgechev/revive/rule/var-naming.go73
41 files changed, 915 insertions, 223 deletions
diff --git a/vendor/github.com/mgechev/revive/config/config.go b/vendor/github.com/mgechev/revive/config/config.go
index abd554a9f..50a2b8966 100644
--- a/vendor/github.com/mgechev/revive/config/config.go
+++ b/vendor/github.com/mgechev/revive/config/config.go
@@ -1,3 +1,4 @@
+// Package config implements revive's configuration data structures and related methods
package config
import (
@@ -5,9 +6,9 @@ import (
"fmt"
"os"
- "github.com/mgechev/revive/formatter"
-
"github.com/BurntSushi/toml"
+
+ "github.com/mgechev/revive/formatter"
"github.com/mgechev/revive/lint"
"github.com/mgechev/revive/rule"
)
@@ -54,7 +55,7 @@ var allRules = append([]lint.Rule{
&rule.ModifiesValRecRule{},
&rule.ConstantLogicalExprRule{},
&rule.BoolLiteralRule{},
- &rule.ImportsBlacklistRule{},
+ &rule.ImportsBlocklistRule{},
&rule.FunctionResultsLimitRule{},
&rule.MaxPublicStructsRule{},
&rule.RangeValInClosureRule{},
@@ -91,6 +92,9 @@ var allRules = append([]lint.Rule{
&rule.RedundantImportAlias{},
&rule.ImportAliasNamingRule{},
&rule.EnforceMapStyleRule{},
+ &rule.EnforceRepeatedArgTypeStyleRule{},
+ &rule.EnforceSliceStyleRule{},
+ &rule.MaxControlNestingRule{},
}, defaultRules...)
var allFormatters = []lint.Formatter{
@@ -128,7 +132,8 @@ func GetLintingRules(config *lint.Config, extraRules []lint.Rule) ([]lint.Rule,
var lintingRules []lint.Rule
for name, ruleConfig := range config.Rules {
- r, ok := rulesMap[name]
+ actualName := actualRuleName(name)
+ r, ok := rulesMap[actualName]
if !ok {
return nil, fmt.Errorf("cannot find rule: %s", name)
}
@@ -143,6 +148,15 @@ func GetLintingRules(config *lint.Config, extraRules []lint.Rule) ([]lint.Rule,
return lintingRules, nil
}
+func actualRuleName(name string) string {
+ switch name {
+ case "imports-blacklist":
+ return "imports-blocklist"
+ default:
+ return name
+ }
+}
+
func parseConfig(path string, config *lint.Config) error {
file, err := os.ReadFile(path)
if err != nil {
diff --git a/vendor/github.com/mgechev/revive/formatter/checkstyle.go b/vendor/github.com/mgechev/revive/formatter/checkstyle.go
index 33a3b2ca1..f45b63c92 100644
--- a/vendor/github.com/mgechev/revive/formatter/checkstyle.go
+++ b/vendor/github.com/mgechev/revive/formatter/checkstyle.go
@@ -3,7 +3,7 @@ package formatter
import (
"bytes"
"encoding/xml"
- plainTemplate "text/template"
+ plain "text/template"
"github.com/mgechev/revive/lint"
)
@@ -50,7 +50,7 @@ func (*Checkstyle) Format(failures <-chan lint.Failure, config lint.Config) (str
issues[fn] = append(issues[fn], iss)
}
- t, err := plainTemplate.New("revive").Parse(checkstyleTemplate)
+ t, err := plain.New("revive").Parse(checkstyleTemplate)
if err != nil {
return "", err
}
diff --git a/vendor/github.com/mgechev/revive/formatter/default.go b/vendor/github.com/mgechev/revive/formatter/default.go
index f76a7b29a..2d5a04434 100644
--- a/vendor/github.com/mgechev/revive/formatter/default.go
+++ b/vendor/github.com/mgechev/revive/formatter/default.go
@@ -1,6 +1,7 @@
package formatter
import (
+ "bytes"
"fmt"
"github.com/mgechev/revive/lint"
@@ -19,8 +20,9 @@ func (*Default) Name() string {
// Format formats the failures gotten from the lint.
func (*Default) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
+ var buf bytes.Buffer
for failure := range failures {
- fmt.Printf("%v: %s\n", failure.Position.Start, failure.Failure)
+ fmt.Fprintf(&buf, "%v: %s\n", failure.Position.Start, failure.Failure)
}
- return "", nil
+ return buf.String(), nil
}
diff --git a/vendor/github.com/mgechev/revive/formatter/doc.go b/vendor/github.com/mgechev/revive/formatter/doc.go
new file mode 100644
index 000000000..bb89f20ea
--- /dev/null
+++ b/vendor/github.com/mgechev/revive/formatter/doc.go
@@ -0,0 +1,2 @@
+// Package formatter implements the linter output formatters.
+package formatter
diff --git a/vendor/github.com/mgechev/revive/formatter/friendly.go b/vendor/github.com/mgechev/revive/formatter/friendly.go
index ced8fa46c..5ff329a23 100644
--- a/vendor/github.com/mgechev/revive/formatter/friendly.go
+++ b/vendor/github.com/mgechev/revive/formatter/friendly.go
@@ -3,6 +3,7 @@ package formatter
import (
"bytes"
"fmt"
+ "io"
"sort"
"github.com/fatih/color"
@@ -31,13 +32,14 @@ func (*Friendly) Name() string {
// Format formats the failures gotten from the lint.
func (f *Friendly) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
+ var buf bytes.Buffer
errorMap := map[string]int{}
warningMap := map[string]int{}
totalErrors := 0
totalWarnings := 0
for failure := range failures {
sev := severity(config, failure)
- f.printFriendlyFailure(failure, sev)
+ f.printFriendlyFailure(&buf, failure, sev)
if sev == lint.SeverityWarning {
warningMap[failure.RuleName]++
totalWarnings++
@@ -47,29 +49,29 @@ func (f *Friendly) Format(failures <-chan lint.Failure, config lint.Config) (str
totalErrors++
}
}
- f.printSummary(totalErrors, totalWarnings)
- f.printStatistics(color.RedString("Errors:"), errorMap)
- f.printStatistics(color.YellowString("Warnings:"), warningMap)
- return "", nil
+ f.printSummary(&buf, totalErrors, totalWarnings)
+ f.printStatistics(&buf, color.RedString("Errors:"), errorMap)
+ f.printStatistics(&buf, color.YellowString("Warnings:"), warningMap)
+ return buf.String(), nil
}
-func (f *Friendly) printFriendlyFailure(failure lint.Failure, severity lint.Severity) {
- f.printHeaderRow(failure, severity)
- f.printFilePosition(failure)
- fmt.Println()
- fmt.Println()
+func (f *Friendly) printFriendlyFailure(w io.Writer, failure lint.Failure, severity lint.Severity) {
+ f.printHeaderRow(w, failure, severity)
+ f.printFilePosition(w, failure)
+ fmt.Fprintln(w)
+ fmt.Fprintln(w)
}
-func (f *Friendly) printHeaderRow(failure lint.Failure, severity lint.Severity) {
+func (f *Friendly) printHeaderRow(w io.Writer, failure lint.Failure, severity lint.Severity) {
emoji := getWarningEmoji()
if severity == lint.SeverityError {
emoji = getErrorEmoji()
}
- fmt.Print(f.table([][]string{{emoji, "https://revive.run/r#" + failure.RuleName, color.GreenString(failure.Failure)}}))
+ fmt.Fprint(w, f.table([][]string{{emoji, "https://revive.run/r#" + failure.RuleName, color.GreenString(failure.Failure)}}))
}
-func (*Friendly) printFilePosition(failure lint.Failure) {
- fmt.Printf(" %s:%d:%d", failure.GetFilename(), failure.Position.Start.Line, failure.Position.Start.Column)
+func (*Friendly) printFilePosition(w io.Writer, failure lint.Failure) {
+ fmt.Fprintf(w, " %s:%d:%d", failure.GetFilename(), failure.Position.Start.Line, failure.Position.Start.Column)
}
type statEntry struct {
@@ -77,7 +79,7 @@ type statEntry struct {
failures int
}
-func (*Friendly) printSummary(errors, warnings int) {
+func (*Friendly) printSummary(w io.Writer, errors, warnings int) {
emoji := getWarningEmoji()
if errors > 0 {
emoji = getErrorEmoji()
@@ -96,18 +98,18 @@ func (*Friendly) printSummary(errors, warnings int) {
}
str := fmt.Sprintf("%d %s (%d %s, %d %s)", errors+warnings, problemsLabel, errors, errorsLabel, warnings, warningsLabel)
if errors > 0 {
- fmt.Printf("%s %s\n", emoji, color.RedString(str))
- fmt.Println()
+ fmt.Fprintf(w, "%s %s\n", emoji, color.RedString(str))
+ fmt.Fprintln(w)
return
}
if warnings > 0 {
- fmt.Printf("%s %s\n", emoji, color.YellowString(str))
- fmt.Println()
+ fmt.Fprintf(w, "%s %s\n", emoji, color.YellowString(str))
+ fmt.Fprintln(w)
return
}
}
-func (f *Friendly) printStatistics(header string, stats map[string]int) {
+func (f *Friendly) printStatistics(w io.Writer, header string, stats map[string]int) {
if len(stats) == 0 {
return
}
@@ -122,8 +124,8 @@ func (f *Friendly) printStatistics(header string, stats map[string]int) {
for _, entry := range data {
formatted = append(formatted, []string{color.GreenString(fmt.Sprintf("%d", entry.failures)), entry.name})
}
- fmt.Println(header)
- fmt.Println(f.table(formatted))
+ fmt.Fprintln(w, header)
+ fmt.Fprintln(w, f.table(formatted))
}
func (*Friendly) table(rows [][]string) string {
diff --git a/vendor/github.com/mgechev/revive/formatter/ndjson.go b/vendor/github.com/mgechev/revive/formatter/ndjson.go
index a02d9c80f..58b35dc44 100644
--- a/vendor/github.com/mgechev/revive/formatter/ndjson.go
+++ b/vendor/github.com/mgechev/revive/formatter/ndjson.go
@@ -1,8 +1,8 @@
package formatter
import (
+ "bytes"
"encoding/json"
- "os"
"github.com/mgechev/revive/lint"
)
@@ -20,7 +20,8 @@ func (*NDJSON) Name() string {
// Format formats the failures gotten from the lint.
func (*NDJSON) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
- enc := json.NewEncoder(os.Stdout)
+ var buf bytes.Buffer
+ enc := json.NewEncoder(&buf)
for failure := range failures {
obj := jsonObject{}
obj.Severity = severity(config, failure)
@@ -30,5 +31,5 @@ func (*NDJSON) Format(failures <-chan lint.Failure, config lint.Config) (string,
return "", err
}
}
- return "", nil
+ return buf.String(), nil
}
diff --git a/vendor/github.com/mgechev/revive/formatter/plain.go b/vendor/github.com/mgechev/revive/formatter/plain.go
index 6e083bcfd..09ebf6cdc 100644
--- a/vendor/github.com/mgechev/revive/formatter/plain.go
+++ b/vendor/github.com/mgechev/revive/formatter/plain.go
@@ -1,6 +1,7 @@
package formatter
import (
+ "bytes"
"fmt"
"github.com/mgechev/revive/lint"
@@ -19,8 +20,9 @@ func (*Plain) Name() string {
// Format formats the failures gotten from the lint.
func (*Plain) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
+ var buf bytes.Buffer
for failure := range failures {
- fmt.Printf("%v: %s %s\n", failure.Position.Start, failure.Failure, "https://revive.run/r#"+failure.RuleName)
+ fmt.Fprintf(&buf, "%v: %s %s\n", failure.Position.Start, failure.Failure, "https://revive.run/r#"+failure.RuleName)
}
- return "", nil
+ return buf.String(), nil
}
diff --git a/vendor/github.com/mgechev/revive/formatter/unix.go b/vendor/github.com/mgechev/revive/formatter/unix.go
index ef2f1613a..e46f3c275 100644
--- a/vendor/github.com/mgechev/revive/formatter/unix.go
+++ b/vendor/github.com/mgechev/revive/formatter/unix.go
@@ -1,6 +1,7 @@
package formatter
import (
+ "bytes"
"fmt"
"github.com/mgechev/revive/lint"
@@ -8,7 +9,8 @@ import (
// Unix is an implementation of the Formatter interface
// which formats the errors to a simple line based error format
-// main.go:24:9: [errorf] should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...)
+//
+// main.go:24:9: [errorf] should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...)
type Unix struct {
Metadata lint.FormatterMetadata
}
@@ -20,8 +22,9 @@ func (*Unix) Name() string {
// Format formats the failures gotten from the lint.
func (*Unix) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
+ var buf bytes.Buffer
for failure := range failures {
- fmt.Printf("%v: [%s] %s\n", failure.Position.Start, failure.RuleName, failure.Failure)
+ fmt.Fprintf(&buf, "%v: [%s] %s\n", failure.Position.Start, failure.RuleName, failure.Failure)
}
- return "", nil
+ return buf.String(), nil
}
diff --git a/vendor/github.com/mgechev/revive/lint/config.go b/vendor/github.com/mgechev/revive/lint/config.go
index 9b26d5841..7e51a93c2 100644
--- a/vendor/github.com/mgechev/revive/lint/config.go
+++ b/vendor/github.com/mgechev/revive/lint/config.go
@@ -3,6 +3,7 @@ package lint
// Arguments is type used for the arguments of a rule.
type Arguments = []interface{}
+// FileFilters is type used for modeling file filters to apply to rules.
type FileFilters = []*FileFilter
// RuleConfig is type used for the rule configuration.
@@ -32,8 +33,8 @@ func (rc *RuleConfig) Initialize() error {
type RulesConfig = map[string]RuleConfig
// MustExclude - checks if given filename `name` must be excluded
-func (rcfg *RuleConfig) MustExclude(name string) bool {
- for _, exclude := range rcfg.excludeFilters {
+func (rc *RuleConfig) MustExclude(name string) bool {
+ for _, exclude := range rc.excludeFilters {
if exclude.MatchFileName(name) {
return true
}
diff --git a/vendor/github.com/mgechev/revive/lint/doc.go b/vendor/github.com/mgechev/revive/lint/doc.go
new file mode 100644
index 000000000..7048adf4b
--- /dev/null
+++ b/vendor/github.com/mgechev/revive/lint/doc.go
@@ -0,0 +1,2 @@
+// Package lint implements the linting machinery.
+package lint
diff --git a/vendor/github.com/mgechev/revive/lint/utils.go b/vendor/github.com/mgechev/revive/lint/utils.go
index 28657c6df..6ccfb0ef2 100644
--- a/vendor/github.com/mgechev/revive/lint/utils.go
+++ b/vendor/github.com/mgechev/revive/lint/utils.go
@@ -6,7 +6,7 @@ import (
)
// Name returns a different name if it should be different.
-func Name(name string, whitelist, blacklist []string) (should string) {
+func Name(name string, allowlist, blocklist []string) (should string) {
// Fast path for simple cases: "_" and all lowercase.
if name == "_" {
return name
@@ -57,12 +57,12 @@ func Name(name string, whitelist, blacklist []string) (should string) {
// [w,i) is a word.
word := string(runes[w:i])
ignoreInitWarnings := map[string]bool{}
- for _, i := range whitelist {
+ for _, i := range allowlist {
ignoreInitWarnings[i] = true
}
extraInits := map[string]bool{}
- for _, i := range blacklist {
+ for _, i := range blocklist {
extraInits[i] = true
}
@@ -71,6 +71,10 @@ func Name(name string, whitelist, blacklist []string) (should string) {
if w == 0 && unicode.IsLower(runes[w]) {
u = strings.ToLower(u)
}
+ // Keep lowercase s for IDs
+ if u == "IDS" {
+ u = "IDs"
+ }
// All the common initialisms are ASCII,
// so we can replace the bytes exactly.
copy(runes[w:], []rune(u))
@@ -99,6 +103,7 @@ var commonInitialisms = map[string]bool{
"HTTP": true,
"HTTPS": true,
"ID": true,
+ "IDS": true,
"IP": true,
"JSON": true,
"LHS": true,
diff --git a/vendor/github.com/mgechev/revive/rule/add-constant.go b/vendor/github.com/mgechev/revive/rule/add-constant.go
index 36a7003da..86182623a 100644
--- a/vendor/github.com/mgechev/revive/rule/add-constant.go
+++ b/vendor/github.com/mgechev/revive/rule/add-constant.go
@@ -18,13 +18,13 @@ const (
kindSTRING = "STRING"
)
-type whiteList map[string]map[string]bool
+type allowList map[string]map[string]bool
-func newWhiteList() whiteList {
+func newAllowList() allowList {
return map[string]map[string]bool{kindINT: {}, kindFLOAT: {}, kindSTRING: {}}
}
-func (wl whiteList) add(kind, list string) {
+func (wl allowList) add(kind, list string) {
elems := strings.Split(list, ",")
for _, e := range elems {
wl[kind][e] = true
@@ -33,7 +33,7 @@ func (wl whiteList) add(kind, list string) {
// AddConstantRule lints unused params in functions.
type AddConstantRule struct {
- whiteList whiteList
+ allowList allowList
ignoreFunctions []*regexp.Regexp
strLitLimit int
sync.Mutex
@@ -49,12 +49,13 @@ func (r *AddConstantRule) Apply(file *lint.File, arguments lint.Arguments) []lin
failures = append(failures, failure)
}
- w := lintAddConstantRule{
+ w := &lintAddConstantRule{
onFailure: onFailure,
strLits: make(map[string]int),
strLitLimit: r.strLitLimit,
- whiteLst: r.whiteList,
+ allowList: r.allowList,
ignoreFunctions: r.ignoreFunctions,
+ structTags: make(map[*ast.BasicLit]struct{}),
}
ast.Walk(w, file.AST)
@@ -71,11 +72,16 @@ type lintAddConstantRule struct {
onFailure func(lint.Failure)
strLits map[string]int
strLitLimit int
- whiteLst whiteList
+ allowList allowList
ignoreFunctions []*regexp.Regexp
+ structTags map[*ast.BasicLit]struct{}
}
-func (w lintAddConstantRule) Visit(node ast.Node) ast.Visitor {
+func (w *lintAddConstantRule) Visit(node ast.Node) ast.Visitor {
+ if node == nil {
+ return nil
+ }
+
switch n := node.(type) {
case *ast.CallExpr:
w.checkFunc(n)
@@ -83,13 +89,23 @@ func (w lintAddConstantRule) Visit(node ast.Node) ast.Visitor {
case *ast.GenDecl:
return nil // skip declarations
case *ast.BasicLit:
- w.checkLit(n)
+ if !w.isStructTag(n) {
+ w.checkLit(n)
+ }
+ case *ast.StructType:
+ if n.Fields != nil {
+ for _, field := range n.Fields.List {
+ if field.Tag != nil {
+ w.structTags[field.Tag] = struct{}{}
+ }
+ }
+ }
}
return w
}
-func (w lintAddConstantRule) checkFunc(expr *ast.CallExpr) {
+func (w *lintAddConstantRule) checkFunc(expr *ast.CallExpr) {
fName := w.getFuncName(expr)
for _, arg := range expr.Args {
@@ -105,7 +121,7 @@ func (w lintAddConstantRule) checkFunc(expr *ast.CallExpr) {
}
}
-func (w lintAddConstantRule) getFuncName(expr *ast.CallExpr) string {
+func (*lintAddConstantRule) getFuncName(expr *ast.CallExpr) string {
switch f := expr.Fun.(type) {
case *ast.SelectorExpr:
switch prefix := f.X.(type) {
@@ -119,7 +135,7 @@ func (w lintAddConstantRule) getFuncName(expr *ast.CallExpr) string {
return ""
}
-func (w lintAddConstantRule) checkLit(n *ast.BasicLit) {
+func (w *lintAddConstantRule) checkLit(n *ast.BasicLit) {
switch kind := n.Kind.String(); kind {
case kindFLOAT, kindINT:
w.checkNumLit(kind, n)
@@ -128,7 +144,7 @@ func (w lintAddConstantRule) checkLit(n *ast.BasicLit) {
}
}
-func (w lintAddConstantRule) isIgnoredFunc(fName string) bool {
+func (w *lintAddConstantRule) isIgnoredFunc(fName string) bool {
for _, pattern := range w.ignoreFunctions {
if pattern.MatchString(fName) {
return true
@@ -138,8 +154,8 @@ func (w lintAddConstantRule) isIgnoredFunc(fName string) bool {
return false
}
-func (w lintAddConstantRule) checkStrLit(n *ast.BasicLit) {
- if w.whiteLst[kindSTRING][n.Value] {
+func (w *lintAddConstantRule) checkStrLit(n *ast.BasicLit) {
+ if w.allowList[kindSTRING][n.Value] {
return
}
@@ -158,8 +174,8 @@ func (w lintAddConstantRule) checkStrLit(n *ast.BasicLit) {
}
}
-func (w lintAddConstantRule) checkNumLit(kind string, n *ast.BasicLit) {
- if w.whiteLst[kind][n.Value] {
+func (w *lintAddConstantRule) checkNumLit(kind string, n *ast.BasicLit) {
+ if w.allowList[kind][n.Value] {
return
}
@@ -171,15 +187,20 @@ func (w lintAddConstantRule) checkNumLit(kind string, n *ast.BasicLit) {
})
}
+func (w *lintAddConstantRule) isStructTag(n *ast.BasicLit) bool {
+ _, ok := w.structTags[n]
+ return ok
+}
+
func (r *AddConstantRule) configure(arguments lint.Arguments) {
r.Lock()
defer r.Unlock()
- if r.whiteList == nil {
+ if r.allowList == nil {
r.strLitLimit = defaultStrLitLimit
- r.whiteList = newWhiteList()
+ r.allowList = newAllowList()
if len(arguments) > 0 {
- args, ok := arguments[0].(map[string]interface{})
+ args, ok := arguments[0].(map[string]any)
if !ok {
panic(fmt.Sprintf("Invalid argument to the add-constant rule. Expecting a k,v map, got %T", arguments[0]))
}
@@ -202,7 +223,7 @@ func (r *AddConstantRule) configure(arguments lint.Arguments) {
if !ok {
panic(fmt.Sprintf("Invalid argument to the add-constant rule, string expected. Got '%v' (%T)", v, v))
}
- r.whiteList.add(kind, list)
+ r.allowList.add(kind, list)
case "maxLitCount":
sl, ok := v.(string)
if !ok {
diff --git a/vendor/github.com/mgechev/revive/rule/comment-spacings.go b/vendor/github.com/mgechev/revive/rule/comment-spacings.go
index 0d75c55f3..2b8240ca5 100644
--- a/vendor/github.com/mgechev/revive/rule/comment-spacings.go
+++ b/vendor/github.com/mgechev/revive/rule/comment-spacings.go
@@ -8,7 +8,7 @@ import (
"github.com/mgechev/revive/lint"
)
-// CommentSpacings Rule check the whether there is a space between
+// CommentSpacingsRule check the whether there is a space between
// the comment symbol( // ) and the start of the comment text
type CommentSpacingsRule struct {
allowList []string
@@ -36,6 +36,7 @@ func (r *CommentSpacingsRule) configure(arguments lint.Arguments) {
}
}
+// Apply the rule.
func (r *CommentSpacingsRule) Apply(file *lint.File, args lint.Arguments) []lint.Failure {
r.configure(args)
@@ -74,6 +75,7 @@ func (r *CommentSpacingsRule) Apply(file *lint.File, args lint.Arguments) []lint
return failures
}
+// Name yields this rule name.
func (*CommentSpacingsRule) Name() string {
return "comment-spacings"
}
diff --git a/vendor/github.com/mgechev/revive/rule/confusing-naming.go b/vendor/github.com/mgechev/revive/rule/confusing-naming.go
index 8b1c3eac4..febfd8824 100644
--- a/vendor/github.com/mgechev/revive/rule/confusing-naming.go
+++ b/vendor/github.com/mgechev/revive/rule/confusing-naming.go
@@ -71,7 +71,6 @@ func (*ConfusingNamingRule) Name() string {
// checkMethodName checks if a given method/function name is similar (just case differences) to other method/function of the same struct/file.
func checkMethodName(holder string, id *ast.Ident, w *lintConfusingNames) {
-
if id.Name == "init" && holder == defaultStructName {
// ignore init functions
return
@@ -112,7 +111,7 @@ func checkMethodName(holder string, id *ast.Ident, w *lintConfusingNames) {
pkgm.methods[holder] = make(map[string]*referenceMethod, 1)
}
- // update the black list
+ // update the block list
if pkgm.methods[holder] == nil {
println("no entry for '", holder, "'")
}
diff --git a/vendor/github.com/mgechev/revive/rule/constant-logical-expr.go b/vendor/github.com/mgechev/revive/rule/constant-logical-expr.go
index 9abc95d67..36cd641f7 100644
--- a/vendor/github.com/mgechev/revive/rule/constant-logical-expr.go
+++ b/vendor/github.com/mgechev/revive/rule/constant-logical-expr.go
@@ -11,7 +11,7 @@ import (
type ConstantLogicalExprRule struct{}
// Apply applies the rule to given file.
-func (r *ConstantLogicalExprRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
+func (*ConstantLogicalExprRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure
onFailure := func(failure lint.Failure) {
@@ -63,7 +63,7 @@ func (w *lintConstantLogicalExpr) Visit(node ast.Node) ast.Visitor {
return w
}
-func (w *lintConstantLogicalExpr) isOperatorWithLogicalResult(t token.Token) bool {
+func (*lintConstantLogicalExpr) isOperatorWithLogicalResult(t token.Token) bool {
switch t {
case token.LAND, token.LOR, token.EQL, token.LSS, token.GTR, token.NEQ, token.LEQ, token.GEQ:
return true
@@ -72,7 +72,7 @@ func (w *lintConstantLogicalExpr) isOperatorWithLogicalResult(t token.Token) boo
return false
}
-func (w *lintConstantLogicalExpr) isEqualityOperator(t token.Token) bool {
+func (*lintConstantLogicalExpr) isEqualityOperator(t token.Token) bool {
switch t {
case token.EQL, token.LEQ, token.GEQ:
return true
@@ -81,7 +81,7 @@ func (w *lintConstantLogicalExpr) isEqualityOperator(t token.Token) bool {
return false
}
-func (w *lintConstantLogicalExpr) isInequalityOperator(t token.Token) bool {
+func (*lintConstantLogicalExpr) isInequalityOperator(t token.Token) bool {
switch t {
case token.LSS, token.GTR, token.NEQ:
return true
diff --git a/vendor/github.com/mgechev/revive/rule/context-as-argument.go b/vendor/github.com/mgechev/revive/rule/context-as-argument.go
index 3c400065e..e0c8cfa5e 100644
--- a/vendor/github.com/mgechev/revive/rule/context-as-argument.go
+++ b/vendor/github.com/mgechev/revive/rule/context-as-argument.go
@@ -82,7 +82,7 @@ func (w lintContextArguments) Visit(n ast.Node) ast.Visitor {
func getAllowTypesFromArguments(args lint.Arguments) map[string]struct{} {
allowTypesBefore := []string{}
if len(args) >= 1 {
- argKV, ok := args[0].(map[string]interface{})
+ argKV, ok := args[0].(map[string]any)
if !ok {
panic(fmt.Sprintf("Invalid argument to the context-as-argument rule. Expecting a k,v map, got %T", args[0]))
}
diff --git a/vendor/github.com/mgechev/revive/rule/datarace.go b/vendor/github.com/mgechev/revive/rule/datarace.go
index 26fcadcdc..39e96696a 100644
--- a/vendor/github.com/mgechev/revive/rule/datarace.go
+++ b/vendor/github.com/mgechev/revive/rule/datarace.go
@@ -53,7 +53,7 @@ func (w lintDataRaces) Visit(n ast.Node) ast.Visitor {
return nil
}
-func (w lintDataRaces) ExtractReturnIDs(fields []*ast.Field) map[*ast.Object]struct{} {
+func (lintDataRaces) ExtractReturnIDs(fields []*ast.Field) map[*ast.Object]struct{} {
r := map[*ast.Object]struct{}{}
for _, f := range fields {
for _, id := range f.Names {
@@ -111,7 +111,7 @@ func (w lintFunctionForDataRaces) Visit(node ast.Node) ast.Visitor {
return ok
}
- ids := pick(funcLit.Body, selectIDs, nil)
+ ids := pick(funcLit.Body, selectIDs)
for _, id := range ids {
id := id.(*ast.Ident)
_, isRangeID := w.rangeIDs[id.Obj]
diff --git a/vendor/github.com/mgechev/revive/rule/defer.go b/vendor/github.com/mgechev/revive/rule/defer.go
index f3ea17920..adc6478ae 100644
--- a/vendor/github.com/mgechev/revive/rule/defer.go
+++ b/vendor/github.com/mgechev/revive/rule/defer.go
@@ -56,7 +56,7 @@ func (*DeferRule) allowFromArgs(args lint.Arguments) map[string]bool {
return allow
}
- aa, ok := args[0].([]interface{})
+ aa, ok := args[0].([]any)
if !ok {
panic(fmt.Sprintf("Invalid argument '%v' for 'defer' rule. Expecting []string, got %T", args[0], args[0]))
}
@@ -144,8 +144,8 @@ func (w lintDeferRule) Visit(node ast.Node) ast.Visitor {
w.newFailure("be careful when deferring calls to methods without pointer receiver", fn, 0.8, "bad practice", "method-call")
}
}
-
}
+
return nil
}
diff --git a/vendor/github.com/mgechev/revive/rule/doc.go b/vendor/github.com/mgechev/revive/rule/doc.go
new file mode 100644
index 000000000..55bf6caa6
--- /dev/null
+++ b/vendor/github.com/mgechev/revive/rule/doc.go
@@ -0,0 +1,2 @@
+// Package rule implements revive's linting rules.
+package rule
diff --git a/vendor/github.com/mgechev/revive/rule/dot-imports.go b/vendor/github.com/mgechev/revive/rule/dot-imports.go
index db78f1957..6b877677d 100644
--- a/vendor/github.com/mgechev/revive/rule/dot-imports.go
+++ b/vendor/github.com/mgechev/revive/rule/dot-imports.go
@@ -1,16 +1,23 @@
package rule
import (
+ "fmt"
"go/ast"
+ "sync"
"github.com/mgechev/revive/lint"
)
// DotImportsRule lints given else constructs.
-type DotImportsRule struct{}
+type DotImportsRule struct {
+ sync.Mutex
+ allowedPackages allowPackages
+}
// Apply applies the rule to given file.
-func (*DotImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
+func (r *DotImportsRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
+ r.configure(arguments)
+
var failures []lint.Failure
fileAst := file.AST
@@ -20,6 +27,7 @@ func (*DotImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
onFailure: func(failure lint.Failure) {
failures = append(failures, failure)
},
+ allowPackages: r.allowedPackages,
}
ast.Walk(walker, fileAst)
@@ -32,15 +40,49 @@ func (*DotImportsRule) Name() string {
return "dot-imports"
}
+func (r *DotImportsRule) configure(arguments lint.Arguments) {
+ r.Lock()
+ defer r.Unlock()
+
+ if r.allowedPackages != nil {
+ return
+ }
+
+ r.allowedPackages = make(allowPackages)
+ if len(arguments) == 0 {
+ return
+ }
+
+ args, ok := arguments[0].(map[string]any)
+ if !ok {
+ panic(fmt.Sprintf("Invalid argument to the dot-imports rule. Expecting a k,v map, got %T", arguments[0]))
+ }
+
+ if allowedPkgArg, ok := args["allowedPackages"]; ok {
+ if pkgs, ok := allowedPkgArg.([]any); ok {
+ for _, p := range pkgs {
+ if pkg, ok := p.(string); ok {
+ r.allowedPackages.add(pkg)
+ } else {
+ panic(fmt.Sprintf("Invalid argument to the dot-imports rule, string expected. Got '%v' (%T)", p, p))
+ }
+ }
+ } else {
+ panic(fmt.Sprintf("Invalid argument to the dot-imports rule, []string expected. Got '%v' (%T)", allowedPkgArg, allowedPkgArg))
+ }
+ }
+}
+
type lintImports struct {
- file *lint.File
- fileAst *ast.File
- onFailure func(lint.Failure)
+ file *lint.File
+ fileAst *ast.File
+ onFailure func(lint.Failure)
+ allowPackages allowPackages
}
func (w lintImports) Visit(_ ast.Node) ast.Visitor {
for _, is := range w.fileAst.Imports {
- if is.Name != nil && is.Name.Name == "." {
+ if is.Name != nil && is.Name.Name == "." && !w.allowPackages.isAllowedPackage(is.Path.Value) {
w.onFailure(lint.Failure{
Confidence: 1,
Failure: "should not use dot imports",
@@ -51,3 +93,14 @@ func (w lintImports) Visit(_ ast.Node) ast.Visitor {
}
return nil
}
+
+type allowPackages map[string]struct{}
+
+func (ap allowPackages) add(pkg string) {
+ ap[fmt.Sprintf(`"%s"`, pkg)] = struct{}{} // import path strings are with double quotes
+}
+
+func (ap allowPackages) isAllowedPackage(pkg string) bool {
+ _, allowed := ap[pkg]
+ return allowed
+}
diff --git a/vendor/github.com/mgechev/revive/rule/early-return.go b/vendor/github.com/mgechev/revive/rule/early-return.go
index 90a0acc55..9c04a1dbe 100644
--- a/vendor/github.com/mgechev/revive/rule/early-return.go
+++ b/vendor/github.com/mgechev/revive/rule/early-return.go
@@ -22,7 +22,7 @@ func (*EarlyReturnRule) Name() string {
}
// CheckIfElse evaluates the rule against an ifelse.Chain.
-func (e *EarlyReturnRule) CheckIfElse(chain ifelse.Chain, args ifelse.Args) (failMsg string) {
+func (*EarlyReturnRule) CheckIfElse(chain ifelse.Chain, args ifelse.Args) (failMsg string) {
if !chain.Else.Deviates() {
// this rule only applies if the else-block deviates control flow
return
diff --git a/vendor/github.com/mgechev/revive/rule/enforce-map-style.go b/vendor/github.com/mgechev/revive/rule/enforce-map-style.go
index ae27b654f..36ac2374c 100644
--- a/vendor/github.com/mgechev/revive/rule/enforce-map-style.go
+++ b/vendor/github.com/mgechev/revive/rule/enforce-map-style.go
@@ -47,7 +47,7 @@ type EnforceMapStyleRule struct {
func (r *EnforceMapStyleRule) configure(arguments lint.Arguments) {
r.Lock()
defer r.Unlock()
-
+
if r.configured {
return
}
@@ -58,7 +58,7 @@ func (r *EnforceMapStyleRule) configure(arguments lint.Arguments) {
return
}
- enforceMapStyle, ok := arguments[0].(string)
+ enforceMapStyle, ok := arguments[0].(string)
if !ok {
panic(fmt.Sprintf("Invalid argument '%v' for 'enforce-map-style' rule. Expecting string, got %T", arguments[0], arguments[0]))
}
@@ -141,7 +141,7 @@ func (r *EnforceMapStyleRule) Apply(file *lint.File, arguments lint.Arguments) [
}
// Name returns the rule name.
-func (r *EnforceMapStyleRule) Name() string {
+func (*EnforceMapStyleRule) Name() string {
return "enforce-map-style"
}
diff --git a/vendor/github.com/mgechev/revive/rule/enforce-repeated-arg-type-style.go b/vendor/github.com/mgechev/revive/rule/enforce-repeated-arg-type-style.go
new file mode 100644
index 000000000..067082b1b
--- /dev/null
+++ b/vendor/github.com/mgechev/revive/rule/enforce-repeated-arg-type-style.go
@@ -0,0 +1,191 @@
+package rule
+
+import (
+ "fmt"
+ "go/ast"
+ "go/types"
+ "sync"
+
+ "github.com/mgechev/revive/lint"
+)
+
+type enforceRepeatedArgTypeStyleType string
+
+const (
+ enforceRepeatedArgTypeStyleTypeAny enforceRepeatedArgTypeStyleType = "any"
+ enforceRepeatedArgTypeStyleTypeShort enforceRepeatedArgTypeStyleType = "short"
+ enforceRepeatedArgTypeStyleTypeFull enforceRepeatedArgTypeStyleType = "full"
+)
+
+func repeatedArgTypeStyleFromString(s string) enforceRepeatedArgTypeStyleType {
+ switch s {
+ case string(enforceRepeatedArgTypeStyleTypeAny), "":
+ return enforceRepeatedArgTypeStyleTypeAny
+ case string(enforceRepeatedArgTypeStyleTypeShort):
+ return enforceRepeatedArgTypeStyleTypeShort
+ case string(enforceRepeatedArgTypeStyleTypeFull):
+ return enforceRepeatedArgTypeStyleTypeFull
+ default:
+ err := fmt.Errorf(
+ "invalid repeated arg type style: %s (expecting one of %v)",
+ s,
+ []enforceRepeatedArgTypeStyleType{
+ enforceRepeatedArgTypeStyleTypeAny,
+ enforceRepeatedArgTypeStyleTypeShort,
+ enforceRepeatedArgTypeStyleTypeFull,
+ },
+ )
+
+ panic(fmt.Sprintf("Invalid argument to the enforce-repeated-arg-type-style rule: %v", err))
+ }
+}
+
+// EnforceRepeatedArgTypeStyleRule implements a rule to enforce repeated argument type style.
+type EnforceRepeatedArgTypeStyleRule struct {
+ configured bool
+ funcArgStyle enforceRepeatedArgTypeStyleType
+ funcRetValStyle enforceRepeatedArgTypeStyleType
+
+ sync.Mutex
+}
+
+func (r *EnforceRepeatedArgTypeStyleRule) configure(arguments lint.Arguments) {
+ r.Lock()
+ defer r.Unlock()
+
+ if r.configured {
+ return
+ }
+ r.configured = true
+
+ r.funcArgStyle = enforceRepeatedArgTypeStyleTypeAny
+ r.funcRetValStyle = enforceRepeatedArgTypeStyleTypeAny
+
+ if len(arguments) == 0 {
+ return
+ }
+
+ switch funcArgStyle := arguments[0].(type) {
+ case string:
+ r.funcArgStyle = repeatedArgTypeStyleFromString(funcArgStyle)
+ r.funcRetValStyle = repeatedArgTypeStyleFromString(funcArgStyle)
+ case map[string]any: // expecting map[string]string
+ for k, v := range funcArgStyle {
+ switch k {
+ case "funcArgStyle":
+ val, ok := v.(string)
+ if !ok {
+ panic(fmt.Sprintf("Invalid map value type for 'enforce-repeated-arg-type-style' rule. Expecting string, got %T", v))
+ }
+ r.funcArgStyle = repeatedArgTypeStyleFromString(val)
+ case "funcRetValStyle":
+ val, ok := v.(string)
+ if !ok {
+ panic(fmt.Sprintf("Invalid map value '%v' for 'enforce-repeated-arg-type-style' rule. Expecting string, got %T", v, v))
+ }
+ r.funcRetValStyle = repeatedArgTypeStyleFromString(val)
+ default:
+ panic(fmt.Sprintf("Invalid map key for 'enforce-repeated-arg-type-style' rule. Expecting 'funcArgStyle' or 'funcRetValStyle', got %v", k))
+ }
+ }
+ default:
+ panic(fmt.Sprintf("Invalid argument '%v' for 'import-alias-naming' rule. Expecting string or map[string]string, got %T", arguments[0], arguments[0]))
+ }
+}
+
+// Apply applies the rule to a given file.
+func (r *EnforceRepeatedArgTypeStyleRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
+ r.configure(arguments)
+
+ if r.funcArgStyle == enforceRepeatedArgTypeStyleTypeAny && r.funcRetValStyle == enforceRepeatedArgTypeStyleTypeAny {
+ // This linter is not configured, return no failures.
+ return nil
+ }
+
+ var failures []lint.Failure
+
+ err := file.Pkg.TypeCheck()
+ if err != nil {
+ // the file has other issues
+ return nil
+ }
+ typesInfo := file.Pkg.TypesInfo()
+
+ astFile := file.AST
+ ast.Inspect(astFile, func(n ast.Node) bool {
+ switch fn := n.(type) {
+ case *ast.FuncDecl:
+ if r.funcArgStyle == enforceRepeatedArgTypeStyleTypeFull {
+ if fn.Type.Params != nil {
+ for _, field := range fn.Type.Params.List {
+ if len(field.Names) > 1 {
+ failures = append(failures, lint.Failure{
+ Confidence: 1,
+ Node: field,
+ Category: "style",
+ Failure: "argument types should not be omitted",
+ })
+ }
+ }
+ }
+ }
+
+ if r.funcArgStyle == enforceRepeatedArgTypeStyleTypeShort {
+ var prevType ast.Expr
+ if fn.Type.Params != nil {
+ for _, field := range fn.Type.Params.List {
+ if types.Identical(typesInfo.Types[field.Type].Type, typesInfo.Types[prevType].Type) {
+ failures = append(failures, lint.Failure{
+ Confidence: 1,
+ Node: field,
+ Category: "style",
+ Failure: "repeated argument type can be omitted",
+ })
+ }
+ prevType = field.Type
+ }
+ }
+ }
+
+ if r.funcRetValStyle == enforceRepeatedArgTypeStyleTypeFull {
+ if fn.Type.Results != nil {
+ for _, field := range fn.Type.Results.List {
+ if len(field.Names) > 1 {
+ failures = append(failures, lint.Failure{
+ Confidence: 1,
+ Node: field,
+ Category: "style",
+ Failure: "return types should not be omitted",
+ })
+ }
+ }
+ }
+ }
+
+ if r.funcRetValStyle == enforceRepeatedArgTypeStyleTypeShort {
+ var prevType ast.Expr
+ if fn.Type.Results != nil {
+ for _, field := range fn.Type.Results.List {
+ if field.Names != nil && types.Identical(typesInfo.Types[field.Type].Type, typesInfo.Types[prevType].Type) {
+ failures = append(failures, lint.Failure{
+ Confidence: 1,
+ Node: field,
+ Category: "style",
+ Failure: "repeated return type can be omitted",
+ })
+ }
+ prevType = field.Type
+ }
+ }
+ }
+ }
+ return true
+ })
+
+ return failures
+}
+
+// Name returns the name of the linter rule.
+func (*EnforceRepeatedArgTypeStyleRule) Name() string {
+ return "enforce-repeated-arg-type-style"
+}
diff --git a/vendor/github.com/mgechev/revive/rule/enforce-slice-style.go b/vendor/github.com/mgechev/revive/rule/enforce-slice-style.go
new file mode 100644
index 000000000..abaf20be0
--- /dev/null
+++ b/vendor/github.com/mgechev/revive/rule/enforce-slice-style.go
@@ -0,0 +1,193 @@
+package rule
+
+import (
+ "fmt"
+ "go/ast"
+ "sync"
+
+ "github.com/mgechev/revive/lint"
+)
+
+type enforceSliceStyleType string
+
+const (
+ enforceSliceStyleTypeAny enforceSliceStyleType = "any"
+ enforceSliceStyleTypeMake enforceSliceStyleType = "make"
+ enforceSliceStyleTypeLiteral enforceSliceStyleType = "literal"
+)
+
+func sliceStyleFromString(s string) (enforceSliceStyleType, error) {
+ switch s {
+ case string(enforceSliceStyleTypeAny), "":
+ return enforceSliceStyleTypeAny, nil
+ case string(enforceSliceStyleTypeMake):
+ return enforceSliceStyleTypeMake, nil
+ case string(enforceSliceStyleTypeLiteral):
+ return enforceSliceStyleTypeLiteral, nil
+ default:
+ return enforceSliceStyleTypeAny, fmt.Errorf(
+ "invalid slice style: %s (expecting one of %v)",
+ s,
+ []enforceSliceStyleType{
+ enforceSliceStyleTypeAny,
+ enforceSliceStyleTypeMake,
+ enforceSliceStyleTypeLiteral,
+ },
+ )
+ }
+}
+
+// EnforceSliceStyleRule implements a rule to enforce `make([]type)` over `[]type{}`.
+type EnforceSliceStyleRule struct {
+ configured bool
+ enforceSliceStyle enforceSliceStyleType
+ sync.Mutex
+}
+
+func (r *EnforceSliceStyleRule) configure(arguments lint.Arguments) {
+ r.Lock()
+ defer r.Unlock()
+
+ if r.configured {
+ return
+ }
+ r.configured = true
+
+ if len(arguments) < 1 {
+ r.enforceSliceStyle = enforceSliceStyleTypeAny
+ return
+ }
+
+ enforceSliceStyle, ok := arguments[0].(string)
+ if !ok {
+ panic(fmt.Sprintf("Invalid argument '%v' for 'enforce-slice-style' rule. Expecting string, got %T", arguments[0], arguments[0]))
+ }
+
+ var err error
+ r.enforceSliceStyle, err = sliceStyleFromString(enforceSliceStyle)
+
+ if err != nil {
+ panic(fmt.Sprintf("Invalid argument to the enforce-slice-style rule: %v", err))
+ }
+}
+
+// Apply applies the rule to given file.
+func (r *EnforceSliceStyleRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
+ r.configure(arguments)
+
+ if r.enforceSliceStyle == enforceSliceStyleTypeAny {
+ // this linter is not configured
+ return nil
+ }
+
+ var failures []lint.Failure
+
+ astFile := file.AST
+ ast.Inspect(astFile, func(n ast.Node) bool {
+ switch v := n.(type) {
+ case *ast.CompositeLit:
+ if r.enforceSliceStyle != enforceSliceStyleTypeMake {
+ return true
+ }
+
+ if !r.isSliceType(v.Type) {
+ return true
+ }
+
+ if len(v.Elts) > 0 {
+ // not an empty slice
+ return true
+ }
+
+ failures = append(failures, lint.Failure{
+ Confidence: 1,
+ Node: v,
+ Category: "style",
+ Failure: "use make([]type) instead of []type{} (or declare nil slice)",
+ })
+ case *ast.CallExpr:
+ if r.enforceSliceStyle != enforceSliceStyleTypeLiteral {
+ // skip any function calls, even if it's make([]type)
+ // we don't want to report it if literals are not enforced
+ return true
+ }
+
+ ident, ok := v.Fun.(*ast.Ident)
+ if !ok || ident.Name != "make" {
+ return true
+ }
+
+ if len(v.Args) < 2 {
+ // skip invalid make declarations
+ return true
+ }
+
+ if !r.isSliceType(v.Args[0]) {
+ // not a slice type
+ return true
+ }
+
+ arg, ok := v.Args[1].(*ast.BasicLit)
+ if !ok {
+ // skip invalid make declarations
+ return true
+ }
+
+ if arg.Value != "0" {
+ // skip slice with non-zero size
+ return true
+ }
+
+ if len(v.Args) > 2 {
+ arg, ok := v.Args[2].(*ast.BasicLit)
+ if !ok {
+ // skip invalid make declarations
+ return true
+ }
+
+ if arg.Value != "0" {
+ // skip non-zero capacity slice
+ return true
+ }
+ }
+
+ failures = append(failures, lint.Failure{
+ Confidence: 1,
+ Node: v.Args[0],
+ Category: "style",
+ Failure: "use []type{} instead of make([]type, 0) (or declare nil slice)",
+ })
+ }
+ return true
+ })
+
+ return failures
+}
+
+// Name returns the rule name.
+func (*EnforceSliceStyleRule) Name() string {
+ return "enforce-slice-style"
+}
+
+func (r *EnforceSliceStyleRule) isSliceType(v ast.Expr) bool {
+ switch t := v.(type) {
+ case *ast.ArrayType:
+ if t.Len != nil {
+ // array
+ return false
+ }
+ // slice
+ return true
+ case *ast.Ident:
+ if t.Obj == nil {
+ return false
+ }
+ typeSpec, ok := t.Obj.Decl.(*ast.TypeSpec)
+ if !ok {
+ return false
+ }
+ return r.isSliceType(typeSpec.Type)
+ default:
+ return false
+ }
+}
diff --git a/vendor/github.com/mgechev/revive/rule/flag-param.go b/vendor/github.com/mgechev/revive/rule/flag-param.go
index 19a05f9fe..f9bfb712c 100644
--- a/vendor/github.com/mgechev/revive/rule/flag-param.go
+++ b/vendor/github.com/mgechev/revive/rule/flag-param.go
@@ -88,7 +88,7 @@ func (w conditionVisitor) Visit(node ast.Node) ast.Visitor {
return false
}
- uses := pick(ifStmt.Cond, fselect, nil)
+ uses := pick(ifStmt.Cond, fselect)
if len(uses) < 1 {
return w
diff --git a/vendor/github.com/mgechev/revive/rule/function-length.go b/vendor/github.com/mgechev/revive/rule/function-length.go
index f7ab8b98e..fd65884e9 100644
--- a/vendor/github.com/mgechev/revive/rule/function-length.go
+++ b/vendor/github.com/mgechev/revive/rule/function-length.go
@@ -171,7 +171,7 @@ func (w lintFuncLength) countFuncLitStmts(stmt ast.Expr) int {
return 0
}
-func (w lintFuncLength) countBodyListStmts(t interface{}) int {
+func (w lintFuncLength) countBodyListStmts(t any) int {
i := reflect.ValueOf(t).Elem().FieldByName(`Body`).Elem().FieldByName(`List`).Interface()
return w.countStmts(i.([]ast.Stmt))
}
diff --git a/vendor/github.com/mgechev/revive/rule/import-alias-naming.go b/vendor/github.com/mgechev/revive/rule/import-alias-naming.go
index 292392b5d..a6d096c8b 100644
--- a/vendor/github.com/mgechev/revive/rule/import-alias-naming.go
+++ b/vendor/github.com/mgechev/revive/rule/import-alias-naming.go
@@ -10,14 +10,15 @@ import (
// ImportAliasNamingRule lints import alias naming.
type ImportAliasNamingRule struct {
- configured bool
- namingRuleRegexp *regexp.Regexp
+ configured bool
+ allowRegexp *regexp.Regexp
+ denyRegexp *regexp.Regexp
sync.Mutex
}
-const defaultNamingRule = "^[a-z][a-z0-9]{0,}$"
+const defaultImportAliasNamingAllowRule = "^[a-z][a-z0-9]{0,}$"
-var defaultNamingRuleRegexp = regexp.MustCompile(defaultNamingRule)
+var defaultImportAliasNamingAllowRegexp = regexp.MustCompile(defaultImportAliasNamingAllowRule)
func (r *ImportAliasNamingRule) configure(arguments lint.Arguments) {
r.Lock()
@@ -26,20 +27,31 @@ func (r *ImportAliasNamingRule) configure(arguments lint.Arguments) {
return
}
- if len(arguments) < 1 {
- r.namingRuleRegexp = defaultNamingRuleRegexp
+ if len(arguments) == 0 {
+ r.allowRegexp = defaultImportAliasNamingAllowRegexp
return
}
- namingRule, ok := arguments[0].(string) // Alt. non panicking version
- if !ok {
- panic(fmt.Sprintf("Invalid argument '%v' for 'import-alias-naming' rule. Expecting string, got %T", arguments[0], arguments[0]))
+ switch namingRule := arguments[0].(type) {
+ case string:
+ r.setAllowRule(namingRule)
+ case map[string]any: // expecting map[string]string
+ for k, v := range namingRule {
+ switch k {
+ case "allowRegex":
+ r.setAllowRule(v)
+ case "denyRegex":
+ r.setDenyRule(v)
+ default:
+ panic(fmt.Sprintf("Invalid map key for 'import-alias-naming' rule. Expecting 'allowRegex' or 'denyRegex', got %v", k))
+ }
+ }
+ default:
+ panic(fmt.Sprintf("Invalid argument '%v' for 'import-alias-naming' rule. Expecting string or map[string]string, got %T", arguments[0], arguments[0]))
}
- var err error
- r.namingRuleRegexp, err = regexp.Compile(namingRule)
- if err != nil {
- panic(fmt.Sprintf("Invalid argument to the import-alias-naming rule. Expecting %q to be a valid regular expression, got: %v", namingRule, err))
+ if r.allowRegexp == nil && r.denyRegexp == nil {
+ r.allowRegexp = defaultImportAliasNamingAllowRegexp
}
}
@@ -56,14 +68,23 @@ func (r *ImportAliasNamingRule) Apply(file *lint.File, arguments lint.Arguments)
}
alias := is.Name
- if alias == nil || alias.Name == "_" {
+ if alias == nil || alias.Name == "_" || alias.Name == "." { // "_" and "." are special types of import aiases and should be processed by another linter rule
continue
}
- if !r.namingRuleRegexp.MatchString(alias.Name) {
+ if r.allowRegexp != nil && !r.allowRegexp.MatchString(alias.Name) {
+ failures = append(failures, lint.Failure{
+ Confidence: 1,
+ Failure: fmt.Sprintf("import name (%s) must match the regular expression: %s", alias.Name, r.allowRegexp.String()),
+ Node: alias,
+ Category: "imports",
+ })
+ }
+
+ if r.denyRegexp != nil && r.denyRegexp.MatchString(alias.Name) {
failures = append(failures, lint.Failure{
Confidence: 1,
- Failure: fmt.Sprintf("import name (%s) must match the regular expression: %s", alias.Name, r.namingRuleRegexp.String()),
+ Failure: fmt.Sprintf("import name (%s) must NOT match the regular expression: %s", alias.Name, r.denyRegexp.String()),
Node: alias,
Category: "imports",
})
@@ -77,3 +98,29 @@ func (r *ImportAliasNamingRule) Apply(file *lint.File, arguments lint.Arguments)
func (*ImportAliasNamingRule) Name() string {
return "import-alias-naming"
}
+
+func (r *ImportAliasNamingRule) setAllowRule(value any) {
+ namingRule, ok := value.(string)
+ if !ok {
+ panic(fmt.Sprintf("Invalid argument '%v' for import-alias-naming allowRegexp rule. Expecting string, got %T", value, value))
+ }
+
+ namingRuleRegexp, err := regexp.Compile(namingRule)
+ if err != nil {
+ panic(fmt.Sprintf("Invalid argument to the import-alias-naming allowRegexp rule. Expecting %q to be a valid regular expression, got: %v", namingRule, err))
+ }
+ r.allowRegexp = namingRuleRegexp
+}
+
+func (r *ImportAliasNamingRule) setDenyRule(value any) {
+ namingRule, ok := value.(string)
+ if !ok {
+ panic(fmt.Sprintf("Invalid argument '%v' for import-alias-naming denyRegexp rule. Expecting string, got %T", value, value))
+ }
+
+ namingRuleRegexp, err := regexp.Compile(namingRule)
+ if err != nil {
+ panic(fmt.Sprintf("Invalid argument to the import-alias-naming denyRegexp rule. Expecting %q to be a valid regular expression, got: %v", namingRule, err))
+ }
+ r.denyRegexp = namingRuleRegexp
+}
diff --git a/vendor/github.com/mgechev/revive/rule/imports-blacklist.go b/vendor/github.com/mgechev/revive/rule/imports-blocklist.go
index bb8262cae..431066403 100644
--- a/vendor/github.com/mgechev/revive/rule/imports-blacklist.go
+++ b/vendor/github.com/mgechev/revive/rule/imports-blocklist.go
@@ -8,37 +8,37 @@ import (
"github.com/mgechev/revive/lint"
)
-// ImportsBlacklistRule lints given else constructs.
-type ImportsBlacklistRule struct {
- blacklist []*regexp.Regexp
+// ImportsBlocklistRule lints given else constructs.
+type ImportsBlocklistRule struct {
+ blocklist []*regexp.Regexp
sync.Mutex
}
-var replaceRegexp = regexp.MustCompile(`/?\*\*/?`)
+var replaceImportRegexp = regexp.MustCompile(`/?\*\*/?`)
-func (r *ImportsBlacklistRule) configure(arguments lint.Arguments) {
+func (r *ImportsBlocklistRule) configure(arguments lint.Arguments) {
r.Lock()
defer r.Unlock()
- if r.blacklist == nil {
- r.blacklist = make([]*regexp.Regexp, 0)
+ if r.blocklist == nil {
+ r.blocklist = make([]*regexp.Regexp, 0)
for _, arg := range arguments {
argStr, ok := arg.(string)
if !ok {
- panic(fmt.Sprintf("Invalid argument to the imports-blacklist rule. Expecting a string, got %T", arg))
+ panic(fmt.Sprintf("Invalid argument to the imports-blocklist rule. Expecting a string, got %T", arg))
}
- regStr, err := regexp.Compile(fmt.Sprintf(`(?m)"%s"$`, replaceRegexp.ReplaceAllString(argStr, `(\W|\w)*`)))
+ regStr, err := regexp.Compile(fmt.Sprintf(`(?m)"%s"$`, replaceImportRegexp.ReplaceAllString(argStr, `(\W|\w)*`)))
if err != nil {
- panic(fmt.Sprintf("Invalid argument to the imports-blacklist rule. Expecting %q to be a valid regular expression, got: %v", argStr, err))
+ panic(fmt.Sprintf("Invalid argument to the imports-blocklist rule. Expecting %q to be a valid regular expression, got: %v", argStr, err))
}
- r.blacklist = append(r.blacklist, regStr)
+ r.blocklist = append(r.blocklist, regStr)
}
}
}
-func (r *ImportsBlacklistRule) isBlacklisted(path string) bool {
- for _, regex := range r.blacklist {
+func (r *ImportsBlocklistRule) isBlocklisted(path string) bool {
+ for _, regex := range r.blocklist {
if regex.MatchString(path) {
return true
}
@@ -47,17 +47,17 @@ func (r *ImportsBlacklistRule) isBlacklisted(path string) bool {
}
// Apply applies the rule to given file.
-func (r *ImportsBlacklistRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
+func (r *ImportsBlocklistRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
r.configure(arguments)
var failures []lint.Failure
for _, is := range file.AST.Imports {
path := is.Path
- if path != nil && r.isBlacklisted(path.Value) {
+ if path != nil && r.isBlocklisted(path.Value) {
failures = append(failures, lint.Failure{
Confidence: 1,
- Failure: "should not use the following blacklisted import: " + path.Value,
+ Failure: "should not use the following blocklisted import: " + path.Value,
Node: is,
Category: "imports",
})
@@ -68,6 +68,6 @@ func (r *ImportsBlacklistRule) Apply(file *lint.File, arguments lint.Arguments)
}
// Name returns the rule name.
-func (*ImportsBlacklistRule) Name() string {
- return "imports-blacklist"
+func (*ImportsBlocklistRule) Name() string {
+ return "imports-blocklist"
}
diff --git a/vendor/github.com/mgechev/revive/rule/indent-error-flow.go b/vendor/github.com/mgechev/revive/rule/indent-error-flow.go
index b80e6486c..294ceef84 100644
--- a/vendor/github.com/mgechev/revive/rule/indent-error-flow.go
+++ b/vendor/github.com/mgechev/revive/rule/indent-error-flow.go
@@ -19,7 +19,7 @@ func (*IndentErrorFlowRule) Name() string {
}
// CheckIfElse evaluates the rule against an ifelse.Chain.
-func (e *IndentErrorFlowRule) CheckIfElse(chain ifelse.Chain, args ifelse.Args) (failMsg string) {
+func (*IndentErrorFlowRule) CheckIfElse(chain ifelse.Chain, args ifelse.Args) (failMsg string) {
if !chain.If.Deviates() {
// this rule only applies if the if-block deviates control flow
return
diff --git a/vendor/github.com/mgechev/revive/rule/max-control-nesting.go b/vendor/github.com/mgechev/revive/rule/max-control-nesting.go
new file mode 100644
index 000000000..c4eb36193
--- /dev/null
+++ b/vendor/github.com/mgechev/revive/rule/max-control-nesting.go
@@ -0,0 +1,128 @@
+package rule
+
+import (
+ "fmt"
+ "go/ast"
+ "sync"
+
+ "github.com/mgechev/revive/lint"
+)
+
+// MaxControlNestingRule lints given else constructs.
+type MaxControlNestingRule struct {
+ max int64
+ sync.Mutex
+}
+
+const defaultMaxControlNesting = 5
+
+// Apply applies the rule to given file.
+func (r *MaxControlNestingRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
+ r.configure(arguments)
+
+ var failures []lint.Failure
+
+ fileAst := file.AST
+
+ walker := &lintMaxControlNesting{
+ onFailure: func(failure lint.Failure) {
+ failures = append(failures, failure)
+ },
+ max: int(r.max),
+ }
+
+ ast.Walk(walker, fileAst)
+
+ return failures
+}
+
+// Name returns the rule name.
+func (*MaxControlNestingRule) Name() string {
+ return "max-control-nesting"
+}
+
+type lintMaxControlNesting struct {
+ max int
+ onFailure func(lint.Failure)
+ nestingLevelAcc int
+ lastCtrlStmt ast.Node
+}
+
+func (w *lintMaxControlNesting) Visit(n ast.Node) ast.Visitor {
+ if w.nestingLevelAcc > w.max { // we are visiting a node beyond the max nesting level
+ w.onFailure(lint.Failure{
+ Failure: fmt.Sprintf("control flow nesting exceeds %d", w.max),
+ Confidence: 1,
+ Node: w.lastCtrlStmt,
+ Category: "complexity",
+ })
+ return nil // stop visiting deeper
+ }
+
+ switch v := n.(type) {
+ case *ast.IfStmt:
+ w.lastCtrlStmt = v
+ w.walkControlledBlock(v.Body) // "then" branch block
+ if v.Else != nil {
+ w.walkControlledBlock(v.Else) // "else" branch block
+ }
+ return nil // stop re-visiting nesting blocks (already visited by w.walkControlledBlock)
+
+ case *ast.ForStmt:
+ w.lastCtrlStmt = v
+ w.walkControlledBlock(v.Body)
+ return nil // stop re-visiting nesting blocks (already visited by w.walkControlledBlock)
+
+ case *ast.CaseClause: // switch case
+ w.lastCtrlStmt = v
+ for _, s := range v.Body { // visit each statement in the case clause
+ w.walkControlledBlock(s)
+ }
+ return nil // stop re-visiting nesting blocks (already visited by w.walkControlledBlock)
+
+ case *ast.CommClause: // select case
+ w.lastCtrlStmt = v
+ for _, s := range v.Body { // visit each statement in the select case clause
+ w.walkControlledBlock(s)
+ }
+ return nil // stop re-visiting nesting blocks (already visited by w.walkControlledBlock)
+
+ case *ast.FuncLit:
+ walker := &lintMaxControlNesting{
+ onFailure: w.onFailure,
+ max: w.max,
+ }
+ ast.Walk(walker, v.Body)
+ return nil
+ }
+
+ return w
+}
+
+func (w *lintMaxControlNesting) walkControlledBlock(b ast.Node) {
+ oldNestingLevel := w.nestingLevelAcc
+ w.nestingLevelAcc++
+ ast.Walk(w, b)
+ w.nestingLevelAcc = oldNestingLevel
+}
+
+func (r *MaxControlNestingRule) configure(arguments lint.Arguments) {
+ r.Lock()
+ defer r.Unlock()
+ if !(r.max < 1) {
+ return // max already set
+ }
+
+ if len(arguments) < 1 {
+ r.max = defaultMaxControlNesting
+ return
+ }
+
+ checkNumberOfArguments(1, arguments, r.Name())
+
+ max, ok := arguments[0].(int64) // Alt. non panicking version
+ if !ok {
+ panic(`invalid value passed as argument number to the "max-control-nesting" rule`)
+ }
+ r.max = max
+}
diff --git a/vendor/github.com/mgechev/revive/rule/modifies-value-receiver.go b/vendor/github.com/mgechev/revive/rule/modifies-value-receiver.go
index 34e651557..e9e64b9a6 100644
--- a/vendor/github.com/mgechev/revive/rule/modifies-value-receiver.go
+++ b/vendor/github.com/mgechev/revive/rule/modifies-value-receiver.go
@@ -78,11 +78,6 @@ func (w lintModifiesValRecRule) Visit(node ast.Node) ast.Visitor {
if name == "" || name != receiverName {
continue
}
-
- if w.skipType(ast.Expr(e.Sel)) {
- continue
- }
-
case *ast.Ident: // receiver := ...
if e.Name != receiverName {
continue
@@ -97,7 +92,7 @@ func (w lintModifiesValRecRule) Visit(node ast.Node) ast.Visitor {
return false
}
- assignmentsToReceiver := pick(n.Body, fselect, nil)
+ assignmentsToReceiver := pick(n.Body, fselect)
for _, assignment := range assignmentsToReceiver {
w.onFailure(lint.Failure{
diff --git a/vendor/github.com/mgechev/revive/rule/optimize-operands-order.go b/vendor/github.com/mgechev/revive/rule/optimize-operands-order.go
index 88928bb98..841bde56c 100644
--- a/vendor/github.com/mgechev/revive/rule/optimize-operands-order.go
+++ b/vendor/github.com/mgechev/revive/rule/optimize-operands-order.go
@@ -54,13 +54,13 @@ func (w lintOptimizeOperandsOrderlExpr) Visit(node ast.Node) ast.Visitor {
}
// check if the left sub-expression contains a function call
- nodes := pick(binExpr.X, isCaller, nil)
+ nodes := pick(binExpr.X, isCaller)
if len(nodes) < 1 {
return w
}
// check if the right sub-expression does not contain a function call
- nodes = pick(binExpr.Y, isCaller, nil)
+ nodes = pick(binExpr.Y, isCaller)
if len(nodes) > 0 {
return w
}
diff --git a/vendor/github.com/mgechev/revive/rule/string-format.go b/vendor/github.com/mgechev/revive/rule/string-format.go
index 3edd62477..70edf7387 100644
--- a/vendor/github.com/mgechev/revive/rule/string-format.go
+++ b/vendor/github.com/mgechev/revive/rule/string-format.go
@@ -38,7 +38,7 @@ func (*StringFormatRule) Name() string {
// ParseArgumentsTest is a public wrapper around w.parseArguments used for testing. Returns the error message provided to panic, or nil if no error was encountered
func (StringFormatRule) ParseArgumentsTest(arguments lint.Arguments) *string {
w := lintStringFormatRule{}
- c := make(chan interface{})
+ c := make(chan any)
// Parse the arguments in a goroutine, defer a recover() call, return the error encountered (or nil if there was no error)
go func() {
defer func() {
@@ -101,8 +101,8 @@ func (w *lintStringFormatRule) parseArguments(arguments lint.Arguments) {
}
}
-func (w lintStringFormatRule) parseArgument(argument interface{}, ruleNum int) (scope stringFormatSubruleScope, regex *regexp.Regexp, negated bool, errorMessage string) {
- g, ok := argument.([]interface{}) // Cast to generic slice first
+func (w lintStringFormatRule) parseArgument(argument any, ruleNum int) (scope stringFormatSubruleScope, regex *regexp.Regexp, negated bool, errorMessage string) {
+ g, ok := argument.([]any) // Cast to generic slice first
if !ok {
w.configError("argument is not a slice", ruleNum, 0)
}
diff --git a/vendor/github.com/mgechev/revive/rule/struct-tag.go b/vendor/github.com/mgechev/revive/rule/struct-tag.go
index d1c8056aa..f6ee47a73 100644
--- a/vendor/github.com/mgechev/revive/rule/struct-tag.go
+++ b/vendor/github.com/mgechev/revive/rule/struct-tag.go
@@ -140,7 +140,7 @@ func (lintStructTagRule) getTagName(tag *structtag.Tag) string {
return strings.TrimPrefix(option, "name=")
}
}
- return "" //protobuf tag lacks 'name' option
+ return "" // protobuf tag lacks 'name' option
default:
return tag.Name
}
diff --git a/vendor/github.com/mgechev/revive/rule/superfluous-else.go b/vendor/github.com/mgechev/revive/rule/superfluous-else.go
index 1ef67bf1a..2aa1b6b2c 100644
--- a/vendor/github.com/mgechev/revive/rule/superfluous-else.go
+++ b/vendor/github.com/mgechev/revive/rule/superfluous-else.go
@@ -20,7 +20,7 @@ func (*SuperfluousElseRule) Name() string {
}
// CheckIfElse evaluates the rule against an ifelse.Chain.
-func (e *SuperfluousElseRule) CheckIfElse(chain ifelse.Chain, args ifelse.Args) (failMsg string) {
+func (*SuperfluousElseRule) CheckIfElse(chain ifelse.Chain, args ifelse.Args) (failMsg string) {
if !chain.If.Deviates() {
// this rule only applies if the if-block deviates control flow
return
diff --git a/vendor/github.com/mgechev/revive/rule/unconditional-recursion.go b/vendor/github.com/mgechev/revive/rule/unconditional-recursion.go
index bad907533..9ac2648cd 100644
--- a/vendor/github.com/mgechev/revive/rule/unconditional-recursion.go
+++ b/vendor/github.com/mgechev/revive/rule/unconditional-recursion.go
@@ -45,8 +45,9 @@ type funcStatus struct {
}
type lintUnconditionalRecursionRule struct {
- onFailure func(lint.Failure)
- currentFunc *funcStatus
+ onFailure func(lint.Failure)
+ currentFunc *funcStatus
+ inGoStatement bool
}
// Visit will traverse the file AST.
@@ -68,9 +69,13 @@ func (w lintUnconditionalRecursionRule) Visit(node ast.Node) ast.Visitor {
default:
rec = n.Recv.List[0].Names[0]
}
-
w.currentFunc = &funcStatus{&funcDesc{rec, n.Name}, false}
case *ast.CallExpr:
+ // check if call arguments has a recursive call
+ for _, arg := range n.Args {
+ ast.Walk(w, arg)
+ }
+
var funcID *ast.Ident
var selector *ast.Ident
switch c := n.Fun.(type) {
@@ -84,6 +89,9 @@ func (w lintUnconditionalRecursionRule) Visit(node ast.Node) ast.Visitor {
return nil
}
funcID = c.Sel
+ case *ast.FuncLit:
+ ast.Walk(w, c.Body) // analyze the body of the function literal
+ return nil
default:
return w
}
@@ -93,11 +101,12 @@ func (w lintUnconditionalRecursionRule) Visit(node ast.Node) ast.Visitor {
w.currentFunc.funcDesc.equal(&funcDesc{selector, funcID}) {
w.onFailure(lint.Failure{
Category: "logic",
- Confidence: 1,
+ Confidence: 0.8,
Node: n,
Failure: "unconditional recursive call",
})
}
+ return nil
case *ast.IfStmt:
w.updateFuncStatus(n.Body)
w.updateFuncStatus(n.Else)
@@ -115,16 +124,21 @@ func (w lintUnconditionalRecursionRule) Visit(node ast.Node) ast.Visitor {
w.updateFuncStatus(n.Body)
return nil
case *ast.GoStmt:
- for _, a := range n.Call.Args {
- ast.Walk(w, a) // check if arguments have a recursive call
- }
- return nil // recursive async call is not an issue
+ w.inGoStatement = true
+ ast.Walk(w, n.Call)
+ w.inGoStatement = false
+ return nil
case *ast.ForStmt:
if n.Cond != nil {
return nil
}
// unconditional loop
return w
+ case *ast.FuncLit:
+ if w.inGoStatement {
+ return w
+ }
+ return nil // literal call (closure) is not necessarily an issue
}
return w
@@ -181,5 +195,5 @@ func (lintUnconditionalRecursionRule) hasControlExit(node ast.Node) bool {
return false
}
- return len(pick(node, isExit, nil)) != 0
+ return len(pick(node, isExit)) != 0
}
diff --git a/vendor/github.com/mgechev/revive/rule/unhandled-error.go b/vendor/github.com/mgechev/revive/rule/unhandled-error.go
index 32a5fe48b..ce6fa3864 100644
--- a/vendor/github.com/mgechev/revive/rule/unhandled-error.go
+++ b/vendor/github.com/mgechev/revive/rule/unhandled-error.go
@@ -119,7 +119,7 @@ func (w *lintUnhandledErrors) addFailure(n *ast.CallExpr) {
Category: "bad practice",
Confidence: 1,
Node: n,
- Failure: fmt.Sprintf("Unhandled error in call to function %v", gofmt(n.Fun)),
+ Failure: fmt.Sprintf("Unhandled error in call to function %v", name),
})
}
diff --git a/vendor/github.com/mgechev/revive/rule/unused-param.go b/vendor/github.com/mgechev/revive/rule/unused-param.go
index df6cd9af0..4b04ee916 100644
--- a/vendor/github.com/mgechev/revive/rule/unused-param.go
+++ b/vendor/github.com/mgechev/revive/rule/unused-param.go
@@ -35,7 +35,7 @@ func (r *UnusedParamRule) configure(args lint.Arguments) {
r.failureMsg = "parameter '%s' seems to be unused, consider removing or renaming it as _"
} else {
// Arguments = [{}]
- options := args[0].(map[string]interface{})
+ options := args[0].(map[string]any)
// Arguments = [{allowedRegex="^_"}]
if allowedRegexParam, ok := options["allowRegex"]; ok {
@@ -87,54 +87,64 @@ type lintUnusedParamRule struct {
}
func (w lintUnusedParamRule) Visit(node ast.Node) ast.Visitor {
+ var (
+ funcType *ast.FuncType
+ funcBody *ast.BlockStmt
+ )
switch n := node.(type) {
+ case *ast.FuncLit:
+ funcType = n.Type
+ funcBody = n.Body
case *ast.FuncDecl:
- params := retrieveNamedParams(n.Type.Params)
- if len(params) < 1 {
- return nil // skip, func without parameters
- }
-
if n.Body == nil {
return nil // skip, is a function prototype
}
- // inspect the func body looking for references to parameters
- fselect := func(n ast.Node) bool {
- ident, isAnID := n.(*ast.Ident)
+ funcType = n.Type
+ funcBody = n.Body
+ default:
+ return w // skip, not a function
+ }
- if !isAnID {
- return false
- }
+ params := retrieveNamedParams(funcType.Params)
+ if len(params) < 1 {
+ return w // skip, func without parameters
+ }
- _, isAParam := params[ident.Obj]
- if isAParam {
- params[ident.Obj] = false // mark as used
- }
+ // inspect the func body looking for references to parameters
+ fselect := func(n ast.Node) bool {
+ ident, isAnID := n.(*ast.Ident)
+ if !isAnID {
return false
}
- _ = pick(n.Body, fselect, nil)
-
- for _, p := range n.Type.Params.List {
- for _, n := range p.Names {
- if w.allowRegex.FindStringIndex(n.Name) != nil {
- continue
- }
- if params[n.Obj] {
- w.onFailure(lint.Failure{
- Confidence: 1,
- Node: n,
- Category: "bad practice",
- Failure: fmt.Sprintf(w.failureMsg, n.Name),
- })
- }
- }
+
+ _, isAParam := params[ident.Obj]
+ if isAParam {
+ params[ident.Obj] = false // mark as used
}
- return nil // full method body already inspected
+ return false
+ }
+ _ = pick(funcBody, fselect)
+
+ for _, p := range funcType.Params.List {
+ for _, n := range p.Names {
+ if w.allowRegex.FindStringIndex(n.Name) != nil {
+ continue
+ }
+ if params[n.Obj] {
+ w.onFailure(lint.Failure{
+ Confidence: 1,
+ Node: n,
+ Category: "bad practice",
+ Failure: fmt.Sprintf(w.failureMsg, n.Name),
+ })
+ }
+ }
}
- return w
+ return w // full method body was inspected
}
func retrieveNamedParams(params *ast.FieldList) map[*ast.Object]bool {
diff --git a/vendor/github.com/mgechev/revive/rule/unused-receiver.go b/vendor/github.com/mgechev/revive/rule/unused-receiver.go
index 488572b7b..715dba338 100644
--- a/vendor/github.com/mgechev/revive/rule/unused-receiver.go
+++ b/vendor/github.com/mgechev/revive/rule/unused-receiver.go
@@ -35,7 +35,7 @@ func (r *UnusedReceiverRule) configure(args lint.Arguments) {
r.failureMsg = "method receiver '%s' is not referenced in method's body, consider removing or renaming it as _"
} else {
// Arguments = [{}]
- options := args[0].(map[string]interface{})
+ options := args[0].(map[string]any)
// Arguments = [{allowedRegex="^_"}]
if allowedRegexParam, ok := options["allowRegex"]; ok {
@@ -113,7 +113,7 @@ func (w lintUnusedReceiverRule) Visit(node ast.Node) ast.Visitor {
return isAnID && ident.Obj == recID.Obj
}
- refs2recID := pick(n.Body, fselect, nil)
+ refs2recID := pick(n.Body, fselect)
if len(refs2recID) > 0 {
return nil // the receiver is referenced in the func body
diff --git a/vendor/github.com/mgechev/revive/rule/utils.go b/vendor/github.com/mgechev/revive/rule/utils.go
index dca1674ca..5778e7696 100644
--- a/vendor/github.com/mgechev/revive/rule/utils.go
+++ b/vendor/github.com/mgechev/revive/rule/utils.go
@@ -93,21 +93,15 @@ func srcLine(src []byte, p token.Position) string {
// pick yields a list of nodes by picking them from a sub-ast with root node n.
// Nodes are selected by applying the fselect function
-// f function is applied to each selected node before inserting it in the final result.
-// If f==nil then it defaults to the identity function (ie it returns the node itself)
-func pick(n ast.Node, fselect func(n ast.Node) bool, f func(n ast.Node) []ast.Node) []ast.Node {
+func pick(n ast.Node, fselect func(n ast.Node) bool) []ast.Node {
var result []ast.Node
if n == nil {
return result
}
- if f == nil {
- f = func(n ast.Node) []ast.Node { return []ast.Node{n} }
- }
-
onSelect := func(n ast.Node) {
- result = append(result, f(n)...)
+ result = append(result, n)
}
p := picker{fselect: fselect, onSelect: onSelect}
ast.Walk(p, n)
@@ -158,7 +152,7 @@ func isExprABooleanLit(n ast.Node) (lexeme string, ok bool) {
}
// gofmt returns a string representation of an AST subtree.
-func gofmt(x interface{}) string {
+func gofmt(x any) string {
buf := bytes.Buffer{}
fs := token.NewFileSet()
printer.Fprint(&buf, fs, x)
diff --git a/vendor/github.com/mgechev/revive/rule/var-naming.go b/vendor/github.com/mgechev/revive/rule/var-naming.go
index 286ff9d75..e91c22dc2 100644
--- a/vendor/github.com/mgechev/revive/rule/var-naming.go
+++ b/vendor/github.com/mgechev/revive/rule/var-naming.go
@@ -18,10 +18,11 @@ var upperCaseConstRE = regexp.MustCompile(`^_?[A-Z][A-Z\d]*(_[A-Z\d]+)*$`)
// VarNamingRule lints given else constructs.
type VarNamingRule struct {
- configured bool
- whitelist []string
- blacklist []string
- upperCaseConst bool // if true - allows to use UPPER_SOME_NAMES for constants
+ configured bool
+ allowlist []string
+ blocklist []string
+ upperCaseConst bool // if true - allows to use UPPER_SOME_NAMES for constants
+ skipPackageNameChecks bool
sync.Mutex
}
@@ -34,31 +35,53 @@ func (r *VarNamingRule) configure(arguments lint.Arguments) {
r.configured = true
if len(arguments) >= 1 {
- r.whitelist = getList(arguments[0], "whitelist")
+ r.allowlist = getList(arguments[0], "allowlist")
}
if len(arguments) >= 2 {
- r.blacklist = getList(arguments[1], "blacklist")
+ r.blocklist = getList(arguments[1], "blocklist")
}
if len(arguments) >= 3 {
// not pretty code because should keep compatibility with TOML (no mixed array types) and new map parameters
thirdArgument := arguments[2]
- asSlice, ok := thirdArgument.([]interface{})
+ asSlice, ok := thirdArgument.([]any)
if !ok {
panic(fmt.Sprintf("Invalid third argument to the var-naming rule. Expecting a %s of type slice, got %T", "options", arguments[2]))
}
if len(asSlice) != 1 {
panic(fmt.Sprintf("Invalid third argument to the var-naming rule. Expecting a %s of type slice, of len==1, but %d", "options", len(asSlice)))
}
- args, ok := asSlice[0].(map[string]interface{})
+ args, ok := asSlice[0].(map[string]any)
if !ok {
panic(fmt.Sprintf("Invalid third argument to the var-naming rule. Expecting a %s of type slice, of len==1, with map, but %T", "options", asSlice[0]))
}
r.upperCaseConst = fmt.Sprint(args["upperCaseConst"]) == "true"
+ r.skipPackageNameChecks = fmt.Sprint(args["skipPackageNameChecks"]) == "true"
}
}
+func (r *VarNamingRule) applyPackageCheckRules(walker *lintNames) {
+ // Package names need slightly different handling than other names.
+ if strings.Contains(walker.fileAst.Name.Name, "_") && !strings.HasSuffix(walker.fileAst.Name.Name, "_test") {
+ walker.onFailure(lint.Failure{
+ Failure: "don't use an underscore in package name",
+ Confidence: 1,
+ Node: walker.fileAst.Name,
+ Category: "naming",
+ })
+ }
+ if anyCapsRE.MatchString(walker.fileAst.Name.Name) {
+ walker.onFailure(lint.Failure{
+ Failure: fmt.Sprintf("don't use MixedCaps in package name; %s should be %s", walker.fileAst.Name.Name, strings.ToLower(walker.fileAst.Name.Name)),
+ Confidence: 1,
+ Node: walker.fileAst.Name,
+ Category: "naming",
+ })
+ }
+
+}
+
// Apply applies the rule to given file.
func (r *VarNamingRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
r.configure(arguments)
@@ -70,30 +93,16 @@ func (r *VarNamingRule) Apply(file *lint.File, arguments lint.Arguments) []lint.
walker := lintNames{
file: file,
fileAst: fileAst,
- whitelist: r.whitelist,
- blacklist: r.blacklist,
+ allowlist: r.allowlist,
+ blocklist: r.blocklist,
onFailure: func(failure lint.Failure) {
failures = append(failures, failure)
},
upperCaseConst: r.upperCaseConst,
}
- // Package names need slightly different handling than other names.
- if strings.Contains(walker.fileAst.Name.Name, "_") && !strings.HasSuffix(walker.fileAst.Name.Name, "_test") {
- walker.onFailure(lint.Failure{
- Failure: "don't use an underscore in package name",
- Confidence: 1,
- Node: walker.fileAst.Name,
- Category: "naming",
- })
- }
- if anyCapsRE.MatchString(walker.fileAst.Name.Name) {
- walker.onFailure(lint.Failure{
- Failure: fmt.Sprintf("don't use MixedCaps in package name; %s should be %s", walker.fileAst.Name.Name, strings.ToLower(walker.fileAst.Name.Name)),
- Confidence: 1,
- Node: walker.fileAst.Name,
- Category: "naming",
- })
+ if !r.skipPackageNameChecks {
+ r.applyPackageCheckRules(&walker)
}
ast.Walk(&walker, fileAst)
@@ -127,7 +136,7 @@ func (w *lintNames) check(id *ast.Ident, thing string) {
// #851 upperCaseConst support
// if it's const
- if thing == token.CONST.String() && w.upperCaseConst && upperCaseConstRE.Match([]byte(id.Name)) {
+ if thing == token.CONST.String() && w.upperCaseConst && upperCaseConstRE.MatchString(id.Name) {
return
}
@@ -142,7 +151,7 @@ func (w *lintNames) check(id *ast.Ident, thing string) {
return
}
- should := lint.Name(id.Name, w.whitelist, w.blacklist)
+ should := lint.Name(id.Name, w.allowlist, w.blocklist)
if id.Name == should {
return
}
@@ -168,8 +177,8 @@ type lintNames struct {
file *lint.File
fileAst *ast.File
onFailure func(lint.Failure)
- whitelist []string
- blacklist []string
+ allowlist []string
+ blocklist []string
upperCaseConst bool
}
@@ -255,8 +264,8 @@ func (w *lintNames) Visit(n ast.Node) ast.Visitor {
return w
}
-func getList(arg interface{}, argName string) []string {
- temp, ok := arg.([]interface{})
+func getList(arg any, argName string) []string {
+ temp, ok := arg.([]any)
if !ok {
panic(fmt.Sprintf("Invalid argument to the var-naming rule. Expecting a %s of type slice with initialisms, got %T", argName, arg))
}