@@ -3,7 +3,6 @@ package processors
33import (
44 "go/parser"
55 "go/token"
6- "path/filepath"
76 "strings"
87 "sync"
98 "time"
@@ -23,9 +22,11 @@ type adjustMap struct {
2322 m map [string ]posMapper
2423}
2524
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.
2930type FilenameUnadjuster struct {
3031 m map [string ]posMapper // map from adjusted filename to position mapper: adjusted -> unadjusted position
3132 log logutils.Log
@@ -36,16 +37,20 @@ func NewFilenameUnadjuster(pkgs []*packages.Package, log logutils.Log) *Filename
3637 m := adjustMap {m : map [string ]posMapper {}}
3738
3839 startedAt := time .Now ()
40+
3941 var wg sync.WaitGroup
4042 wg .Add (len (pkgs ))
43+
4144 for _ , pkg := range pkgs {
4245 go func (pkg * packages.Package ) {
4346 // It's important to call func here to run GC
4447 processUnadjusterPkg (& m , pkg , log )
4548 wg .Done ()
4649 }(pkg )
4750 }
51+
4852 wg .Wait ()
53+
4954 log .Infof ("Pre-built %d adjustments in %s" , len (m .m ), time .Since (startedAt ))
5055
5156 return & FilenameUnadjuster {
@@ -61,17 +66,7 @@ func (*FilenameUnadjuster) Name() string {
6166
6267func (p * FilenameUnadjuster ) Process (issues []result.Issue ) ([]result.Issue , error ) {
6368 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 ()]
7570 if mapper == nil {
7671 return issue
7772 }
0 commit comments