aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/polyfloyd
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2023-02-22 22:16:50 +0100
committerTaras Madan <tarasmadan@google.com>2023-02-24 12:47:23 +0100
commit4165372ec8fd142475a4e35fd0cf4f8042132208 (patch)
tree21cd62211b4dd80bee469054c5b65db77342333c /vendor/github.com/polyfloyd
parent2b3ed821a493b8936c8bacfa6f8b4f1c90a00855 (diff)
dependencies: update
set go min requirements to 1.19 update dependencies update vendor
Diffstat (limited to 'vendor/github.com/polyfloyd')
-rw-r--r--vendor/github.com/polyfloyd/go-errorlint/errorlint/allowed.go1
-rw-r--r--vendor/github.com/polyfloyd/go-errorlint/errorlint/analysis.go14
-rw-r--r--vendor/github.com/polyfloyd/go-errorlint/errorlint/lint.go83
-rw-r--r--vendor/github.com/polyfloyd/go-errorlint/errorlint/printf.go3
4 files changed, 88 insertions, 13 deletions
diff --git a/vendor/github.com/polyfloyd/go-errorlint/errorlint/allowed.go b/vendor/github.com/polyfloyd/go-errorlint/errorlint/allowed.go
index 7fe4c38cc..c9dcf5e55 100644
--- a/vendor/github.com/polyfloyd/go-errorlint/errorlint/allowed.go
+++ b/vendor/github.com/polyfloyd/go-errorlint/errorlint/allowed.go
@@ -40,6 +40,7 @@ var allowedErrors = []struct {
{err: "io.ErrClosedPipe", fun: "(*io.PipeWriter).Write"},
{err: "io.ErrShortBuffer", fun: "io.ReadAtLeast"},
{err: "io.ErrUnexpectedEOF", fun: "io.ReadAtLeast"},
+ {err: "io.EOF", fun: "io.ReadFull"},
{err: "io.ErrUnexpectedEOF", fun: "io.ReadFull"},
// pkg/net/http
{err: "http.ErrServerClosed", fun: "(*net/http.Server).ListenAndServe"},
diff --git a/vendor/github.com/polyfloyd/go-errorlint/errorlint/analysis.go b/vendor/github.com/polyfloyd/go-errorlint/errorlint/analysis.go
index 58ddb2632..ab02136f4 100644
--- a/vendor/github.com/polyfloyd/go-errorlint/errorlint/analysis.go
+++ b/vendor/github.com/polyfloyd/go-errorlint/errorlint/analysis.go
@@ -57,7 +57,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
type TypesInfoExt struct {
types.Info
- // Maps AST nodes back to the node they are contain within.
+ // Maps AST nodes back to the node they are contained within.
NodeParent map[ast.Node]ast.Node
// Maps an object back to all identifiers to refer to it.
@@ -97,3 +97,15 @@ func newTypesInfoExt(info *types.Info) *TypesInfoExt {
IdentifiersForObject: identifiersForObject,
}
}
+
+func (info *TypesInfoExt) ContainingFuncDecl(node ast.Node) *ast.FuncDecl {
+ for parent := info.NodeParent[node]; ; parent = info.NodeParent[parent] {
+ if _, ok := parent.(*ast.File); ok {
+ break
+ }
+ if fun, ok := parent.(*ast.FuncDecl); ok {
+ return fun
+ }
+ }
+ return nil
+}
diff --git a/vendor/github.com/polyfloyd/go-errorlint/errorlint/lint.go b/vendor/github.com/polyfloyd/go-errorlint/errorlint/lint.go
index 5301a3f22..b9ebe6efe 100644
--- a/vendor/github.com/polyfloyd/go-errorlint/errorlint/lint.go
+++ b/vendor/github.com/polyfloyd/go-errorlint/errorlint/lint.go
@@ -41,9 +41,9 @@ func LintFmtErrorfCalls(fset *token.FileSet, info types.Info) []Lint {
continue
}
- // For any arguments that are errors, check whether the wrapping verb
- // is used. Only one %w verb may be used in a single format string at a
- // time, so we stop after finding a correct %w.
+ // For any arguments that are errors, check whether the wrapping verb is used. %w may occur
+ // for multiple errors in one Errorf invocation. We raise an issue if at least one error
+ // does not have a corresponding wrapping verb.
var lintArg ast.Expr
args := call.Args[1:]
for i := 0; i < len(args) && i < len(formatVerbs); i++ {
@@ -52,12 +52,12 @@ func LintFmtErrorfCalls(fset *token.FileSet, info types.Info) []Lint {
}
if formatVerbs[i] == "w" {
- lintArg = nil
- break
+ continue
}
if lintArg == nil {
lintArg = args[i]
+ break
}
}
if lintArg != nil {
@@ -85,8 +85,8 @@ func isErrorStringCall(info types.Info, expr ast.Expr) bool {
}
// printfFormatStringVerbs returns a normalized list of all the verbs that are used per argument to
-// the printf function. The index of each returned element corresponds to index of the respective
-// argument.
+// the printf function. The index of each returned element corresponds to the index of the
+// respective argument.
func printfFormatStringVerbs(info types.Info, call *ast.CallExpr) ([]string, bool) {
if len(call.Args) <= 1 {
return nil, false
@@ -156,10 +156,14 @@ func LintErrorComparisons(fset *token.FileSet, info *TypesInfoExt) []Lint {
if !isErrorComparison(info.Info, binExpr) {
continue
}
-
+ // Some errors that are returned from some functions are exempt.
if isAllowedErrorComparison(info, binExpr) {
continue
}
+ // Comparisons that happen in `func (type) Is(error) bool` are okay.
+ if isNodeInErrorIsFunc(info, binExpr) {
+ continue
+ }
lints = append(lints, Lint{
Message: fmt.Sprintf("comparing with %s will fail on wrapped errors. Use errors.Is to check for a specific error", binExpr.Op),
@@ -181,11 +185,17 @@ func LintErrorComparisons(fset *token.FileSet, info *TypesInfoExt) []Lint {
if tagType.Type.String() != "error" {
continue
}
+ if isNodeInErrorIsFunc(info, switchStmt) {
+ continue
+ }
+
+ if switchComparesNonNil(switchStmt) {
+ lints = append(lints, Lint{
+ Message: "switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors",
+ Pos: switchStmt.Pos(),
+ })
+ }
- lints = append(lints, Lint{
- Message: "switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors",
- Pos: switchStmt.Pos(),
- })
}
return lints
@@ -207,6 +217,55 @@ func isErrorComparison(info types.Info, binExpr *ast.BinaryExpr) bool {
return tx.Type.String() == "error" || ty.Type.String() == "error"
}
+func isNodeInErrorIsFunc(info *TypesInfoExt, node ast.Node) bool {
+ funcDecl := info.ContainingFuncDecl(node)
+ if funcDecl == nil {
+ return false
+ }
+
+ if funcDecl.Name.Name != "Is" {
+ return false
+ }
+ if funcDecl.Recv == nil {
+ return false
+ }
+ // There should be 1 argument of type error.
+ if ii := funcDecl.Type.Params.List; len(ii) != 1 || info.Types[ii[0].Type].Type.String() != "error" {
+ return false
+ }
+ // The return type should be bool.
+ if ii := funcDecl.Type.Results.List; len(ii) != 1 || info.Types[ii[0].Type].Type.String() != "bool" {
+ return false
+ }
+
+ return true
+}
+
+// switchComparesNonNil returns true if one of its clauses compares by value.
+func switchComparesNonNil(switchStmt *ast.SwitchStmt) bool {
+ for _, caseBlock := range switchStmt.Body.List {
+ caseClause, ok := caseBlock.(*ast.CaseClause)
+ if !ok {
+ continue
+ }
+ for _, clause := range caseClause.List {
+ switch clause := clause.(type) {
+ case nil:
+ // default label is safe
+ continue
+ case *ast.Ident:
+ // `case nil` is safe
+ if clause.Name == "nil" {
+ continue
+ }
+ }
+ // anything else (including an Ident other than nil) isn't safe
+ return true
+ }
+ }
+ return false
+}
+
func LintErrorTypeAssertions(fset *token.FileSet, info types.Info) []Lint {
lints := []Lint{}
diff --git a/vendor/github.com/polyfloyd/go-errorlint/errorlint/printf.go b/vendor/github.com/polyfloyd/go-errorlint/errorlint/printf.go
index f3d81b571..d9a935ff2 100644
--- a/vendor/github.com/polyfloyd/go-errorlint/errorlint/printf.go
+++ b/vendor/github.com/polyfloyd/go-errorlint/errorlint/printf.go
@@ -14,6 +14,9 @@ func verbOrder(verbs []verb, numArgs int) [][]verb {
if v.index != -1 {
i = v.index - 1
}
+ if i >= len(orderedVerbs) {
+ continue
+ }
orderedVerbs[i] = append(orderedVerbs[i], v)
verbs = verbs[1:]
i++