aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/butuzov
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/butuzov
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/butuzov')
-rw-r--r--vendor/github.com/butuzov/ireturn/analyzer/analyzer.go79
-rw-r--r--vendor/github.com/butuzov/ireturn/analyzer/internal/types/iface.go11
-rw-r--r--vendor/github.com/butuzov/ireturn/analyzer/std.go3
-rw-r--r--vendor/github.com/butuzov/ireturn/analyzer/typeparams.go38
4 files changed, 68 insertions, 63 deletions
diff --git a/vendor/github.com/butuzov/ireturn/analyzer/analyzer.go b/vendor/github.com/butuzov/ireturn/analyzer/analyzer.go
index 21e5897b2..f68170fb3 100644
--- a/vendor/github.com/butuzov/ireturn/analyzer/analyzer.go
+++ b/vendor/github.com/butuzov/ireturn/analyzer/analyzer.go
@@ -4,6 +4,7 @@ import (
"flag"
"go/ast"
gotypes "go/types"
+ "runtime"
"strings"
"sync"
@@ -22,10 +23,11 @@ type validator interface {
}
type analyzer struct {
- once sync.Once
- mu sync.RWMutex
- handler validator
- err error
+ once sync.Once
+ mu sync.RWMutex
+ handler validator
+ err error
+ diabledNolint bool
found []analysis.Diagnostic
}
@@ -61,8 +63,7 @@ func (a *analyzer) run(pass *analysis.Pass) (interface{}, error) {
}
// 003. Is it allowed to be checked?
- // TODO(butuzov): add inline comment
- if hasDisallowDirective(f.Doc) {
+ if !a.diabledNolint && hasDisallowDirective(f.Doc) {
return
}
@@ -70,7 +71,6 @@ func (a *analyzer) run(pass *analysis.Pass) (interface{}, error) {
// 004. Filtering Results.
for _, issue := range filterInterfaces(pass, f.Type, dotImportedStd) {
-
if a.handler.IsValid(issue) {
continue
}
@@ -112,6 +112,13 @@ func (a *analyzer) readConfiguration(fs *flag.FlagSet) {
return
}
+ // First: checking nonolint directive
+ val := fs.Lookup("nonolint")
+ if val != nil {
+ a.diabledNolint = fs.Lookup("nonolint").Value.String() == "true"
+ }
+
+ // Second: validators implementation next
if validatorImpl, ok := cnf.(validator); ok {
a.handler = validatorImpl
return
@@ -136,6 +143,7 @@ func flags() flag.FlagSet {
set := flag.NewFlagSet("", flag.PanicOnError)
set.String("allow", "", "accept-list of the comma-separated interfaces")
set.String("reject", "", "reject-list of the comma-separated interfaces")
+ set.Bool("nonolint", false, "disable nolint checks")
return *set
}
@@ -146,13 +154,10 @@ func filterInterfaces(p *analysis.Pass, ft *ast.FuncType, di map[string]struct{}
return results
}
- tp := newTypeParams(ft.TypeParams)
-
for _, el := range ft.Results.List {
switch v := el.Type.(type) {
// ----- empty or anonymous interfaces
case *ast.InterfaceType:
-
if len(v.Methods.List) == 0 {
results = append(results, types.NewIssue("interface{}", types.EmptyInterface))
continue
@@ -164,35 +169,65 @@ func filterInterfaces(p *analysis.Pass, ft *ast.FuncType, di map[string]struct{}
case *ast.Ident:
t1 := p.TypesInfo.TypeOf(el.Type)
- if !gotypes.IsInterface(t1.Underlying()) {
+ val, ok := t1.Underlying().(*gotypes.Interface)
+ if !ok {
continue
}
- word := t1.String()
- // only build in interface is error
- if obj := gotypes.Universe.Lookup(word); obj != nil {
- results = append(results, types.NewIssue(obj.Name(), types.ErrorInterface))
+ var (
+ name = t1.String()
+ isNamed = strings.Contains(name, ".")
+ isEmpty = val.Empty()
+ )
+
+ // catching any
+ if isEmpty && name == "any" {
+ results = append(results, types.NewIssue(name, types.EmptyInterface))
+ continue
+ }
+
+ // NOTE: FIXED!
+ if name == "error" {
+ results = append(results, types.NewIssue(name, types.ErrorInterface))
continue
}
- // found in type params
- if tp.In(word) {
- results = append(results, types.NewIssue(word, types.Generic))
+ if !isNamed {
+
+ typeParams := val.String()
+ prefix, suffix := "interface{", "}"
+ if strings.HasPrefix(typeParams, prefix) { // nolint: gosimple
+ typeParams = typeParams[len(prefix):]
+ }
+ if strings.HasSuffix(typeParams, suffix) {
+ typeParams = typeParams[:len(typeParams)-1]
+ }
+
+ goVersion := runtime.Version()
+ if strings.HasPrefix(goVersion, "go1.18") || strings.HasPrefix(goVersion, "go1.19") {
+ typeParams = strings.ReplaceAll(typeParams, "|", " | ")
+ }
+
+ results = append(results, types.IFace{
+ Name: name,
+ Type: types.Generic,
+ OfType: typeParams,
+ })
continue
}
// is it dot-imported package?
// handling cases when stdlib package imported via "." dot-import
if len(di) > 0 {
- name := stdPkgInterface(word)
- if _, ok := di[name]; ok {
- results = append(results, types.NewIssue(word, types.NamedStdInterface))
+ pkgName := stdPkgInterface(name)
+ if _, ok := di[pkgName]; ok {
+ results = append(results, types.NewIssue(name, types.NamedStdInterface))
continue
}
}
- results = append(results, types.NewIssue(word, types.NamedInterface))
+ results = append(results, types.NewIssue(name, types.NamedInterface))
// ------- standard library and 3rd party interfaces
case *ast.SelectorExpr:
diff --git a/vendor/github.com/butuzov/ireturn/analyzer/internal/types/iface.go b/vendor/github.com/butuzov/ireturn/analyzer/internal/types/iface.go
index 13f19a3e2..5e576374d 100644
--- a/vendor/github.com/butuzov/ireturn/analyzer/internal/types/iface.go
+++ b/vendor/github.com/butuzov/ireturn/analyzer/internal/types/iface.go
@@ -14,6 +14,7 @@ type IFace struct {
Pos token.Pos // Token Position
FuncName string //
+ OfType string
}
func NewIssue(name string, interfaceType IType) IFace {
@@ -30,11 +31,15 @@ func (i *IFace) Enrich(f *ast.FuncDecl) {
}
func (i IFace) String() string {
- if i.Type == Generic {
- return fmt.Sprintf("%s returns generic interface (%s)", i.FuncName, i.Name)
+ if i.Type != Generic {
+ return fmt.Sprintf("%s returns interface (%s)", i.FuncName, i.Name)
}
- return fmt.Sprintf("%s returns interface (%s)", i.FuncName, i.Name)
+ if i.OfType != "" {
+ return fmt.Sprintf("%s returns generic interface (%s) of type param %s", i.FuncName, i.Name, i.OfType)
+ }
+
+ return fmt.Sprintf("%s returns generic interface (%s)", i.FuncName, i.Name)
}
func (i IFace) HashString() string {
diff --git a/vendor/github.com/butuzov/ireturn/analyzer/std.go b/vendor/github.com/butuzov/ireturn/analyzer/std.go
index 4c6c4e420..cac464612 100644
--- a/vendor/github.com/butuzov/ireturn/analyzer/std.go
+++ b/vendor/github.com/butuzov/ireturn/analyzer/std.go
@@ -197,4 +197,7 @@ var std = map[string]struct{}{
"maps": {},
"slices": {},
"testing/slogtest": {},
+ // added in Go v1.22 in compare to v1.21 (docker image)
+ "go/version": {},
+ "math/rand/v2": {},
}
diff --git a/vendor/github.com/butuzov/ireturn/analyzer/typeparams.go b/vendor/github.com/butuzov/ireturn/analyzer/typeparams.go
deleted file mode 100644
index 14193c355..000000000
--- a/vendor/github.com/butuzov/ireturn/analyzer/typeparams.go
+++ /dev/null
@@ -1,38 +0,0 @@
-package analyzer
-
-import (
- "go/ast"
-)
-
-type typeParams struct {
- found []string
-}
-
-func newTypeParams(fl *ast.FieldList) typeParams {
- tp := typeParams{}
-
- if fl == nil {
- return tp
- }
-
- for _, el := range fl.List {
- if el == nil {
- continue
- }
-
- for _, name := range el.Names {
- tp.found = append(tp.found, name.Name)
- }
- }
-
- return tp
-}
-
-func (tp typeParams) In(t string) bool {
- for _, i := range tp.found {
- if i == t {
- return true
- }
- }
- return false
-}