Fix linting of goyacc files
Skip yacctab, yaccpar and NONE files. Relates: #467, #468
This commit is contained in:
parent
ed0b551070
commit
ec5bf9b67b
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/token"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/lint/astcache"
|
||||
@ -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
|
||||
|
@ -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{}
|
||||
@ -51,8 +52,9 @@ func NewFilenameUnadjuster(cache *astcache.Cache, log logutils.Log) *FilenameUna
|
||||
}
|
||||
|
||||
return &FilenameUnadjuster{
|
||||
m: m,
|
||||
log: log,
|
||||
m: m,
|
||||
log: log,
|
||||
loggedUnadjustments: map[string]bool{},
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +62,7 @@ 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()) {
|
||||
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user