forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgo.go
59 lines (45 loc) · 1.3 KB
/
cgo.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
51
52
53
54
55
56
57
58
59
package processors
import (
"fmt"
"path/filepath"
"strings"
"github.com/nalekseevs/itns-golangci-lint/pkg/goutil"
"github.com/nalekseevs/itns-golangci-lint/pkg/result"
)
var _ Processor = (*Cgo)(nil)
type Cgo struct {
goCacheDir string
}
func NewCgo(goenv *goutil.Env) *Cgo {
return &Cgo{
goCacheDir: goenv.Get(goutil.EnvGoCache),
}
}
func (Cgo) Name() string {
return "cgo"
}
func (p Cgo) Process(issues []result.Issue) ([]result.Issue, error) {
return filterIssuesErr(issues, p.shouldPassIssue)
}
func (Cgo) Finish() {}
func (p Cgo) shouldPassIssue(issue *result.Issue) (bool, error) {
// some linters (e.g. gosec, deadcode) return incorrect filepaths for cgo issues,
// also cgo files have strange issues looking like false positives.
// cache dir contains all preprocessed files including cgo files
issueFilePath := issue.FilePath()
if !filepath.IsAbs(issue.FilePath()) {
absPath, err := filepath.Abs(issue.FilePath())
if err != nil {
return false, fmt.Errorf("failed to build abs path for %q: %w", issue.FilePath(), err)
}
issueFilePath = absPath
}
if p.goCacheDir != "" && strings.HasPrefix(issueFilePath, p.goCacheDir) {
return false, nil
}
if filepath.Base(issue.FilePath()) == "_cgo_gotypes.go" {
// skip cgo warning for go1.10
return false, nil
}
return true, nil
}