Skip to content

Commit 3ae2762

Browse files
author
Cosmin Cojocar
committed
Add support for partial path match in the skip option
1 parent 0573847 commit 3ae2762

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

filelist.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,24 @@ func (f *fileList) Set(path string) error {
5757

5858
func (f fileList) Contains(path string) bool {
5959
for p := range f.patterns {
60-
if glob.Glob(p, path) {
61-
if logger != nil {
62-
logger.Printf("skipping: %s\n", path)
60+
if strings.Contains(p, glob.GLOB) {
61+
if glob.Glob(p, path) {
62+
if logger != nil {
63+
logger.Printf("skipping: %s\n", path)
64+
}
65+
return true
6366
}
64-
return true
67+
} else {
68+
// check if only a sub-folder of the path is excluded
69+
if strings.Contains(path, p) {
70+
if logger != nil {
71+
logger.Printf("skipping: %s\n", path)
72+
}
73+
return true
74+
}
75+
6576
}
6677
}
67-
//log.Printf("including: %s\n", path)
6878
return false
6979
}
7080

filelist_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ func Test_fileList_Contains(t *testing.T) {
235235
args: args{path: "/baz/bar/foo_test.go"},
236236
want: true,
237237
},
238+
{
239+
name: "sub-folder, match",
240+
fields: fields{patterns: []string{"vendor"}},
241+
args: args{path: "/baz/vendor/bar/foo_test.go"},
242+
want: true,
243+
},
238244
}
239245
for _, tt := range tests {
240246
f := newFileList(tt.fields.patterns...)

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func main() {
155155

156156
// Exclude files
157157
excluded := newFileList("*_test.go")
158-
flag.Var(excluded, "skip", "File pattern to exclude from scan. Uses simple * globs and requires full match")
158+
flag.Var(excluded, "skip", "File pattern to exclude from scan. Uses simple * globs and requires full or partial match")
159159

160160
incRules := ""
161161
flag.StringVar(&incRules, "include", "", "Comma separated list of rules IDs to include. (see rule list)")

0 commit comments

Comments
 (0)