forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 2
/
unconvert.go
37 lines (29 loc) · 779 Bytes
/
unconvert.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
package golinters
import (
"context"
"github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/result"
unconvertAPI "github.com/golangci/unconvert"
)
type Unconvert struct{}
func (Unconvert) Name() string {
return "unconvert"
}
func (Unconvert) Desc() string {
return "Remove unnecessary type conversions"
}
func (lint Unconvert) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) {
positions := unconvertAPI.Run(lintCtx.Program)
if len(positions) == 0 {
return nil, nil
}
res := make([]result.Issue, 0, len(positions))
for _, pos := range positions {
res = append(res, result.Issue{
Pos: pos,
Text: "unnecessary conversion",
FromLinter: lint.Name(),
})
}
return res, nil
}