Skip to content

Commit 87cb7bf

Browse files
committed
Fix skip-dirs options after support of go/packages
1 parent fbcc552 commit 87cb7bf

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

pkg/packages/skip.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
package packages
22

3+
import (
4+
"fmt"
5+
"path/filepath"
6+
)
7+
8+
func pathElemRe(e string) string {
9+
return fmt.Sprintf(`(^|%c)%s($|%c)`, filepath.Separator, e, filepath.Separator)
10+
}
11+
312
var StdExcludeDirRegexps = []string{
4-
"^vendor$", "^third_party$",
5-
"^testdata$", "^examples$",
6-
"^Godeps$",
7-
"^builtin$",
13+
pathElemRe("vendor"),
14+
pathElemRe("third_party"),
15+
pathElemRe("testdata"),
16+
pathElemRe("examples"),
17+
pathElemRe("Godeps"),
18+
pathElemRe("builtin"),
819
}

pkg/result/processors/skip_dirs.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/pkg/errors"
1010

11-
"github.com/golangci/golangci-lint/pkg/fsutils"
1211
"github.com/golangci/golangci-lint/pkg/logutils"
1312
"github.com/golangci/golangci-lint/pkg/result"
1413
)
@@ -75,11 +74,11 @@ func (p *SkipDirs) Process(issues []result.Issue) ([]result.Issue, error) {
7574
return filterIssues(issues, p.shouldPassIssue), nil
7675
}
7776

78-
func (p *SkipDirs) getLongestArgRelativeIssuePath(i *result.Issue) (string, string) {
77+
func (p *SkipDirs) getLongestArgRelativeIssuePath(i *result.Issue) string {
7978
issueAbsPath, err := filepath.Abs(i.FilePath())
8079
if err != nil {
8180
p.log.Warnf("Can't abs-ify path %q: %s", i.FilePath(), err)
82-
return "", ""
81+
return ""
8382
}
8483

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

9089
relPath := strings.TrimPrefix(issueAbsPath, arg)
9190
relPath = strings.TrimPrefix(relPath, string(filepath.Separator))
92-
return relPath, arg
91+
return relPath
9392
}
9493

9594
p.log.Infof("Issue path %q isn't relative to any of run args", i.FilePath())
96-
return "", ""
95+
return ""
9796
}
9897

9998
func (p *SkipDirs) shouldPassIssue(i *result.Issue) bool {
100-
relIssuePath, issueArg := p.getLongestArgRelativeIssuePath(i)
99+
relIssuePath := p.getLongestArgRelativeIssuePath(i)
101100
if relIssuePath == "" {
102101
return true
103102
}
@@ -106,21 +105,10 @@ func (p *SkipDirs) shouldPassIssue(i *result.Issue) bool {
106105
relIssuePath = filepath.Dir(relIssuePath)
107106
}
108107

109-
relIssueDirParts := strings.Split(relIssuePath, string(filepath.Separator))
110-
111108
for _, pattern := range p.patterns {
112-
skippedDir := issueArg
113-
for _, part := range relIssueDirParts {
114-
skippedDir = filepath.Join(skippedDir, part)
115-
if pattern.MatchString(part) {
116-
relSkippedDir, err := fsutils.ShortestRelPath(skippedDir, "")
117-
if err != nil {
118-
p.log.Warnf("Can't construct short relative path for %q: %s", skippedDir, err)
119-
return true
120-
}
121-
p.skippedDirs[relSkippedDir] = true
122-
return false
123-
}
109+
if pattern.MatchString(relIssuePath) {
110+
p.skippedDirs[relIssuePath] = true
111+
return false
124112
}
125113
}
126114

0 commit comments

Comments
 (0)