forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinvalid_issue.go
63 lines (46 loc) · 1.34 KB
/
invalid_issue.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
60
61
62
63
package processors
import (
"path/filepath"
"github.com/golangci/golangci-lint/pkg/logutils"
"github.com/golangci/golangci-lint/pkg/result"
)
var _ Processor = (*InvalidIssue)(nil)
// InvalidIssue filters invalid reports.
// - non-go files (except `go.mod`)
// - reports without file path
type InvalidIssue struct {
log logutils.Log
}
func NewInvalidIssue(log logutils.Log) *InvalidIssue {
return &InvalidIssue{log: log}
}
func (InvalidIssue) Name() string {
return "invalid_issue"
}
func (p InvalidIssue) Process(issues []result.Issue) ([]result.Issue, error) {
tcIssues := filterIssuesUnsafe(issues, func(issue *result.Issue) bool {
return issue.FromLinter == typeCheckName
})
if len(tcIssues) > 0 {
return tcIssues, nil
}
return filterIssuesErr(issues, p.shouldPassIssue)
}
func (InvalidIssue) Finish() {}
func (p InvalidIssue) shouldPassIssue(issue *result.Issue) (bool, error) {
if issue.FilePath() == "" {
p.log.Warnf("no file path for the issue: probably a bug inside the linter %q: %#v", issue.FromLinter, issue)
return false, nil
}
if filepath.Base(issue.FilePath()) == "go.mod" {
return true, nil
}
if !isGoFile(issue.FilePath()) {
p.log.Infof("issue related to file %s is skipped", issue.FilePath())
return false, nil
}
return true, nil
}
func isGoFile(name string) bool {
return filepath.Ext(name) == ".go"
}