Skip to content

Commit 7278b7a

Browse files
committed
setup typecheck error file if it's empty
1 parent 27752e8 commit 7278b7a

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

pkg/packages/util.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ func ExtractErrors(pkg *packages.Package) []packages.Error {
3131
}
3232
}
3333

34+
// some errors like "code in directory expects import" don't have Pos, set it here
35+
if len(pkg.GoFiles) != 0 {
36+
for i := range uniqErrors {
37+
err := &uniqErrors[i]
38+
if err.Pos == "" {
39+
err.Pos = fmt.Sprintf("%s:1", pkg.GoFiles[0])
40+
}
41+
}
42+
}
43+
3444
return uniqErrors
3545
}
3646

pkg/result/processors/autogenerated_exclude.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ func (p *AutogeneratedExclude) getOrCreateFileSummary(i *result.Issue) (*ageFile
8383
fs = &ageFileSummary{}
8484
p.fileSummaryCache[i.FilePath()] = fs
8585

86+
if i.FilePath() == "" {
87+
return nil, fmt.Errorf("no file path for issue")
88+
}
89+
8690
f := p.astCache.GetOrParse(i.FilePath(), nil)
8791
if f.Err != nil {
8892
return nil, fmt.Errorf("can't parse file %s: %s", i.FilePath(), f.Err)

pkg/result/processors/nolint.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ func (p *Nolint) getOrCreateFileData(i *result.Issue) (*fileData, error) {
8383
fd = &fileData{}
8484
p.cache[i.FilePath()] = fd
8585

86+
if i.FilePath() == "" {
87+
return nil, fmt.Errorf("no file path for issue")
88+
}
89+
8690
file := p.astCache.GetOrParse(i.FilePath(), nil)
8791
if file.Err != nil {
8892
return nil, fmt.Errorf("can't parse file %s: %s", i.FilePath(), file.Err)

0 commit comments

Comments
 (0)