From 847861db3a5dfd7bd3ea320a89e8e50c56e7a48f Mon Sep 17 00:00:00 2001 From: Ben Boyter Date: Wed, 16 Oct 2019 09:00:41 +1100 Subject: [PATCH] PC refactor before anyone mentions it --- main.go | 4 ++-- processor/file.go | 14 +++++++------- processor/file_test.go | 22 +++++++++++----------- processor/processor.go | 14 +++++++------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/main.go b/main.go index 7abe4400a..f619db570 100644 --- a/main.go +++ b/main.go @@ -71,7 +71,7 @@ func main() { "enable debug output", ) flags.StringSliceVar( - &processor.PathBlacklist, + &processor.PathDenyList, "exclude-dir", []string{".git", ".hg", ".svn"}, "directories to exclude", @@ -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{}, diff --git a/processor/file.go b/processor/file.go index 08d2a6e82..f5451f4f2 100644 --- a/processor/file.go +++ b/processor/file.go @@ -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 } @@ -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) } @@ -209,9 +209,9 @@ 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 } @@ -219,7 +219,7 @@ func newFileJob(path, name string) *FileJob { 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 } diff --git a/processor/file_test.go b/processor/file_test.go index bfb58f095..cfe06a6fb 100644 --- a/processor/file_test.go +++ b/processor/file_test.go @@ -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 @@ -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 @@ -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 @@ -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 @@ -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" { @@ -231,7 +231,7 @@ func TestNewFileJob(t *testing.T) { } func TestNewFileJobGitIgnore(t *testing.T) { - WhiteListExtensions = []string{} + AllowListExtensions = []string{} ProcessConstants() job := newFileJob("./examples/issue114/", ".gitignore") @@ -241,7 +241,7 @@ func TestNewFileJobGitIgnore(t *testing.T) { } func TestNewFileJobIgnore(t *testing.T) { - WhiteListExtensions = []string{} + AllowListExtensions = []string{} ProcessConstants() job := newFileJob("./examples/issue114/", ".ignore") diff --git a/processor/processor.go b/processor/processor.go index 7697465cf..38b3189c3 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -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() @@ -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 @@ -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)) @@ -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