Fix skip-dirs options after support of go/packages
This commit is contained in:
parent
fbcc55224f
commit
87cb7bf1a6
@ -1,8 +1,19 @@
|
|||||||
package packages
|
package packages
|
||||||
|
|
||||||
var StdExcludeDirRegexps = []string{
|
import (
|
||||||
"^vendor$", "^third_party$",
|
"fmt"
|
||||||
"^testdata$", "^examples$",
|
"path/filepath"
|
||||||
"^Godeps$",
|
)
|
||||||
"^builtin$",
|
|
||||||
|
func pathElemRe(e string) string {
|
||||||
|
return fmt.Sprintf(`(^|%c)%s($|%c)`, filepath.Separator, e, filepath.Separator)
|
||||||
|
}
|
||||||
|
|
||||||
|
var StdExcludeDirRegexps = []string{
|
||||||
|
pathElemRe("vendor"),
|
||||||
|
pathElemRe("third_party"),
|
||||||
|
pathElemRe("testdata"),
|
||||||
|
pathElemRe("examples"),
|
||||||
|
pathElemRe("Godeps"),
|
||||||
|
pathElemRe("builtin"),
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/golangci/golangci-lint/pkg/fsutils"
|
|
||||||
"github.com/golangci/golangci-lint/pkg/logutils"
|
"github.com/golangci/golangci-lint/pkg/logutils"
|
||||||
"github.com/golangci/golangci-lint/pkg/result"
|
"github.com/golangci/golangci-lint/pkg/result"
|
||||||
)
|
)
|
||||||
@ -75,11 +74,11 @@ func (p *SkipDirs) Process(issues []result.Issue) ([]result.Issue, error) {
|
|||||||
return filterIssues(issues, p.shouldPassIssue), nil
|
return filterIssues(issues, p.shouldPassIssue), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SkipDirs) getLongestArgRelativeIssuePath(i *result.Issue) (string, string) {
|
func (p *SkipDirs) getLongestArgRelativeIssuePath(i *result.Issue) string {
|
||||||
issueAbsPath, err := filepath.Abs(i.FilePath())
|
issueAbsPath, err := filepath.Abs(i.FilePath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.log.Warnf("Can't abs-ify path %q: %s", i.FilePath(), err)
|
p.log.Warnf("Can't abs-ify path %q: %s", i.FilePath(), err)
|
||||||
return "", ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, arg := range p.sortedAbsArgs {
|
for _, arg := range p.sortedAbsArgs {
|
||||||
@ -89,15 +88,15 @@ func (p *SkipDirs) getLongestArgRelativeIssuePath(i *result.Issue) (string, stri
|
|||||||
|
|
||||||
relPath := strings.TrimPrefix(issueAbsPath, arg)
|
relPath := strings.TrimPrefix(issueAbsPath, arg)
|
||||||
relPath = strings.TrimPrefix(relPath, string(filepath.Separator))
|
relPath = strings.TrimPrefix(relPath, string(filepath.Separator))
|
||||||
return relPath, arg
|
return relPath
|
||||||
}
|
}
|
||||||
|
|
||||||
p.log.Infof("Issue path %q isn't relative to any of run args", i.FilePath())
|
p.log.Infof("Issue path %q isn't relative to any of run args", i.FilePath())
|
||||||
return "", ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SkipDirs) shouldPassIssue(i *result.Issue) bool {
|
func (p *SkipDirs) shouldPassIssue(i *result.Issue) bool {
|
||||||
relIssuePath, issueArg := p.getLongestArgRelativeIssuePath(i)
|
relIssuePath := p.getLongestArgRelativeIssuePath(i)
|
||||||
if relIssuePath == "" {
|
if relIssuePath == "" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -106,23 +105,12 @@ func (p *SkipDirs) shouldPassIssue(i *result.Issue) bool {
|
|||||||
relIssuePath = filepath.Dir(relIssuePath)
|
relIssuePath = filepath.Dir(relIssuePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
relIssueDirParts := strings.Split(relIssuePath, string(filepath.Separator))
|
|
||||||
|
|
||||||
for _, pattern := range p.patterns {
|
for _, pattern := range p.patterns {
|
||||||
skippedDir := issueArg
|
if pattern.MatchString(relIssuePath) {
|
||||||
for _, part := range relIssueDirParts {
|
p.skippedDirs[relIssuePath] = true
|
||||||
skippedDir = filepath.Join(skippedDir, part)
|
|
||||||
if pattern.MatchString(part) {
|
|
||||||
relSkippedDir, err := fsutils.ShortestRelPath(skippedDir, "")
|
|
||||||
if err != nil {
|
|
||||||
p.log.Warnf("Can't construct short relative path for %q: %s", skippedDir, err)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
p.skippedDirs[relSkippedDir] = true
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user