@@ -3,7 +3,6 @@ package processors
3
3
import (
4
4
"go/parser"
5
5
"go/token"
6
- "path/filepath"
7
6
"strings"
8
7
"sync"
9
8
"time"
@@ -23,9 +22,11 @@ type adjustMap struct {
23
22
m map [string ]posMapper
24
23
}
25
24
26
- // FilenameUnadjuster is needed because a lot of linters use fset.Position(f.Pos())
27
- // to get filename. And they return adjusted filename (e.g. *.qtpl) for an issue. We need
28
- // restore real .go filename to properly output it, parse it, etc.
25
+ // FilenameUnadjuster is needed because a lot of linters use `fset.Position(f.Pos())` to get filename.
26
+ // And they return adjusted filename (e.g.` *.qtpl`) for an issue.
27
+ // We need restore real `.go` filename to properly output it, parse it, etc.
28
+ //
29
+ // Require absolute filepath.
29
30
type FilenameUnadjuster struct {
30
31
m map [string ]posMapper // map from adjusted filename to position mapper: adjusted -> unadjusted position
31
32
log logutils.Log
@@ -36,16 +37,20 @@ func NewFilenameUnadjuster(pkgs []*packages.Package, log logutils.Log) *Filename
36
37
m := adjustMap {m : map [string ]posMapper {}}
37
38
38
39
startedAt := time .Now ()
40
+
39
41
var wg sync.WaitGroup
40
42
wg .Add (len (pkgs ))
43
+
41
44
for _ , pkg := range pkgs {
42
45
go func (pkg * packages.Package ) {
43
46
// It's important to call func here to run GC
44
47
processUnadjusterPkg (& m , pkg , log )
45
48
wg .Done ()
46
49
}(pkg )
47
50
}
51
+
48
52
wg .Wait ()
53
+
49
54
log .Infof ("Pre-built %d adjustments in %s" , len (m .m ), time .Since (startedAt ))
50
55
51
56
return & FilenameUnadjuster {
@@ -61,17 +66,7 @@ func (*FilenameUnadjuster) Name() string {
61
66
62
67
func (p * FilenameUnadjuster ) Process (issues []result.Issue ) ([]result.Issue , error ) {
63
68
return transformIssues (issues , func (issue * result.Issue ) * result.Issue {
64
- issueFilePath := issue .FilePath ()
65
- if ! filepath .IsAbs (issue .FilePath ()) {
66
- absPath , err := filepath .Abs (issue .FilePath ())
67
- if err != nil {
68
- p .log .Warnf ("failed to build abs path for %q: %s" , issue .FilePath (), err )
69
- return issue
70
- }
71
- issueFilePath = absPath
72
- }
73
-
74
- mapper := p .m [issueFilePath ]
69
+ mapper := p .m [issue .FilePath ()]
75
70
if mapper == nil {
76
71
return issue
77
72
}
0 commit comments