github.com/alecthomas/golangci-lint@v1.4.2-0.20180609094924-581a3564ff68/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 in go programs. These unchecked errors can be critical bugs in some cases" 20 } 21 22 func (e Errcheck) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) { 23 errCfg := &lintCtx.Settings().Errcheck 24 issues, err := errcheckAPI.Run(lintCtx.Program, errCfg.CheckAssignToBlank, errCfg.CheckTypeAssertions) 25 if err != nil { 26 return nil, err 27 } 28 29 if len(issues) == 0 { 30 return nil, nil 31 } 32 33 res := make([]result.Issue, 0, len(issues)) 34 for _, i := range issues { 35 var text string 36 if i.FuncName != "" { 37 text = fmt.Sprintf("Error return value of %s is not checked", formatCode(i.FuncName, lintCtx.Cfg)) 38 } else { 39 text = "Error return value is not checked" 40 } 41 res = append(res, result.Issue{ 42 FromLinter: e.Name(), 43 Text: text, 44 Pos: i.Pos, 45 }) 46 } 47 48 return res, nil 49 }