Skip to content

Commit b09af54

Browse files
committed
Fix linting of goyacc files
Skip yacctab, yaccpar and NONE files. Relates: #467, #468
1 parent ed0b551 commit b09af54

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

pkg/result/processors/autogenerated_exclude.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"go/ast"
66
"go/token"
7+
"path/filepath"
78
"strings"
89

910
"github.com/golangci/golangci-lint/pkg/lint/astcache"
@@ -41,12 +42,22 @@ func (p *AutogeneratedExclude) Process(issues []result.Issue) ([]result.Issue, e
4142
return filterIssuesErr(issues, p.shouldPassIssue)
4243
}
4344

45+
func isSpecialAutogeneratedFile(filePath string) bool {
46+
fileName := filepath.Base(filePath)
47+
// fake files to which //line points to for goyacc generated files
48+
return fileName == "yacctab" || fileName == "yaccpar" || fileName == "NONE"
49+
}
50+
4451
func (p *AutogeneratedExclude) shouldPassIssue(i *result.Issue) (bool, error) {
4552
if i.FromLinter == "typecheck" {
4653
// don't hide typechecking errors in generated files: users expect to see why the project isn't compiling
4754
return true, nil
4855
}
4956

57+
if isSpecialAutogeneratedFile(i.FilePath()) {
58+
return false, nil
59+
}
60+
5061
fs, err := p.getOrCreateFileSummary(i)
5162
if err != nil {
5263
return false, err

pkg/result/processors/filename_unadjuster.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ type posMapper func(pos token.Position) token.Position
1818
// to get filename. And they return adjusted filename (e.g. *.qtpl) for an issue. We need
1919
// restore real .go filename to properly output it, parse it, etc.
2020
type FilenameUnadjuster struct {
21-
m map[string]posMapper // map from adjusted filename to position mapper: adjusted -> unadjusted position
22-
log logutils.Log
21+
m map[string]posMapper // map from adjusted filename to position mapper: adjusted -> unadjusted position
22+
log logutils.Log
23+
loggedUnadjustments map[string]bool
2324
}
2425

25-
var _ Processor = FilenameUnadjuster{}
26+
var _ Processor = &FilenameUnadjuster{}
2627

2728
func NewFilenameUnadjuster(cache *astcache.Cache, log logutils.Log) *FilenameUnadjuster {
2829
m := map[string]posMapper{}
@@ -51,16 +52,17 @@ func NewFilenameUnadjuster(cache *astcache.Cache, log logutils.Log) *FilenameUna
5152
}
5253

5354
return &FilenameUnadjuster{
54-
m: m,
55-
log: log,
55+
m: m,
56+
log: log,
57+
loggedUnadjustments: map[string]bool{},
5658
}
5759
}
5860

5961
func (p FilenameUnadjuster) Name() string {
6062
return "filename_unadjuster"
6163
}
6264

63-
func (p FilenameUnadjuster) Process(issues []result.Issue) ([]result.Issue, error) {
65+
func (p *FilenameUnadjuster) Process(issues []result.Issue) ([]result.Issue, error) {
6466
return transformIssues(issues, func(i *result.Issue) *result.Issue {
6567
issueFilePath := i.FilePath()
6668
if !filepath.IsAbs(i.FilePath()) {
@@ -79,7 +81,10 @@ func (p FilenameUnadjuster) Process(issues []result.Issue) ([]result.Issue, erro
7981

8082
newI := *i
8183
newI.Pos = mapper(i.Pos)
82-
p.log.Infof("Unadjusted from %v to %v", i.Pos, newI.Pos)
84+
if !p.loggedUnadjustments[i.Pos.Filename] {
85+
p.log.Infof("Unadjusted from %v to %v", i.Pos, newI.Pos)
86+
p.loggedUnadjustments[i.Pos.Filename] = true
87+
}
8388
return &newI
8489
}), nil
8590
}

pkg/result/processors/skip_dirs.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ func (p *SkipDirs) Process(issues []result.Issue) ([]result.Issue, error) {
7171

7272
func (p *SkipDirs) shouldPassIssue(i *result.Issue) bool {
7373
if filepath.IsAbs(i.FilePath()) {
74-
p.log.Warnf("Got abs path in skip dirs processor, it should be relative")
74+
if !isSpecialAutogeneratedFile(i.FilePath()) {
75+
p.log.Warnf("Got abs path %s in skip dirs processor, it should be relative", i.FilePath())
76+
}
7577
return true
7678
}
7779

0 commit comments

Comments
 (0)