Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions filelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,24 @@ func (f *fileList) Set(path string) error {

func (f fileList) Contains(path string) bool {
for p := range f.patterns {
if glob.Glob(p, path) {
if logger != nil {
logger.Printf("skipping: %s\n", path)
if strings.Contains(p, glob.GLOB) {
if glob.Glob(p, path) {
if logger != nil {
logger.Printf("skipping: %s\n", path)
}
return true
}
return true
} else {
// check if only a sub-folder of the path is excluded
if strings.Contains(path, p) {
if logger != nil {
logger.Printf("skipping: %s\n", path)
}
return true
}

}
}
//log.Printf("including: %s\n", path)
return false
}

Expand Down
6 changes: 6 additions & 0 deletions filelist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ func Test_fileList_Contains(t *testing.T) {
args: args{path: "/baz/bar/foo_test.go"},
want: true,
},
{
name: "sub-folder, match",
fields: fields{patterns: []string{"vendor"}},
args: args{path: "/baz/vendor/bar/foo_test.go"},
want: true,
},
}
for _, tt := range tests {
f := newFileList(tt.fields.patterns...)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func main() {

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

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