|
| 1 | +package golinters |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | + |
| 6 | + "github.com/kulti/thelper/pkg/analyzer" |
| 7 | + "golang.org/x/tools/go/analysis" |
| 8 | + |
| 9 | + "github.com/golangci/golangci-lint/pkg/config" |
| 10 | + "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" |
| 11 | +) |
| 12 | + |
| 13 | +func NewThelper(cfg *config.ThelperSettings) *goanalysis.Linter { |
| 14 | + a := analyzer.NewAnalyzer() |
| 15 | + |
| 16 | + cfgMap := map[string]map[string]interface{}{} |
| 17 | + if cfg != nil { |
| 18 | + var opts []string |
| 19 | + |
| 20 | + if cfg.Test.Name { |
| 21 | + opts = append(opts, "t_name") |
| 22 | + } |
| 23 | + if cfg.Test.Begin { |
| 24 | + opts = append(opts, "t_begin") |
| 25 | + } |
| 26 | + if cfg.Test.First { |
| 27 | + opts = append(opts, "t_first") |
| 28 | + } |
| 29 | + |
| 30 | + if cfg.Benchmark.Name { |
| 31 | + opts = append(opts, "b_name") |
| 32 | + } |
| 33 | + if cfg.Benchmark.Begin { |
| 34 | + opts = append(opts, "b_begin") |
| 35 | + } |
| 36 | + if cfg.Benchmark.First { |
| 37 | + opts = append(opts, "b_first") |
| 38 | + } |
| 39 | + |
| 40 | + cfgMap[a.Name] = map[string]interface{}{ |
| 41 | + "checks": strings.Join(opts, ","), |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + return goanalysis.NewLinter( |
| 46 | + "thelper", |
| 47 | + "thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers", |
| 48 | + []*analysis.Analyzer{a}, |
| 49 | + cfgMap, |
| 50 | + ).WithLoadMode(goanalysis.LoadModeTypesInfo) |
| 51 | +} |
0 commit comments