www.github.com/golangci/golangci-lint.git@v1.10.1/pkg/golinters/errcheck.go (about) 1 package golinters 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/golangci/golangci-lint/pkg/lint/linter" 8 "github.com/golangci/golangci-lint/pkg/result" 9 errcheckAPI "github.com/kisielk/errcheck/golangci" 10 ) 11 12 type Errcheck struct{} 13 14 func (Errcheck) Name() string { 15 return "errcheck" 16 } 17 18 func (Errcheck) Desc() string { 19 return "Errcheck is a program for checking for unchecked errors " + 20 "in go programs. These unchecked errors can be critical bugs in some cases" 21 } 22 23 func (e Errcheck) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) { 24 errCfg := &lintCtx.Settings().Errcheck 25 issues, err := errcheckAPI.Run(lintCtx.Program, errCfg.CheckAssignToBlank, errCfg.CheckTypeAssertions) 26 if err != nil { 27 return nil, err 28 } 29 30 if len(issues) == 0 { 31 return nil, nil 32 } 33 34 res := make([]result.Issue, 0, len(issues)) 35 for _, i := range issues { 36 var text string 37 if i.FuncName != "" { 38 text = fmt.Sprintf("Error return value of %s is not checked", formatCode(i.FuncName, lintCtx.Cfg)) 39 } else { 40 text = "Error return value is not checked" 41 } 42 res = append(res, result.Issue{ 43 FromLinter: e.Name(), 44 Text: text, 45 Pos: i.Pos, 46 }) 47 } 48 49 return res, nil 50 }