Merge pull request #128 from cosmincojocar/improve_skip

Add support for partial path match in the skip option
This commit is contained in:
Grant Murphy 2017-04-11 12:38:53 -07:00 committed by GitHub
commit 1beec25f77
3 changed files with 22 additions and 6 deletions

View file

@ -57,14 +57,24 @@ func (f *fileList) Set(path string) error {
func (f fileList) Contains(path string) bool { func (f fileList) Contains(path string) bool {
for p := range f.patterns { for p := range f.patterns {
if strings.Contains(p, glob.GLOB) {
if glob.Glob(p, path) { if glob.Glob(p, path) {
if logger != nil { if logger != nil {
logger.Printf("skipping: %s\n", path) 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 return false
} }

View file

@ -235,6 +235,12 @@ func Test_fileList_Contains(t *testing.T) {
args: args{path: "/baz/bar/foo_test.go"}, args: args{path: "/baz/bar/foo_test.go"},
want: true, 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 { for _, tt := range tests {
f := newFileList(tt.fields.patterns...) f := newFileList(tt.fields.patterns...)

View file

@ -155,7 +155,7 @@ func main() {
// Exclude files // Exclude files
excluded := newFileList("*_test.go") 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 := "" incRules := ""
flag.StringVar(&incRules, "include", "", "Comma separated list of rules IDs to include. (see rule list)") flag.StringVar(&incRules, "include", "", "Comma separated list of rules IDs to include. (see rule list)")