diff options
| author | Taras Madan <tarasmadan@google.com> | 2025-01-22 16:07:17 +0100 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2025-01-23 10:42:36 +0000 |
| commit | 7b4377ad9d8a7205416df8d6217ef2b010f89481 (patch) | |
| tree | e6fec4fd12ff807a16d847923f501075bf71d16c /vendor/github.com/Antonboom/errname | |
| parent | 475a4c203afb8b7d3af51c4fd32bb170ff32a45e (diff) | |
vendor: delete
Diffstat (limited to 'vendor/github.com/Antonboom/errname')
| -rw-r--r-- | vendor/github.com/Antonboom/errname/LICENSE | 21 | ||||
| -rw-r--r-- | vendor/github.com/Antonboom/errname/pkg/analyzer/analyzer.go | 108 | ||||
| -rw-r--r-- | vendor/github.com/Antonboom/errname/pkg/analyzer/facts.go | 95 |
3 files changed, 0 insertions, 224 deletions
diff --git a/vendor/github.com/Antonboom/errname/LICENSE b/vendor/github.com/Antonboom/errname/LICENSE deleted file mode 100644 index e2002e4d4..000000000 --- a/vendor/github.com/Antonboom/errname/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 Anton Telyshev - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/vendor/github.com/Antonboom/errname/pkg/analyzer/analyzer.go b/vendor/github.com/Antonboom/errname/pkg/analyzer/analyzer.go deleted file mode 100644 index 2b8794dc2..000000000 --- a/vendor/github.com/Antonboom/errname/pkg/analyzer/analyzer.go +++ /dev/null @@ -1,108 +0,0 @@ -package analyzer - -import ( - "go/ast" - "go/token" - "go/types" - "unicode" - - "golang.org/x/tools/go/analysis" - "golang.org/x/tools/go/analysis/passes/inspect" - "golang.org/x/tools/go/ast/inspector" -) - -// New returns new errname analyzer. -func New() *analysis.Analyzer { - return &analysis.Analyzer{ - Name: "errname", - Doc: "Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.", - Run: run, - Requires: []*analysis.Analyzer{inspect.Analyzer}, - } -} - -func run(pass *analysis.Pass) (interface{}, error) { - insp := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) - - insp.Nodes([]ast.Node{ - (*ast.TypeSpec)(nil), - (*ast.ValueSpec)(nil), - (*ast.FuncDecl)(nil), - }, func(node ast.Node, push bool) bool { - if !push { - return false - } - - switch v := node.(type) { - case *ast.FuncDecl: - return false - - case *ast.ValueSpec: - if len(v.Names) != 1 { - return false - } - ident := v.Names[0] - - if exprImplementsError(pass, ident) && !isValidErrorVarName(ident.Name) { - reportAboutSentinelError(pass, v.Pos(), ident.Name) - } - return false - - case *ast.TypeSpec: - tt := pass.TypesInfo.TypeOf(v.Name) - if tt == nil { - return false - } - // NOTE(a.telyshev): Pointer is the hack against Error() method with pointer receiver. - if !typeImplementsError(types.NewPointer(tt)) { - return false - } - - name := v.Name.Name - if _, ok := v.Type.(*ast.ArrayType); ok { - if !isValidErrorArrayTypeName(name) { - reportAboutArrayErrorType(pass, v.Pos(), name) - } - } else if !isValidErrorTypeName(name) { - reportAboutErrorType(pass, v.Pos(), name) - } - return false - } - - return true - }) - - return nil, nil //nolint:nilnil -} - -func reportAboutErrorType(pass *analysis.Pass, typePos token.Pos, typeName string) { - var form string - if unicode.IsLower([]rune(typeName)[0]) { - form = "xxxError" - } else { - form = "XxxError" - } - - pass.Reportf(typePos, "the error type name `%s` should conform to the `%s` format", typeName, form) -} - -func reportAboutArrayErrorType(pass *analysis.Pass, typePos token.Pos, typeName string) { - var forms string - if unicode.IsLower([]rune(typeName)[0]) { - forms = "`xxxErrors` or `xxxError`" - } else { - forms = "`XxxErrors` or `XxxError`" - } - - pass.Reportf(typePos, "the error type name `%s` should conform to the %s format", typeName, forms) -} - -func reportAboutSentinelError(pass *analysis.Pass, pos token.Pos, varName string) { - var form string - if unicode.IsLower([]rune(varName)[0]) { - form = "errXxx" - } else { - form = "ErrXxx" - } - pass.Reportf(pos, "the sentinel error name `%s` should conform to the `%s` format", varName, form) -} diff --git a/vendor/github.com/Antonboom/errname/pkg/analyzer/facts.go b/vendor/github.com/Antonboom/errname/pkg/analyzer/facts.go deleted file mode 100644 index 04e14fb68..000000000 --- a/vendor/github.com/Antonboom/errname/pkg/analyzer/facts.go +++ /dev/null @@ -1,95 +0,0 @@ -package analyzer - -import ( - "go/ast" - "go/types" - "strings" - "unicode" - - "golang.org/x/tools/go/analysis" -) - -var errorIface = types.Universe.Lookup("error").Type().Underlying().(*types.Interface) - -func exprImplementsError(pass *analysis.Pass, e ast.Expr) bool { - return typeImplementsError(pass.TypesInfo.TypeOf(e)) -} - -func typeImplementsError(t types.Type) bool { - return t != nil && types.Implements(t, errorIface) -} - -func isValidErrorTypeName(s string) bool { - if isInitialism(s) { - return true - } - - words := split(s) - wordsCnt := wordsCount(words) - - if wordsCnt["error"] != 1 { - return false - } - return words[len(words)-1] == "error" -} - -func isValidErrorArrayTypeName(s string) bool { - if isInitialism(s) { - return true - } - - words := split(s) - wordsCnt := wordsCount(words) - - if wordsCnt["errors"] != 1 && wordsCnt["error"] != 1 { - return false - } - - lastWord := words[len(words)-1] - return lastWord == "errors" || lastWord == "error" -} - -func isValidErrorVarName(s string) bool { - if isInitialism(s) { - return true - } - - words := split(s) - wordsCnt := wordsCount(words) - - if wordsCnt["err"] != 1 { - return false - } - return words[0] == "err" -} - -func isInitialism(s string) bool { - return strings.ToLower(s) == s || strings.ToUpper(s) == s -} - -func split(s string) []string { - var words []string - ss := []rune(s) - - var b strings.Builder - b.WriteRune(ss[0]) - - for _, r := range ss[1:] { - if unicode.IsUpper(r) { - words = append(words, strings.ToLower(b.String())) - b.Reset() - } - b.WriteRune(r) - } - - words = append(words, strings.ToLower(b.String())) - return words -} - -func wordsCount(w []string) map[string]int { - result := make(map[string]int, len(w)) - for _, ww := range w { - result[ww]++ - } - return result -} |
