From 1a633344ff3ac49ded45228f73a4cd65489bfd1f Mon Sep 17 00:00:00 2001 From: Ben Boyter Date: Wed, 15 Dec 2021 12:47:16 +1100 Subject: [PATCH] resolve https://github.com/boyter/scc/issues/259 --- README.md | 6 ++++++ SCC-OUTPUT-REPORT.html | 34 +++++++++++++++++----------------- main.go | 7 +++++++ processor/file.go | 18 ++++++++++++++++++ processor/processor.go | 3 +++ test-all.sh | 13 +++++++++++++ 6 files changed, 64 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 50ee4e90..01f2f99c 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,7 @@ Command line usage of `scc` is designed to be as simple as possible. Full details can be found in `scc --help` or `scc -h`. Note that the below reflects the state of master not a release. ``` +$ scc -h Sloc, Cloc and Code. Count lines of code in a directory with complexity estimation. Version 3.0.0 Ben Boyter + Contributors @@ -204,8 +205,11 @@ Flags: --ci enable CI output settings where stdout is ASCII --cocomo-project-type string change COCOMO model type [organic, semi-detached, embedded, "custom,1,1,1,1"] (default "organic") --count-as string count extension as language [e.g. jsp:htm,chead:"C Header" maps extension jsp to html and chead to C Header] + --currency-symbol string set currency symbol (default "$") --debug enable debug output + --eaf float the effort adjustment factor derived from the cost drivers (1.0 if rated nominal) (default 1) --exclude-dir strings directories to exclude (default [.git,.hg,.svn]) + -x, --exclude-ext strings ignore file extensions (overrides include-ext) [comma separated list: e.g. go,java,js] --file-gc-count int number of files to parse before turning the GC on (default 10000) -f, --format string set output format [tabular, wide, json, csv, csv-stream, cloc-yaml, html, html-table, sql, sql-insert, openmetrics] (default "tabular") --format-multi string have multiple format output overriding --format [e.g. tabular:stdout,csv:file.csv,json:file.json] @@ -232,9 +236,11 @@ Flags: --no-size remove size calculation output -M, --not-match stringArray ignore files and directories matching regular expression -o, --output string output filename (default stdout) + --overhead float set the overhead multiplier for corporate overhead (facilities, equipment, accounting, etc.) (default 2.4) --remap-all string inspect every file and remap by checking for a string and remapping the language [e.g. "-*- C++ -*-":"C Header"] --remap-unknown string inspect files of unknown type and remap by checking for a string and remapping the language [e.g. "-*- C++ -*-":"C Header"] --size-unit string set size unit [si, binary, mixed, xkcd-kb, xkcd-kelly, xkcd-imaginary, xkcd-intel, xkcd-drive, xkcd-bakers] (default "si") + --sloccount-format print a more SLOCCount like COCOMO calculation -s, --sort string column to sort by [files, name, lines, blanks, code, comments, complexity] (default "files") --sql-project string use supplied name as the project identifier for the current run. Only valid with the --format sql or sql-insert option -t, --trace enable trace output (not recommended when processing multiple files) diff --git a/SCC-OUTPUT-REPORT.html b/SCC-OUTPUT-REPORT.html index 2c2604d9..86d16af4 100644 --- a/SCC-OUTPUT-REPORT.html +++ b/SCC-OUTPUT-REPORT.html @@ -12,12 +12,12 @@ Go 36 - 8899 - 1431 - 422 - 7046 - 1419 - 352051 + 8927 + 1434 + 425 + 7068 + 1426 + 352771 Java 24 @@ -93,12 +93,12 @@ Shell 3 - 1097 - 145 + 1110 + 146 85 - 867 - 97 - 39410 + 879 + 99 + 39752 C# 2 @@ -607,11 +607,11 @@ Total 176 - 26727 - 3028 - 1758 - 21941 - 2403 - 1808690 + 26768 + 3032 + 1761 + 21975 + 2412 + 1809752 \ No newline at end of file diff --git a/main.go b/main.go index 17e1c94a..9c9afda7 100644 --- a/main.go +++ b/main.go @@ -96,6 +96,13 @@ func main() { []string{}, "limit to file extensions [comma separated list: e.g. go,java,js]", ) + flags.StringSliceVarP( + &processor.ExcludeListExtensions, + "exclude-ext", + "x", + []string{}, + "ignore file extensions (overrides include-ext) [comma separated list: e.g. go,java,js]", + ) flags.BoolVarP( &processor.Languages, "languages", diff --git a/processor/file.go b/processor/file.go index 18c198c6..519d84d9 100644 --- a/processor/file.go +++ b/processor/file.go @@ -246,6 +246,7 @@ func newFileJob(path, name string, fileInfo os.FileInfo) *FileJob { language, extension := DetectLanguage(name) if len(language) != 0 { + // check if extensions in the allow list, which should limit to just those extensions if len(AllowListExtensions) != 0 { ok := false for _, x := range AllowListExtensions { @@ -262,6 +263,23 @@ func newFileJob(path, name string, fileInfo os.FileInfo) *FileJob { } } + // check if we should exclude this type + if len(ExcludeListExtensions) != 0 { + ok := true + for _, x := range ExcludeListExtensions { + if x == extension { + ok = false + } + } + + if !ok { + if Verbose { + printWarn(fmt.Sprintf("skipping file as in exclude list: %s", name)) + } + return nil + } + } + for _, l := range language { LoadLanguageFeature(l) } diff --git a/processor/processor.go b/processor/processor.go index eead133b..e485a7a8 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -146,6 +146,9 @@ var FileSummaryJobQueueSize = runtime.NumCPU() // AllowListExtensions is a list of extensions which are allowed to be processed var AllowListExtensions = []string{} +// ExcludeListExtensions is a list of extensions which should be ignored +var ExcludeListExtensions = []string{} + // AverageWage is the average wage in dollars used for the COCOMO cost estimate var AverageWage int64 = 56286 diff --git a/test-all.sh b/test-all.sh index 2b838578..57d70c95 100755 --- a/test-all.sh +++ b/test-all.sh @@ -848,6 +848,19 @@ else echo -e "${GREEN}PASSED examples exclude-dir check" fi +a=$(./scc --exclude-ext go) +b=$(./scc) +if [ "$a" == "$b" ]; then + echo "$a" + echo "$b" + echo -e "${RED}=======================================================" + echo -e "FAILED exclude-ext check" + echo -e "=================================================${NC}" + exit +else + echo -e "${GREEN}PASSED exclude-ext check" +fi + # Try out specific languages for i in 'Bosque ' 'Flow9 ' 'Bitbucket Pipeline ' 'Docker ignore ' 'Q# ' 'Futhark ' 'Alloy ' 'Wren ' 'Monkey C ' 'Alchemist ' 'Luna ' 'ignore ' 'XML Schema ' 'Web Services' 'Go ' 'Java ' 'Boo ' 'License ' 'BASH ' 'C Shell ' 'Korn Shell ' 'Makefile ' 'Shell ' 'Zsh ' 'Rakefile ' 'Gemfile ' 'Dockerfile ' 'Yarn ' 'Sieve ' 'F# ' 'Elm ' 'Terraform ' 'Clojure ' 'C# ' 'LLVM IR ' 'HAML ' 'FXML ' 'DM ' 'Nushell ' 'Racket ' 'DOT ' do