Skip to content

Commit

Permalink
update the should ignore file
Browse files Browse the repository at this point in the history
  • Loading branch information
owenrumney-f3 committed Feb 10, 2021
1 parent 13b9812 commit 50e0bda
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/app/squealer/scan/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package scan

import (
"fmt"
"github.com/owenrumney/squealer/internal/app/squealer/config"
"github.com/owenrumney/squealer/internal/app/squealer/mertics"
"os"
"regexp"
"strings"

"github.com/owenrumney/squealer/internal/app/squealer/config"
"github.com/owenrumney/squealer/internal/app/squealer/mertics"
)

type ScannerType string
Expand Down Expand Up @@ -48,7 +50,7 @@ func notGit(basepath string) bool {

func shouldIgnore(filename string, ignorePaths []string, ignoreExtensions []string) bool {
for _, ignorePath := range ignorePaths {
if strings.HasPrefix(filename, ignorePath) {
if match, err := regexp.MatchString(fmt.Sprintf(`\b%s\b`, ignorePath), filename); err == nil && match {
return true
}
}
Expand Down
14 changes: 14 additions & 0 deletions internal/app/squealer/scan/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,17 @@ func TestNewScannerIsDirectoryScanner(t *testing.T) {
assert.NoError(t, err)
assert.IsType(t, &directoryScanner{}, scanner)
}

func TestShouldIgnore(t *testing.T) {
ignorePaths := []string{"vendor", "npm_modules"}
ignoreExtensions := []string{"zip"}
assert.True(t, shouldIgnore("/src/scan/vendor/github.com", ignorePaths, ignoreExtensions))
assert.True(t, shouldIgnore("/src/scan/npm_modules/github.com", ignorePaths, ignoreExtensions))
assert.True(t, shouldIgnore("vendor/github.com", ignorePaths, ignoreExtensions))
assert.True(t, shouldIgnore("npm_modules/github.com", ignorePaths, ignoreExtensions))
assert.True(t, shouldIgnore("pingu.zip", ignorePaths, ignoreExtensions))
assert.False(t, shouldIgnore("src/scan", ignorePaths, ignoreExtensions))
assert.False(t, shouldIgnore("test", ignorePaths, ignoreExtensions))
assert.False(t, shouldIgnore("govendor", ignorePaths, ignoreExtensions))
assert.False(t, shouldIgnore("pingu.honk", ignorePaths, ignoreExtensions))
}

0 comments on commit 50e0bda

Please sign in to comment.