www.github.com/golangci/golangci-lint.git@v1.10.1/pkg/golinters/varcheck.go (about) 1 package golinters // nolint:dupl 2 3 import ( 4 "context" 5 "fmt" 6 7 varcheckAPI "github.com/golangci/check/cmd/varcheck" 8 "github.com/golangci/golangci-lint/pkg/lint/linter" 9 "github.com/golangci/golangci-lint/pkg/result" 10 ) 11 12 type Varcheck struct{} 13 14 func (Varcheck) Name() string { 15 return "varcheck" 16 } 17 18 func (Varcheck) Desc() string { 19 return "Finds unused global variables and constants" 20 } 21 22 func (v Varcheck) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) { 23 issues := varcheckAPI.Run(lintCtx.Program, lintCtx.Settings().Varcheck.CheckExportedFields) 24 if len(issues) == 0 { 25 return nil, nil 26 } 27 28 res := make([]result.Issue, 0, len(issues)) 29 for _, i := range issues { 30 res = append(res, result.Issue{ 31 Pos: i.Pos, 32 Text: fmt.Sprintf("%s is unused", formatCode(i.VarName, lintCtx.Cfg)), 33 FromLinter: v.Name(), 34 }) 35 } 36 return res, nil 37 }