Skip to content

Commit

Permalink
Fix skip-dirs options after support of go/packages
Browse files Browse the repository at this point in the history
  • Loading branch information
jirfag committed Oct 28, 2018
1 parent fbcc552 commit 87cb7bf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
19 changes: 15 additions & 4 deletions pkg/packages/skip.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
package packages

import (
"fmt"
"path/filepath"
)

func pathElemRe(e string) string {
return fmt.Sprintf(`(^|%c)%s($|%c)`, filepath.Separator, e, filepath.Separator)
}

var StdExcludeDirRegexps = []string{
"^vendor$", "^third_party$",
"^testdata$", "^examples$",
"^Godeps$",
"^builtin$",
pathElemRe("vendor"),
pathElemRe("third_party"),
pathElemRe("testdata"),
pathElemRe("examples"),
pathElemRe("Godeps"),
pathElemRe("builtin"),
}
28 changes: 8 additions & 20 deletions pkg/result/processors/skip_dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/pkg/errors"

"github.com/golangci/golangci-lint/pkg/fsutils"
"github.com/golangci/golangci-lint/pkg/logutils"
"github.com/golangci/golangci-lint/pkg/result"
)
Expand Down Expand Up @@ -75,11 +74,11 @@ func (p *SkipDirs) Process(issues []result.Issue) ([]result.Issue, error) {
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())
if err != nil {
p.log.Warnf("Can't abs-ify path %q: %s", i.FilePath(), err)
return "", ""
return ""
}

for _, arg := range p.sortedAbsArgs {
Expand All @@ -89,15 +88,15 @@ func (p *SkipDirs) getLongestArgRelativeIssuePath(i *result.Issue) (string, stri

relPath := strings.TrimPrefix(issueAbsPath, arg)
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())
return "", ""
return ""
}

func (p *SkipDirs) shouldPassIssue(i *result.Issue) bool {
relIssuePath, issueArg := p.getLongestArgRelativeIssuePath(i)
relIssuePath := p.getLongestArgRelativeIssuePath(i)
if relIssuePath == "" {
return true
}
Expand All @@ -106,21 +105,10 @@ func (p *SkipDirs) shouldPassIssue(i *result.Issue) bool {
relIssuePath = filepath.Dir(relIssuePath)
}

relIssueDirParts := strings.Split(relIssuePath, string(filepath.Separator))

for _, pattern := range p.patterns {
skippedDir := issueArg
for _, part := range relIssueDirParts {
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
}
if pattern.MatchString(relIssuePath) {
p.skippedDirs[relIssuePath] = true
return false
}
}

Expand Down

0 comments on commit 87cb7bf

Please sign in to comment.