@@ -2,12 +2,7 @@ package golinters
2
2
3
3
import (
4
4
"context"
5
- "fmt"
6
- "go/token"
7
- "strconv"
8
- "strings"
9
5
10
- "github.com/pkg/errors"
11
6
"golang.org/x/tools/go/packages"
12
7
13
8
"github.com/golangci/golangci-lint/pkg/lint/linter"
@@ -26,44 +21,31 @@ func (TypeCheck) Desc() string {
26
21
}
27
22
28
23
func (lint TypeCheck ) parseError (srcErr packages.Error ) (* result.Issue , error ) {
29
- // file:line(<optional>:colon)
30
- parts := strings .Split (srcErr .Pos , ":" )
31
- if len (parts ) == 1 {
32
- return nil , errors .New ("no colons" )
33
- }
34
-
35
- file := parts [0 ]
36
- line , err := strconv .Atoi (parts [1 ])
24
+ pos , err := libpackages .ParseErrorPosition (srcErr .Pos )
37
25
if err != nil {
38
- return nil , fmt .Errorf ("can't parse line number %q: %s" , parts [1 ], err )
39
- }
40
-
41
- var column int
42
- if len (parts ) == 3 { // no column
43
- column , err = strconv .Atoi (parts [2 ])
44
- if err != nil {
45
- return nil , errors .Wrapf (err , "failed to parse column from %q" , parts [2 ])
46
- }
26
+ return nil , err
47
27
}
48
28
49
29
return & result.Issue {
50
- Pos : token.Position {
51
- Filename : file ,
52
- Line : line ,
53
- Column : column ,
54
- },
30
+ Pos : * pos ,
55
31
Text : srcErr .Msg ,
56
32
FromLinter : lint .Name (),
57
33
}, nil
58
34
}
59
35
60
36
func (lint TypeCheck ) Run (ctx context.Context , lintCtx * linter.Context ) ([]result.Issue , error ) {
37
+ uniqReportedIssues := map [string ]bool {}
38
+
61
39
var res []result.Issue
62
40
for _ , pkg := range lintCtx .NotCompilingPackages {
63
- errors := libpackages .ExtractErrors (pkg )
41
+ errors := libpackages .ExtractErrors (pkg , lintCtx . ASTCache )
64
42
for _ , err := range errors {
65
43
i , perr := lint .parseError (err )
66
44
if perr != nil { // failed to parse
45
+ if uniqReportedIssues [err .Msg ] {
46
+ continue
47
+ }
48
+ uniqReportedIssues [err .Msg ] = true
67
49
lintCtx .Log .Errorf ("typechecking error: %s" , err .Msg )
68
50
} else {
69
51
res = append (res , * i )
0 commit comments