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"
|
"fmt"
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/token"
|
"go/token"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golangci/golangci-lint/pkg/lint/astcache"
|
"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)
|
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) {
|
func (p *AutogeneratedExclude) shouldPassIssue(i *result.Issue) (bool, error) {
|
||||||
if i.FromLinter == "typecheck" {
|
if i.FromLinter == "typecheck" {
|
||||||
// don't hide typechecking errors in generated files: users expect to see why the project isn't compiling
|
// don't hide typechecking errors in generated files: users expect to see why the project isn't compiling
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isSpecialAutogeneratedFile(i.FilePath()) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
fs, err := p.getOrCreateFileSummary(i)
|
fs, err := p.getOrCreateFileSummary(i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
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
|
// 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.
|
// restore real .go filename to properly output it, parse it, etc.
|
||||||
type FilenameUnadjuster struct {
|
type FilenameUnadjuster struct {
|
||||||
m map[string]posMapper // map from adjusted filename to position mapper: adjusted -> unadjusted position
|
m map[string]posMapper // map from adjusted filename to position mapper: adjusted -> unadjusted position
|
||||||
log logutils.Log
|
log logutils.Log
|
||||||
|
loggedUnadjustments map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Processor = FilenameUnadjuster{}
|
var _ Processor = &FilenameUnadjuster{}
|
||||||
|
|
||||||
func NewFilenameUnadjuster(cache *astcache.Cache, log logutils.Log) *FilenameUnadjuster {
|
func NewFilenameUnadjuster(cache *astcache.Cache, log logutils.Log) *FilenameUnadjuster {
|
||||||
m := map[string]posMapper{}
|
m := map[string]posMapper{}
|
||||||
@ -51,8 +52,9 @@ func NewFilenameUnadjuster(cache *astcache.Cache, log logutils.Log) *FilenameUna
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &FilenameUnadjuster{
|
return &FilenameUnadjuster{
|
||||||
m: m,
|
m: m,
|
||||||
log: log,
|
log: log,
|
||||||
|
loggedUnadjustments: map[string]bool{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +62,7 @@ func (p FilenameUnadjuster) Name() string {
|
|||||||
return "filename_unadjuster"
|
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 {
|
return transformIssues(issues, func(i *result.Issue) *result.Issue {
|
||||||
issueFilePath := i.FilePath()
|
issueFilePath := i.FilePath()
|
||||||
if !filepath.IsAbs(i.FilePath()) {
|
if !filepath.IsAbs(i.FilePath()) {
|
||||||
@ -79,7 +81,10 @@ func (p FilenameUnadjuster) Process(issues []result.Issue) ([]result.Issue, erro
|
|||||||
|
|
||||||
newI := *i
|
newI := *i
|
||||||
newI.Pos = mapper(i.Pos)
|
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
|
return &newI
|
||||||
}), nil
|
}), nil
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,9 @@ func (p *SkipDirs) Process(issues []result.Issue) ([]result.Issue, error) {
|
|||||||
|
|
||||||
func (p *SkipDirs) shouldPassIssue(i *result.Issue) bool {
|
func (p *SkipDirs) shouldPassIssue(i *result.Issue) bool {
|
||||||
if filepath.IsAbs(i.FilePath()) {
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user