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