From 7b4377ad9d8a7205416df8d6217ef2b010f89481 Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Wed, 22 Jan 2025 16:07:17 +0100 Subject: vendor: delete --- .../loggercheck/internal/checkers/checker.go | 58 ----- .../loggercheck/internal/checkers/common.go | 46 ---- .../loggercheck/internal/checkers/filter.go | 35 --- .../loggercheck/internal/checkers/general.go | 68 ------ .../loggercheck/internal/checkers/printf/printf.go | 252 --------------------- .../loggercheck/internal/checkers/slog.go | 19 -- .../timonwong/loggercheck/internal/checkers/zap.go | 21 -- .../timonwong/loggercheck/internal/rules/rules.go | 198 ---------------- .../timonwong/loggercheck/internal/sets/string.go | 59 ----- .../loggercheck/internal/stringutil/is.go | 15 -- 10 files changed, 771 deletions(-) delete mode 100644 vendor/github.com/timonwong/loggercheck/internal/checkers/checker.go delete mode 100644 vendor/github.com/timonwong/loggercheck/internal/checkers/common.go delete mode 100644 vendor/github.com/timonwong/loggercheck/internal/checkers/filter.go delete mode 100644 vendor/github.com/timonwong/loggercheck/internal/checkers/general.go delete mode 100644 vendor/github.com/timonwong/loggercheck/internal/checkers/printf/printf.go delete mode 100644 vendor/github.com/timonwong/loggercheck/internal/checkers/slog.go delete mode 100644 vendor/github.com/timonwong/loggercheck/internal/checkers/zap.go delete mode 100644 vendor/github.com/timonwong/loggercheck/internal/rules/rules.go delete mode 100644 vendor/github.com/timonwong/loggercheck/internal/sets/string.go delete mode 100644 vendor/github.com/timonwong/loggercheck/internal/stringutil/is.go (limited to 'vendor/github.com/timonwong/loggercheck/internal') diff --git a/vendor/github.com/timonwong/loggercheck/internal/checkers/checker.go b/vendor/github.com/timonwong/loggercheck/internal/checkers/checker.go deleted file mode 100644 index 5fa1cfb2c..000000000 --- a/vendor/github.com/timonwong/loggercheck/internal/checkers/checker.go +++ /dev/null @@ -1,58 +0,0 @@ -package checkers - -import ( - "go/ast" - "go/types" - - "golang.org/x/tools/go/analysis" -) - -type Config struct { - RequireStringKey bool - NoPrintfLike bool -} - -type CallContext struct { - Expr *ast.CallExpr - Func *types.Func - Signature *types.Signature -} - -type Checker interface { - FilterKeyAndValues(pass *analysis.Pass, keyAndValues []ast.Expr) []ast.Expr - CheckLoggingKey(pass *analysis.Pass, keyAndValues []ast.Expr) - CheckPrintfLikeSpecifier(pass *analysis.Pass, args []ast.Expr) -} - -func ExecuteChecker(c Checker, pass *analysis.Pass, call CallContext, cfg Config) { - params := call.Signature.Params() - nparams := params.Len() // variadic => nonzero - startIndex := nparams - 1 - - iface, ok := types.Unalias(params.At(startIndex).Type().(*types.Slice).Elem()).(*types.Interface) - if !ok || !iface.Empty() { - return // final (args) param is not ...interface{} - } - - keyValuesArgs := c.FilterKeyAndValues(pass, call.Expr.Args[startIndex:]) - - if len(keyValuesArgs)%2 != 0 { - firstArg := keyValuesArgs[0] - lastArg := keyValuesArgs[len(keyValuesArgs)-1] - pass.Report(analysis.Diagnostic{ - Pos: firstArg.Pos(), - End: lastArg.End(), - Category: DiagnosticCategory, - Message: "odd number of arguments passed as key-value pairs for logging", - }) - } - - if cfg.RequireStringKey { - c.CheckLoggingKey(pass, keyValuesArgs) - } - - if cfg.NoPrintfLike { - // Check all args - c.CheckPrintfLikeSpecifier(pass, call.Expr.Args) - } -} diff --git a/vendor/github.com/timonwong/loggercheck/internal/checkers/common.go b/vendor/github.com/timonwong/loggercheck/internal/checkers/common.go deleted file mode 100644 index 977f5d70c..000000000 --- a/vendor/github.com/timonwong/loggercheck/internal/checkers/common.go +++ /dev/null @@ -1,46 +0,0 @@ -package checkers - -import ( - "go/ast" - "go/constant" - "go/printer" - "go/token" - "go/types" - "strings" - "unicode/utf8" - - "golang.org/x/tools/go/analysis" -) - -const ( - DiagnosticCategory = "logging" -) - -// extractValueFromStringArg returns true if the argument is a string type (literal or constant). -func extractValueFromStringArg(pass *analysis.Pass, arg ast.Expr) (value string, ok bool) { - if typeAndValue, ok := pass.TypesInfo.Types[arg]; ok { - if typ, ok := typeAndValue.Type.(*types.Basic); ok && typ.Kind() == types.String && typeAndValue.Value != nil { - return constant.StringVal(typeAndValue.Value), true - } - } - - return "", false -} - -func renderNodeEllipsis(fset *token.FileSet, v interface{}) string { - const maxLen = 20 - - buf := &strings.Builder{} - _ = printer.Fprint(buf, fset, v) - s := buf.String() - if utf8.RuneCountInString(s) > maxLen { - // Copied from go/constant/value.go - i := 0 - for n := 0; n < maxLen-3; n++ { - _, size := utf8.DecodeRuneInString(s[i:]) - i += size - } - s = s[:i] + "..." - } - return s -} diff --git a/vendor/github.com/timonwong/loggercheck/internal/checkers/filter.go b/vendor/github.com/timonwong/loggercheck/internal/checkers/filter.go deleted file mode 100644 index a09a54f99..000000000 --- a/vendor/github.com/timonwong/loggercheck/internal/checkers/filter.go +++ /dev/null @@ -1,35 +0,0 @@ -package checkers - -import ( - "go/ast" - "go/types" - - "golang.org/x/tools/go/analysis" -) - -func filterKeyAndValues(pass *analysis.Pass, keyAndValues []ast.Expr, objName string) []ast.Expr { - // Check the argument count - filtered := make([]ast.Expr, 0, len(keyAndValues)) - for _, arg := range keyAndValues { - // Skip any object type field we found - switch arg := arg.(type) { - case *ast.CallExpr, *ast.Ident: - typ := types.Unalias(pass.TypesInfo.TypeOf(arg)) - - switch typ := typ.(type) { - case *types.Named: - obj := typ.Obj() - if obj != nil && obj.Name() == objName { - continue - } - - default: - // pass - } - } - - filtered = append(filtered, arg) - } - - return filtered -} diff --git a/vendor/github.com/timonwong/loggercheck/internal/checkers/general.go b/vendor/github.com/timonwong/loggercheck/internal/checkers/general.go deleted file mode 100644 index 6512cce30..000000000 --- a/vendor/github.com/timonwong/loggercheck/internal/checkers/general.go +++ /dev/null @@ -1,68 +0,0 @@ -package checkers - -import ( - "fmt" - "go/ast" - - "golang.org/x/tools/go/analysis" - - "github.com/timonwong/loggercheck/internal/checkers/printf" - "github.com/timonwong/loggercheck/internal/stringutil" -) - -type General struct{} - -func (g General) FilterKeyAndValues(_ *analysis.Pass, keyAndValues []ast.Expr) []ast.Expr { - return keyAndValues -} - -func (g General) CheckLoggingKey(pass *analysis.Pass, keyAndValues []ast.Expr) { - for i := 0; i < len(keyAndValues); i += 2 { - arg := keyAndValues[i] - if value, ok := extractValueFromStringArg(pass, arg); ok { - if stringutil.IsASCII(value) { - continue - } - - pass.Report(analysis.Diagnostic{ - Pos: arg.Pos(), - End: arg.End(), - Category: DiagnosticCategory, - Message: fmt.Sprintf( - "logging keys are expected to be alphanumeric strings, please remove any non-latin characters from %q", - value), - }) - } else { - pass.Report(analysis.Diagnostic{ - Pos: arg.Pos(), - End: arg.End(), - Category: DiagnosticCategory, - Message: fmt.Sprintf( - "logging keys are expected to be inlined constant strings, please replace %q provided with string", - renderNodeEllipsis(pass.Fset, arg)), - }) - } - } -} - -func (g General) CheckPrintfLikeSpecifier(pass *analysis.Pass, args []ast.Expr) { - for _, arg := range args { - format, ok := extractValueFromStringArg(pass, arg) - if !ok { - continue - } - - if specifier, ok := printf.IsPrintfLike(format); ok { - pass.Report(analysis.Diagnostic{ - Pos: arg.Pos(), - End: arg.End(), - Category: DiagnosticCategory, - Message: fmt.Sprintf("logging message should not use format specifier %q", specifier), - }) - - return // One error diagnostic is enough - } - } -} - -var _ Checker = (*General)(nil) diff --git a/vendor/github.com/timonwong/loggercheck/internal/checkers/printf/printf.go b/vendor/github.com/timonwong/loggercheck/internal/checkers/printf/printf.go deleted file mode 100644 index 926b57e04..000000000 --- a/vendor/github.com/timonwong/loggercheck/internal/checkers/printf/printf.go +++ /dev/null @@ -1,252 +0,0 @@ -package printf - -import ( - "strconv" - "strings" - "unicode/utf8" -) - -// Copied from golang.org/x/tools -// Copyright 2010 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -type printVerb struct { - verb rune // User may provide verb through Formatter; could be a rune. - flags string // known flags are all ASCII -} - -// Common flag sets for printf verbs. -const ( - noFlag = "" - numFlag = " -+.0" - sharpNumFlag = " -+.0#" - allFlags = " -+.0#" -) - -// printVerbs identifies which flags are known to printf for each verb. -var printVerbs = []printVerb{ - // '-' is a width modifier, always valid. - // '.' is a precision for float, max width for strings. - // '+' is required sign for numbers, Go format for %v. - // '#' is alternate format for several verbs. - // ' ' is spacer for numbers - {'%', noFlag}, - {'b', sharpNumFlag}, - {'c', "-"}, - {'d', numFlag}, - {'e', sharpNumFlag}, - {'E', sharpNumFlag}, - {'f', sharpNumFlag}, - {'F', sharpNumFlag}, - {'g', sharpNumFlag}, - {'G', sharpNumFlag}, - {'o', sharpNumFlag}, - {'O', sharpNumFlag}, - {'p', "-#"}, - {'q', " -+.0#"}, - {'s', " -+.0"}, - {'t', "-"}, - {'T', "-"}, - {'U', "-#"}, - {'v', allFlags}, - {'w', allFlags}, - {'x', sharpNumFlag}, - {'X', sharpNumFlag}, -} - -// formatState holds the parsed representation of a printf directive such as "%3.*[4]d". -// It is constructed by parsePrintfVerb. -type formatState struct { - verb rune // the format verb: 'd' for "%d" - format string // the full format directive from % through verb, "%.3d". - flags []byte // the list of # + etc. - // Used only during parse. - hasIndex bool // Whether the argument is indexed. - indexPending bool // Whether we have an indexed argument that has not resolved. - nbytes int // number of bytes of the format string consumed. -} - -// parseFlags accepts any printf flags. -func (s *formatState) parseFlags() { - for s.nbytes < len(s.format) { - switch c := s.format[s.nbytes]; c { - case '#', '0', '+', '-', ' ': - s.flags = append(s.flags, c) - s.nbytes++ - default: - return - } - } -} - -// scanNum advances through a decimal number if present. -func (s *formatState) scanNum() { - for ; s.nbytes < len(s.format); s.nbytes++ { - c := s.format[s.nbytes] - if c < '0' || '9' < c { - return - } - } -} - -func stringIndexAt(s, substr string, start int) int { - idx := strings.Index(s[start:], substr) - if idx < 0 { - return idx - } - return idx + start -} - -// parseIndex scans an index expression. It returns false if there is a syntax error. -func (s *formatState) parseIndex() bool { - if s.nbytes == len(s.format) || s.format[s.nbytes] != '[' { - return true - } - // Argument index present. - s.nbytes++ // skip '[' - start := s.nbytes - s.scanNum() - ok := true - if s.nbytes == len(s.format) || s.nbytes == start || s.format[s.nbytes] != ']' { - ok = false - s.nbytes = stringIndexAt(s.format, "]", start) - if s.nbytes < 0 { - return false - } - } - arg32, err := strconv.ParseInt(s.format[start:s.nbytes], 10, 32) - if err != nil || !ok || arg32 <= 0 { - return false - } - s.nbytes++ // skip ']' - s.hasIndex = true - s.indexPending = true - return true -} - -// parseNum scans a width or precision (or *). -func (s *formatState) parseNum() { - if s.nbytes < len(s.format) && s.format[s.nbytes] == '*' { - if s.indexPending { // Absorb it. - s.indexPending = false - } - s.nbytes++ - } else { - s.scanNum() - } -} - -// parsePrecision scans for a precision. It returns false if there's a bad index expression. -func (s *formatState) parsePrecision() bool { - // If there's a period, there may be a precision. - if s.nbytes < len(s.format) && s.format[s.nbytes] == '.' { - s.flags = append(s.flags, '.') // Treat precision as a flag. - s.nbytes++ - if !s.parseIndex() { - return false - } - s.parseNum() - } - return true -} - -// parsePrintfVerb looks the formatting directive that begins the format string -// and returns a formatState that encodes what the directive wants, without looking -// at the actual arguments present in the call. The result is nil if there is an error. -func parsePrintfVerb(format string) *formatState { - state := &formatState{ - format: format, - flags: make([]byte, 0, 5), //nolint:mnd - nbytes: 1, // There's guaranteed to be a percent sign. - } - - // There may be flags. - state.parseFlags() - // There may be an index. - if !state.parseIndex() { - return nil - } - // There may be a width. - state.parseNum() - // There may be a precision. - if !state.parsePrecision() { - return nil - } - // Now a verb, possibly prefixed by an index (which we may already have). - if !state.indexPending && !state.parseIndex() { - return nil - } - if state.nbytes == len(state.format) { - // missing verb at end of string - return nil - } - verb, w := utf8.DecodeRuneInString(state.format[state.nbytes:]) - state.verb = verb - state.nbytes += w - state.format = state.format[:state.nbytes] - return state -} - -func containsAll(s string, pattern []byte) bool { - for _, c := range pattern { - if !strings.ContainsRune(s, rune(c)) { - return false - } - } - return true -} - -func isPrintfArg(state *formatState) bool { - var v printVerb - found := false - // Linear scan is fast enough for a small list. - for _, v = range printVerbs { - if v.verb == state.verb { - found = true - break - } - } - - if !found { - // unknown verb, just skip - return false - } - - if !containsAll(v.flags, state.flags) { - // unrecognized format flag, just skip - return false - } - - return true -} - -func IsPrintfLike(format string) (firstSpecifier string, ok bool) { - if !strings.Contains(format, "%") { - return "", false - } - - for i, w := 0, 0; i < len(format); i += w { - w = 1 - if format[i] != '%' { - continue - } - - state := parsePrintfVerb(format[i:]) - if state == nil { - return "", false - } - - w = len(state.format) - if !isPrintfArg(state) { - return "", false - } - - if !ok { - firstSpecifier = state.format - ok = true - } - } - - return -} diff --git a/vendor/github.com/timonwong/loggercheck/internal/checkers/slog.go b/vendor/github.com/timonwong/loggercheck/internal/checkers/slog.go deleted file mode 100644 index 5812e6660..000000000 --- a/vendor/github.com/timonwong/loggercheck/internal/checkers/slog.go +++ /dev/null @@ -1,19 +0,0 @@ -package checkers - -import ( - "go/ast" - - "golang.org/x/tools/go/analysis" -) - -type Slog struct { - General -} - -func (z Slog) FilterKeyAndValues(pass *analysis.Pass, keyAndValues []ast.Expr) []ast.Expr { - // check slog.Group() constructed group slog.Attr - // since we also check `slog.Group` so it is OK skip here - return filterKeyAndValues(pass, keyAndValues, "Attr") -} - -var _ Checker = (*Slog)(nil) diff --git a/vendor/github.com/timonwong/loggercheck/internal/checkers/zap.go b/vendor/github.com/timonwong/loggercheck/internal/checkers/zap.go deleted file mode 100644 index 4dac21f78..000000000 --- a/vendor/github.com/timonwong/loggercheck/internal/checkers/zap.go +++ /dev/null @@ -1,21 +0,0 @@ -package checkers - -import ( - "go/ast" - - "golang.org/x/tools/go/analysis" -) - -type Zap struct { - General -} - -func (z Zap) FilterKeyAndValues(pass *analysis.Pass, keyAndValues []ast.Expr) []ast.Expr { - // Skip any zapcore.Field we found - // This is a strongly-typed field. Consume it and move on. - // Actually it's go.uber.org/zap/zapcore.Field, however for simplicity - // we don't check the import path - return filterKeyAndValues(pass, keyAndValues, "Field") -} - -var _ Checker = (*Zap)(nil) diff --git a/vendor/github.com/timonwong/loggercheck/internal/rules/rules.go b/vendor/github.com/timonwong/loggercheck/internal/rules/rules.go deleted file mode 100644 index 3ed69b5bd..000000000 --- a/vendor/github.com/timonwong/loggercheck/internal/rules/rules.go +++ /dev/null @@ -1,198 +0,0 @@ -package rules - -import ( - "bufio" - "errors" - "fmt" - "go/types" - "io" - "strings" -) - -var ErrInvalidRule = errors.New("invalid rule format") - -const CustomRulesetName = "custom" - -type Ruleset struct { - Name string - PackageImport string - Rules []FuncRule - - ruleIndicesByFuncName map[string][]int -} - -func (rs *Ruleset) Match(fn *types.Func) bool { - // PackageImport is already checked (by indices), skip checking it here - sig := fn.Type().(*types.Signature) // it's safe since we already checked - - // Fail fast if the function name is not in the rule list. - indices, ok := rs.ruleIndicesByFuncName[fn.Name()] - if !ok { - return false - } - - for _, idx := range indices { - rule := &rs.Rules[idx] - if matchRule(rule, sig) { - return true - } - } - - return false -} - -func receiverTypeOf(recvType types.Type) string { - buf := &strings.Builder{} - - var recvNamed *types.Named - switch recvType := recvType.(type) { - case *types.Pointer: - buf.WriteByte('*') - if elem, ok := recvType.Elem().(*types.Named); ok { - recvNamed = elem - } - case *types.Named: - recvNamed = recvType - } - - if recvNamed == nil { - // not supported type - return "" - } - - buf.WriteString(recvNamed.Obj().Name()) - typeParams := recvNamed.TypeParams() - if typeParamsLen := typeParams.Len(); typeParamsLen > 0 { - buf.WriteByte('[') - for i := 0; i < typeParamsLen; i++ { - if i > 0 { - // comma as separator - buf.WriteByte(',') - } - p := typeParams.At(i) - buf.WriteString(p.Obj().Name()) - } - buf.WriteByte(']') - } - - return buf.String() -} - -func matchRule(p *FuncRule, sig *types.Signature) bool { - // we do not check package import here since it's already checked in Match() - recv := sig.Recv() - isReceiver := recv != nil - if isReceiver != p.IsReceiver { - return false - } - - if isReceiver { - recvType := recv.Type() - receiverType := receiverTypeOf(recvType) - if receiverType != p.ReceiverType { - return false - } - } - - return true -} - -type FuncRule struct { // package import should be accessed from Rulset - ReceiverType string - FuncName string - IsReceiver bool -} - -func ParseFuncRule(rule string) (packageImport string, pat FuncRule, err error) { - lastDot := strings.LastIndexFunc(rule, func(r rune) bool { - return r == '.' || r == '/' - }) - if lastDot == -1 || rule[lastDot] == '/' { - return "", pat, ErrInvalidRule - } - - importOrReceiver := rule[:lastDot] - pat.FuncName = rule[lastDot+1:] - - if strings.HasPrefix(rule, "(") { // package - if !strings.HasSuffix(importOrReceiver, ")") { - return "", FuncRule{}, ErrInvalidRule - } - - var isPointerReceiver bool - pat.IsReceiver = true - receiver := importOrReceiver[1 : len(importOrReceiver)-1] - if strings.HasPrefix(receiver, "*") { - isPointerReceiver = true - receiver = receiver[1:] - } - - typeDotIdx := strings.LastIndexFunc(receiver, func(r rune) bool { - return r == '.' || r == '/' - }) - if typeDotIdx == -1 || receiver[typeDotIdx] == '/' { - return "", FuncRule{}, ErrInvalidRule - } - receiverType := receiver[typeDotIdx+1:] - if isPointerReceiver { - receiverType = "*" + receiverType - } - pat.ReceiverType = receiverType - packageImport = receiver[:typeDotIdx] - } else { - packageImport = importOrReceiver - } - - return packageImport, pat, nil -} - -func ParseRules(lines []string) (result []Ruleset, err error) { - rulesByImport := make(map[string][]FuncRule) - for i, line := range lines { - if line == "" { - continue - } - - if strings.HasPrefix(line, "#") { // comments - continue - } - - packageImport, pat, err := ParseFuncRule(line) - if err != nil { - return nil, fmt.Errorf("error parse rule at line %d: %w", i+1, err) - } - rulesByImport[packageImport] = append(rulesByImport[packageImport], pat) - } - - for packageImport, rules := range rulesByImport { - ruleIndicesByFuncName := make(map[string][]int, len(rules)) - for idx, rule := range rules { - fnName := rule.FuncName - ruleIndicesByFuncName[fnName] = append(ruleIndicesByFuncName[fnName], idx) - } - - result = append(result, Ruleset{ - Name: CustomRulesetName, // NOTE(timonwong) Always "custom" for custom rule - PackageImport: packageImport, - Rules: rules, - ruleIndicesByFuncName: ruleIndicesByFuncName, - }) - } - return result, nil -} - -func ParseRuleFile(r io.Reader) (result []Ruleset, err error) { - // Rule files are relatively small, so read it into string slice first. - var lines []string - - scanner := bufio.NewScanner(r) - for scanner.Scan() { - line := strings.TrimSpace(scanner.Text()) - lines = append(lines, line) - } - if err := scanner.Err(); err != nil { - return nil, err - } - - return ParseRules(lines) -} diff --git a/vendor/github.com/timonwong/loggercheck/internal/sets/string.go b/vendor/github.com/timonwong/loggercheck/internal/sets/string.go deleted file mode 100644 index daf8d57fc..000000000 --- a/vendor/github.com/timonwong/loggercheck/internal/sets/string.go +++ /dev/null @@ -1,59 +0,0 @@ -package sets - -import ( - "sort" - "strings" -) - -type Empty struct{} - -type StringSet map[string]Empty - -func NewString(items ...string) StringSet { - s := make(StringSet) - s.Insert(items...) - return s -} - -func (s StringSet) Insert(items ...string) { - for _, item := range items { - s[item] = Empty{} - } -} - -func (s StringSet) Has(item string) bool { - _, contained := s[item] - return contained -} - -func (s StringSet) List() []string { - if len(s) == 0 { - return nil - } - - res := make([]string, 0, len(s)) - for key := range s { - res = append(res, key) - } - sort.Strings(res) - return res -} - -// Set implements flag.Value interface. -func (s *StringSet) Set(v string) error { - v = strings.TrimSpace(v) - if v == "" { - *s = nil - return nil - } - - parts := strings.Split(v, ",") - set := NewString(parts...) - *s = set - return nil -} - -// String implements flag.Value interface -func (s StringSet) String() string { - return strings.Join(s.List(), ",") -} diff --git a/vendor/github.com/timonwong/loggercheck/internal/stringutil/is.go b/vendor/github.com/timonwong/loggercheck/internal/stringutil/is.go deleted file mode 100644 index a36b742fc..000000000 --- a/vendor/github.com/timonwong/loggercheck/internal/stringutil/is.go +++ /dev/null @@ -1,15 +0,0 @@ -package stringutil - -import "unicode/utf8" - -// IsASCII returns true if string are ASCII. -func IsASCII(s string) bool { - for _, r := range s { - if r >= utf8.RuneSelf { - // Not ASCII. - return false - } - } - - return true -} -- cgit mrf-deployment