Skip to content

Commit

Permalink
PC refactor before anyone mentions it
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Oct 15, 2019
1 parent 8711b66 commit 847861d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func main() {
"enable debug output",
)
flags.StringSliceVar(
&processor.PathBlacklist,
&processor.PathDenyList,
"exclude-dir",
[]string{".git", ".hg", ".svn"},
"directories to exclude",
Expand All @@ -90,7 +90,7 @@ func main() {
"set output format [tabular, wide, json, csv, cloc-yaml]",
)
flags.StringSliceVarP(
&processor.WhiteListExtensions,
&processor.AllowListExtensions,
"include-ext",
"i",
[]string{},
Expand Down
14 changes: 7 additions & 7 deletions processor/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ DIRENTS:
path := filepath.Join(job.path, name)
isDir := dirent.IsDir()

for _, black := range PathBlacklist {
if strings.HasSuffix(path, black) {
for _, deny := range PathDenyList {
if strings.HasSuffix(path, deny) {
if Verbose {
printWarn(fmt.Sprintf("skipping directory due to being in blacklist: %s", path))
printWarn(fmt.Sprintf("skipping directory due to being in denylist: %s", path))
}
continue DIRENTS
}
Expand Down Expand Up @@ -190,7 +190,7 @@ func newFileJob(path, name string) *FileJob {
t := strings.Count(name, ".")

// If there is no . in the filename or it starts with one then check if #! or other
if (t == 0 || (name[0] == '.' && t == 1)) && len(WhiteListExtensions) == 0 {
if (t == 0 || (name[0] == '.' && t == 1)) && len(AllowListExtensions) == 0 {
return checkFullName(name, path, extension)
}

Expand All @@ -209,17 +209,17 @@ func newFileJob(path, name string) *FileJob {
}

if ok {
if len(WhiteListExtensions) != 0 {
if len(AllowListExtensions) != 0 {
ok = false
for _, x := range WhiteListExtensions {
for _, x := range AllowListExtensions {
if x == extension {
ok = true
}
}

if !ok {
if Verbose {
printWarn(fmt.Sprintf("skipping file as not whitelisted: %s", name))
printWarn(fmt.Sprintf("skipping file as not in allow list: %s", name))
}
return nil
}
Expand Down
22 changes: 11 additions & 11 deletions processor/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ func TestWalkDirectoryParallel(t *testing.T) {
isLazy = false
ProcessConstants()

WhiteListExtensions = []string{"go"}
AllowListExtensions = []string{"go"}
Exclude = []string{"vendor"}
PathBlacklist = []string{"vendor"}
PathDenyList = []string{"vendor"}
Verbose = true
Trace = true
Debug = true
Expand Down Expand Up @@ -107,9 +107,9 @@ func TestWalkDirectoryParallelWorksWithSingleInputFile(t *testing.T) {
isLazy = false
ProcessConstants()

WhiteListExtensions = []string{"go"}
AllowListExtensions = []string{"go"}
Exclude = []string{"vendor"}
PathBlacklist = []string{"vendor"}
PathDenyList = []string{"vendor"}
Verbose = true
Trace = true
Debug = true
Expand Down Expand Up @@ -139,9 +139,9 @@ func TestWalkDirectoryParallelIgnoresRootTrailingSlash(t *testing.T) {
isLazy = false
ProcessConstants()

WhiteListExtensions = []string{"go"}
AllowListExtensions = []string{"go"}
Exclude = []string{"vendor"}
PathBlacklist = []string{"vendor"}
PathDenyList = []string{"vendor"}
Verbose = true
Trace = true
Debug = true
Expand Down Expand Up @@ -177,9 +177,9 @@ func TestWalkDirectoryParallelIgnoresAbsoluteGitPath(t *testing.T) {
// certain to appear in the .git directory.
// This test also relies on the behaviour of treating `master` as a file
// with the `master` file extension.
WhiteListExtensions = []string{"master", "go"}
AllowListExtensions = []string{"master", "go"}
Exclude = []string{"vendor"}
PathBlacklist = []string{".git", "vendor"}
PathDenyList = []string{".git", "vendor"}
Verbose = true
Trace = true
Debug = true
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestWalkDirectoryParallelIgnoresAbsoluteGitPath(t *testing.T) {

func TestNewFileJobFullname(t *testing.T) {
ProcessConstants()
WhiteListExtensions = []string{}
AllowListExtensions = []string{}
job := newFileJob("./examples/issue114/", "makefile")

if job.PossibleLanguages[0] != "Makefile" {
Expand All @@ -231,7 +231,7 @@ func TestNewFileJob(t *testing.T) {
}

func TestNewFileJobGitIgnore(t *testing.T) {
WhiteListExtensions = []string{}
AllowListExtensions = []string{}
ProcessConstants()
job := newFileJob("./examples/issue114/", ".gitignore")

Expand All @@ -241,7 +241,7 @@ func TestNewFileJobGitIgnore(t *testing.T) {
}

func TestNewFileJobIgnore(t *testing.T) {
WhiteListExtensions = []string{}
AllowListExtensions = []string{}
ProcessConstants()
job := newFileJob("./examples/issue114/", ".ignore")

Expand Down
14 changes: 7 additions & 7 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ var Format = ""
// FileOutput sets the file that output should be written to
var FileOutput = ""

// PathBlacklist sets the paths that should be skipped
var PathBlacklist = []string{}
// PathDenyList sets the paths that should be skipped
var PathDenyList = []string{}

// FileListQueueSize is the queue of files found and ready to be read into memory
var FileListQueueSize = runtime.NumCPU()
Expand All @@ -97,8 +97,8 @@ var FileProcessJobWorkers = runtime.NumCPU() * 4
// FileSummaryJobQueueSize is the queue used to hold processed file statistics before formatting
var FileSummaryJobQueueSize = runtime.NumCPU()

// WhiteListExtensions is a list of extensions which are whitelisted to be processed
var WhiteListExtensions = []string{}
// AllowListExtensions is a list of extensions which are allowed to be processed
var AllowListExtensions = []string{}

// AverageWage is the average wage in dollars used for the COCOMO cost estimate
var AverageWage int64 = 56286
Expand Down Expand Up @@ -291,9 +291,9 @@ func processFlags() {
}

if Debug {
printDebug(fmt.Sprintf("Path Black List: %v", PathBlacklist))
printDebug(fmt.Sprintf("Path Deny List: %v", PathDenyList))
printDebug(fmt.Sprintf("Sort By: %s", SortBy))
printDebug(fmt.Sprintf("White List: %v", WhiteListExtensions))
printDebug(fmt.Sprintf("White List: %v", AllowListExtensions))
printDebug(fmt.Sprintf("Files Output: %t", Files))
printDebug(fmt.Sprintf("Verbose: %t", Verbose))
printDebug(fmt.Sprintf("Duplicates Detection: %t", Duplicates))
Expand Down Expand Up @@ -373,7 +373,7 @@ func Process() {
if Debug {
printDebug(fmt.Sprintf("NumCPU: %d", runtime.NumCPU()))
printDebug(fmt.Sprintf("SortBy: %s", SortBy))
printDebug(fmt.Sprintf("PathBlacklist: %v", PathBlacklist))
printDebug(fmt.Sprintf("PathDenyList: %v", PathDenyList))
}

fileListQueue := make(chan *FileJob, FileListQueueSize) // Files ready to be read from disk
Expand Down

0 comments on commit 847861d

Please sign in to comment.