diff --git a/tools/go.mod b/tools/go.mod index 5809f0ee..6590673e 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -3,7 +3,7 @@ module github.com/obalunenko/logger/tools go 1.18 require ( - github.com/golangci/golangci-lint v1.46.1 + github.com/golangci/golangci-lint v1.46.2 github.com/goreleaser/goreleaser v1.9.0 golang.org/x/tools v0.1.11-0.20220316014157-77aa08bb151a gotest.tools/gotestsum v1.8.1 @@ -173,7 +173,7 @@ require ( github.com/ldez/gomoddirectives v0.2.3 // indirect github.com/ldez/tagliatelle v0.3.1 // indirect github.com/leonklingele/grouper v1.1.0 // indirect - github.com/lufeee/execinquery v1.2.0 // indirect + github.com/lufeee/execinquery v1.2.1 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/maratori/testpackage v1.0.1 // indirect github.com/matoous/godox v0.0.0-20210227103229-6504466cf951 // indirect @@ -203,7 +203,7 @@ require ( github.com/phayes/checkstyle v0.0.0-20170904204023-bfd46e6a821d // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/polyfloyd/go-errorlint v0.0.0-20211125173453-6d6d39c5bb8b // indirect + github.com/polyfloyd/go-errorlint v1.0.0 // indirect github.com/prometheus/client_golang v1.12.1 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect diff --git a/tools/go.sum b/tools/go.sum index 30805dcd..91f19f6c 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -540,8 +540,8 @@ github.com/golangci/go-misc v0.0.0-20220329215616-d24fe342adfe h1:6RGUuS7EGotKx6 github.com/golangci/go-misc v0.0.0-20220329215616-d24fe342adfe/go.mod h1:gjqyPShc/m8pEMpk0a3SeagVb0kaqvhscv+i9jI5ZhQ= github.com/golangci/gofmt v0.0.0-20190930125516-244bba706f1a h1:iR3fYXUjHCR97qWS8ch1y9zPNsgXThGwjKPrYfqMPks= github.com/golangci/gofmt v0.0.0-20190930125516-244bba706f1a/go.mod h1:9qCChq59u/eW8im404Q2WWTrnBUQKjpNYKMbU4M7EFU= -github.com/golangci/golangci-lint v1.46.1 h1:sc3XD0pprdZuqZkl6snUfnmUT1XW4dTTyLeOBvxn+3M= -github.com/golangci/golangci-lint v1.46.1/go.mod h1:wX6nN6s18dtWgm5Hjmes0sZKOxi+32KCI+OLVQCyhtM= +github.com/golangci/golangci-lint v1.46.2 h1:o90t/Xa6dhJbvy8Bz2RpzUXqrkigp19DLStMolTZbyo= +github.com/golangci/golangci-lint v1.46.2/go.mod h1:3DkdHnxn9eoTTrpT2gB0TEv8KSziuoqe9FitgQLHvAY= github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0 h1:MfyDlzVjl1hoaPzPD4Gpb/QgoRfSBR0jdhwGyAWwMSA= github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0/go.mod h1:66R6K6P6VWk9I95jvqGxkqJxVWGFy9XlDwLwVz1RCFg= github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca h1:kNY3/svz5T29MYHubXix4aDDuE3RWHkPvopM/EDv/MA= @@ -831,8 +831,8 @@ github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/lufeee/execinquery v1.2.0 h1:07LBuxOFCLoNXUuwnRxL1T+ef8rI0gYZRBe2yh9BflU= -github.com/lufeee/execinquery v1.2.0/go.mod h1:EC7DrEKView09ocscGHC+apXMIaorh4xqSxS/dy8SbM= +github.com/lufeee/execinquery v1.2.1 h1:hf0Ems4SHcUGBxpGN7Jz78z1ppVkP/837ZlETPCEtOM= +github.com/lufeee/execinquery v1.2.1/go.mod h1:EC7DrEKView09ocscGHC+apXMIaorh4xqSxS/dy8SbM= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= @@ -991,8 +991,8 @@ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qR github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polyfloyd/go-errorlint v0.0.0-20211125173453-6d6d39c5bb8b h1:/BDyEJWLnDUYKGWdlNx/82qSaVu2bUok/EvPUtIGuvw= -github.com/polyfloyd/go-errorlint v0.0.0-20211125173453-6d6d39c5bb8b/go.mod h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw= +github.com/polyfloyd/go-errorlint v1.0.0 h1:pDrQG0lrh68e602Wfp68BlUTRFoHn8PZYAjLgt2LFsM= +github.com/polyfloyd/go-errorlint v1.0.0/go.mod h1:KZy4xxPJyy88/gldCe5OdW6OQRtNO3EZE7hXzmnebgA= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= diff --git a/tools/vendor/github.com/golangci/golangci-lint/pkg/config/linters_settings.go b/tools/vendor/github.com/golangci/golangci-lint/pkg/config/linters_settings.go index cb4095d0..3d479517 100644 --- a/tools/vendor/github.com/golangci/golangci-lint/pkg/config/linters_settings.go +++ b/tools/vendor/github.com/golangci/golangci-lint/pkg/config/linters_settings.go @@ -550,26 +550,16 @@ type TestpackageSettings struct { } type ThelperSettings struct { - Test struct { - First bool `mapstructure:"first"` - Name bool `mapstructure:"name"` - Begin bool `mapstructure:"begin"` - } `mapstructure:"test"` - Fuzz struct { - First bool `mapstructure:"first"` - Name bool `mapstructure:"name"` - Begin bool `mapstructure:"begin"` - } `mapstructure:"fuzz"` - Benchmark struct { - First bool `mapstructure:"first"` - Name bool `mapstructure:"name"` - Begin bool `mapstructure:"begin"` - } `mapstructure:"benchmark"` - TB struct { - First bool `mapstructure:"first"` - Name bool `mapstructure:"name"` - Begin bool `mapstructure:"begin"` - } `mapstructure:"tb"` + Test ThelperOptions `mapstructure:"test"` + Fuzz ThelperOptions `mapstructure:"fuzz"` + Benchmark ThelperOptions `mapstructure:"benchmark"` + TB ThelperOptions `mapstructure:"tb"` +} + +type ThelperOptions struct { + First *bool `mapstructure:"first"` + Name *bool `mapstructure:"name"` + Begin *bool `mapstructure:"begin"` } type TenvSettings struct { diff --git a/tools/vendor/github.com/golangci/golangci-lint/pkg/golinters/thelper.go b/tools/vendor/github.com/golangci/golangci-lint/pkg/golinters/thelper.go index 349c4666..41edbe76 100644 --- a/tools/vendor/github.com/golangci/golangci-lint/pkg/golinters/thelper.go +++ b/tools/vendor/github.com/golangci/golangci-lint/pkg/golinters/thelper.go @@ -13,53 +13,44 @@ import ( func NewThelper(cfg *config.ThelperSettings) *goanalysis.Linter { a := analyzer.NewAnalyzer() - cfgMap := map[string]map[string]interface{}{} - if cfg != nil { - var opts []string + opts := map[string]struct{}{ + "t_name": {}, + "t_begin": {}, + "t_first": {}, - if cfg.Test.Name { - opts = append(opts, "t_name") - } - if cfg.Test.Begin { - opts = append(opts, "t_begin") - } - if cfg.Test.First { - opts = append(opts, "t_first") - } + "f_name": {}, + "f_begin": {}, + "f_first": {}, - if cfg.Fuzz.Name { - opts = append(opts, "f_name") - } - if cfg.Fuzz.Begin { - opts = append(opts, "f_begin") - } - if cfg.Fuzz.First { - opts = append(opts, "f_first") - } + "b_name": {}, + "b_begin": {}, + "b_first": {}, - if cfg.Benchmark.Name { - opts = append(opts, "b_name") - } - if cfg.Benchmark.Begin { - opts = append(opts, "b_begin") - } - if cfg.Benchmark.First { - opts = append(opts, "b_first") - } + "tb_name": {}, + "tb_begin": {}, + "tb_first": {}, + } - if cfg.TB.Name { - opts = append(opts, "tb_name") - } - if cfg.TB.Begin { - opts = append(opts, "tb_begin") - } - if cfg.TB.First { - opts = append(opts, "tb_first") - } + if cfg != nil { + applyTHelperOptions(cfg.Test, "t_", opts) + applyTHelperOptions(cfg.Fuzz, "f_", opts) + applyTHelperOptions(cfg.Benchmark, "b_", opts) + applyTHelperOptions(cfg.TB, "tb_", opts) + } - cfgMap[a.Name] = map[string]interface{}{ - "checks": strings.Join(opts, ","), - } + if len(opts) == 0 { + linterLogger.Fatalf("thelper: at least one option must be enabled") + } + + var args []string + for k := range opts { + args = append(args, k) + } + + cfgMap := map[string]map[string]interface{}{ + a.Name: { + "checks": strings.Join(args, ","), + }, } return goanalysis.NewLinter( @@ -69,3 +60,23 @@ func NewThelper(cfg *config.ThelperSettings) *goanalysis.Linter { cfgMap, ).WithLoadMode(goanalysis.LoadModeTypesInfo) } + +func applyTHelperOptions(o config.ThelperOptions, prefix string, opts map[string]struct{}) { + if o.Name != nil { + if !*o.Name { + delete(opts, prefix+"name") + } + } + + if o.Begin != nil { + if !*o.Begin { + delete(opts, prefix+"begin") + } + } + + if o.First != nil { + if !*o.First { + delete(opts, prefix+"first") + } + } +} diff --git a/tools/vendor/github.com/lufeee/execinquery/README.md b/tools/vendor/github.com/lufeee/execinquery/README.md index 05b67e52..38fa7c8b 100644 --- a/tools/vendor/github.com/lufeee/execinquery/README.md +++ b/tools/vendor/github.com/lufeee/execinquery/README.md @@ -1,5 +1,6 @@ # execinquery - a simple query string checker in Query function -[![test-and-lint](https://github.com/lufeee/execinquery/actions/workflows/test-and-lint.yml/badge.svg?branch=main)](https://github.com/lufeee/execinquery/actions/workflows/test-and-lint.yml) +[![Go Matrix](https://github.com/lufeee/execinquery/actions/workflows/go-cross.yml/badge.svg?branch=main)](https://github.com/lufeee/execinquery/actions/workflows/go-cross.yml) +[![Go lint](https://github.com/lufeee/execinquery/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/lufeee/execinquery/actions/workflows/lint.yml) [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) ## About diff --git a/tools/vendor/github.com/lufeee/execinquery/execinquery.go b/tools/vendor/github.com/lufeee/execinquery/execinquery.go index 66836188..c37dc170 100644 --- a/tools/vendor/github.com/lufeee/execinquery/execinquery.go +++ b/tools/vendor/github.com/lufeee/execinquery/execinquery.go @@ -49,6 +49,10 @@ func (l linter) run(pass *analysis.Pass) (interface{}, error) { return } + if pass.TypesInfo == nil || pass.TypesInfo.Uses[selector.Sel] == nil || pass.TypesInfo.Uses[selector.Sel].Pkg() == nil { + return + } + if "database/sql" != pass.TypesInfo.Uses[selector.Sel].Pkg().Path() { return } @@ -60,7 +64,7 @@ func (l linter) run(pass *analysis.Pass) (interface{}, error) { replacement := "Exec" var i int // the index of the query argument if strings.Contains(selector.Sel.Name, "Context") { - replacement = "ExecContext" + replacement += "Context" i = 1 } @@ -116,6 +120,9 @@ func (l linter) getQueryString(exp interface{}) string { return v case *ast.Ident: + if e.Obj == nil { + return "" + } return l.getQueryString(e.Obj.Decl) case *ast.BinaryExpr: diff --git a/tools/vendor/github.com/polyfloyd/go-errorlint/errorlint/allowed.go b/tools/vendor/github.com/polyfloyd/go-errorlint/errorlint/allowed.go index cb8fc642..7fe4c38c 100644 --- a/tools/vendor/github.com/polyfloyd/go-errorlint/errorlint/allowed.go +++ b/tools/vendor/github.com/polyfloyd/go-errorlint/errorlint/allowed.go @@ -168,6 +168,10 @@ func assigningCallExprs(info *TypesInfoExt, subject *ast.Ident) []*ast.CallExpr // Found the function call. callExprs = append(callExprs, assignT) case *ast.Ident: + // Skip assignments here the RHS points to the same object as the subject. + if assignT.Obj == subject.Obj { + continue + } // The subject was the result of assigning from another identifier. callExprs = append(callExprs, assigningCallExprs(info, assignT)...) default: diff --git a/tools/vendor/github.com/polyfloyd/go-errorlint/errorlint/lint.go b/tools/vendor/github.com/polyfloyd/go-errorlint/errorlint/lint.go index 3d239f62..5301a3f2 100644 --- a/tools/vendor/github.com/polyfloyd/go-errorlint/errorlint/lint.go +++ b/tools/vendor/github.com/polyfloyd/go-errorlint/errorlint/lint.go @@ -6,7 +6,6 @@ import ( "go/constant" "go/token" "go/types" - "regexp" ) type Lint struct { @@ -52,7 +51,7 @@ func LintFmtErrorfCalls(fset *token.FileSet, info types.Info) []Lint { continue } - if formatVerbs[i] == "%w" { + if formatVerbs[i] == "w" { lintArg = nil break } @@ -85,6 +84,9 @@ func isErrorStringCall(info types.Info, expr ast.Expr) bool { return false } +// 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. func printfFormatStringVerbs(info types.Info, call *ast.CallExpr) ([]string, bool) { if len(call.Args) <= 1 { return nil, false @@ -96,10 +98,23 @@ func printfFormatStringVerbs(info types.Info, call *ast.CallExpr) ([]string, boo } formatString := constant.StringVal(info.Types[strLit].Value) - // Naive format string argument verb. This does not take modifiers such as - // padding into account... - re := regexp.MustCompile(`%[^%]`) - return re.FindAllString(formatString, -1), true + pp := printfParser{str: formatString} + verbs, err := pp.ParseAllVerbs() + if err != nil { + return nil, false + } + orderedVerbs := verbOrder(verbs, len(call.Args)-1) + + resolvedVerbs := make([]string, len(orderedVerbs)) + for i, vv := range orderedVerbs { + for _, v := range vv { + resolvedVerbs[i] = v.format + if v.format == "w" { + break + } + } + } + return resolvedVerbs, true } func isFmtErrorfCallExpr(info types.Info, expr ast.Expr) (*ast.CallExpr, bool) { diff --git a/tools/vendor/github.com/polyfloyd/go-errorlint/errorlint/printf.go b/tools/vendor/github.com/polyfloyd/go-errorlint/errorlint/printf.go new file mode 100644 index 00000000..b5ecee4f --- /dev/null +++ b/tools/vendor/github.com/polyfloyd/go-errorlint/errorlint/printf.go @@ -0,0 +1,127 @@ +package errorlint + +import ( + "fmt" + "io" + "strconv" + "strings" +) + +func verbOrder(verbs []verb, numArgs int) [][]verb { + orderedVerbs := make([][]verb, numArgs) + i := 0 + for _, v := range verbs { + if v.index != -1 { + i = v.index - 1 + } + orderedVerbs[i] = append(orderedVerbs[i], v) + verbs = verbs[1:] + i++ + } + return orderedVerbs +} + +type verb struct { + format string + index int +} + +type printfParser struct { + str string +} + +func (pp *printfParser) ParseAllVerbs() ([]verb, error) { + verbs := []verb{} + for { + verb, err := pp.parseVerb() + if err == io.EOF { + break + } else if err != nil { + return nil, err + } + verbs = append(verbs, *verb) + } + return verbs, nil +} + +func (pp *printfParser) parseVerb() (*verb, error) { + if err := pp.skipToPercent(); err != nil { + return nil, err + } + if pp.next() != '%' { + return nil, fmt.Errorf("expected '%%'") + } + + index := -1 + switch pp.peek() { + case '%': + pp.next() + return pp.parseVerb() + case '+', '#': + pp.next() + case '[': + var err error + index, err = pp.parseIndex() + if err != nil { + return nil, err + } + case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.': + pp.parsePrecision() + case 0: + return nil, io.EOF + } + + format := pp.next() + + return &verb{format: string(format), index: index}, nil +} + +func (pp *printfParser) parseIndex() (int, error) { + if pp.next() != '[' { + return -1, fmt.Errorf("expected '['") + } + end := strings.Index(pp.str, "]") + if end == -1 { + return -1, fmt.Errorf("unterminated indexed verb") + } + index, err := strconv.Atoi(pp.str[:end]) + if err != nil { + return -1, err + } + pp.str = pp.str[end+1:] + return index, nil +} + +func (pp *printfParser) parsePrecision() { + for { + if r := pp.peek(); (r < '0' || '9' < r) && r != '.' { + break + } + pp.next() + } +} + +func (pp *printfParser) skipToPercent() error { + i := strings.Index(pp.str, "%") + if i == -1 { + return io.EOF + } + pp.str = pp.str[i:] + return nil +} + +func (pp *printfParser) peek() rune { + if len(pp.str) == 0 { + return 0 + } + return rune(pp.str[0]) +} + +func (pp *printfParser) next() rune { + if len(pp.str) == 0 { + return 0 + } + r := rune(pp.str[0]) + pp.str = pp.str[1:] + return r +} diff --git a/tools/vendor/modules.txt b/tools/vendor/modules.txt index 6c64be75..3bbf8196 100644 --- a/tools/vendor/modules.txt +++ b/tools/vendor/modules.txt @@ -541,7 +541,7 @@ github.com/golangci/go-misc/deadcode ## explicit github.com/golangci/gofmt/gofmt github.com/golangci/gofmt/goimports -# github.com/golangci/golangci-lint v1.46.1 +# github.com/golangci/golangci-lint v1.46.2 ## explicit; go 1.18 github.com/golangci/golangci-lint/cmd/golangci-lint github.com/golangci/golangci-lint/internal/cache @@ -844,7 +844,7 @@ github.com/leonklingele/grouper/pkg/analyzer/globals github.com/leonklingele/grouper/pkg/analyzer/imports github.com/leonklingele/grouper/pkg/analyzer/types github.com/leonklingele/grouper/pkg/analyzer/vars -# github.com/lufeee/execinquery v1.2.0 +# github.com/lufeee/execinquery v1.2.1 ## explicit; go 1.17 github.com/lufeee/execinquery # github.com/magiconair/properties v1.8.6 @@ -950,7 +950,7 @@ github.com/pkg/errors # github.com/pmezard/go-difflib v1.0.0 ## explicit github.com/pmezard/go-difflib/difflib -# github.com/polyfloyd/go-errorlint v0.0.0-20211125173453-6d6d39c5bb8b +# github.com/polyfloyd/go-errorlint v1.0.0 ## explicit; go 1.13 github.com/polyfloyd/go-errorlint/errorlint # github.com/prometheus/client_golang v1.12.1