Skip to content

Commit

Permalink
Fix linting of goyacc files
Browse files Browse the repository at this point in the history
Skip yacctab, yaccpar and NONE files.

Relates: #467, #468
  • Loading branch information
jirfag committed Apr 20, 2019
1 parent ed0b551 commit ec5bf9b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
11 changes: 11 additions & 0 deletions pkg/result/processors/autogenerated_exclude.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"go/ast"
"go/token"
"path/filepath"
"strings"

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

func isSpecialAutogeneratedFile(filePath string) bool {
fileName := filepath.Base(filePath)
// fake files to which //line points to for goyacc generated files
return fileName == "yacctab" || fileName == "yaccpar" || fileName == "NONE"
}

func (p *AutogeneratedExclude) shouldPassIssue(i *result.Issue) (bool, error) {
if i.FromLinter == "typecheck" {
// don't hide typechecking errors in generated files: users expect to see why the project isn't compiling
return true, nil
}

if isSpecialAutogeneratedFile(i.FilePath()) {
return false, nil
}

fs, err := p.getOrCreateFileSummary(i)
if err != nil {
return false, err
Expand Down
19 changes: 12 additions & 7 deletions pkg/result/processors/filename_unadjuster.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ type posMapper func(pos token.Position) token.Position
// to get filename. And they return adjusted filename (e.g. *.qtpl) for an issue. We need
// restore real .go filename to properly output it, parse it, etc.
type FilenameUnadjuster struct {
m map[string]posMapper // map from adjusted filename to position mapper: adjusted -> unadjusted position
log logutils.Log
m map[string]posMapper // map from adjusted filename to position mapper: adjusted -> unadjusted position
log logutils.Log
loggedUnadjustments map[string]bool
}

var _ Processor = FilenameUnadjuster{}
var _ Processor = &FilenameUnadjuster{}

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

return &FilenameUnadjuster{
m: m,
log: log,
m: m,
log: log,
loggedUnadjustments: map[string]bool{},
}
}

func (p FilenameUnadjuster) Name() string {
return "filename_unadjuster"
}

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

newI := *i
newI.Pos = mapper(i.Pos)
p.log.Infof("Unadjusted from %v to %v", i.Pos, newI.Pos)
if !p.loggedUnadjustments[i.Pos.Filename] {
p.log.Infof("Unadjusted from %v to %v", i.Pos, newI.Pos)
p.loggedUnadjustments[i.Pos.Filename] = true
}
return &newI
}), nil
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/result/processors/skip_dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func (p *SkipDirs) Process(issues []result.Issue) ([]result.Issue, error) {

func (p *SkipDirs) shouldPassIssue(i *result.Issue) bool {
if filepath.IsAbs(i.FilePath()) {
p.log.Warnf("Got abs path in skip dirs processor, it should be relative")
if !isSpecialAutogeneratedFile(i.FilePath()) {
p.log.Warnf("Got abs path %s in skip dirs processor, it should be relative", i.FilePath())
}
return true
}

Expand Down

0 comments on commit ec5bf9b

Please sign in to comment.