Skip to content

Commit

Permalink
resolve #259
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Dec 15, 2021
1 parent f0fa7a5 commit 1a63334
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 17 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ben@boyter.org> + Contributors
Expand All @@ -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]
Expand All @@ -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)
Expand Down
34 changes: 17 additions & 17 deletions SCC-OUTPUT-REPORT.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<tbody><tr>
<th>Go</th>
<th>36</th>
<th>8899</th>
<th>1431</th>
<th>422</th>
<th>7046</th>
<th>1419</th>
<th>352051</th>
<th>8927</th>
<th>1434</th>
<th>425</th>
<th>7068</th>
<th>1426</th>
<th>352771</th>
</tr><tr>
<th>Java</th>
<th>24</th>
Expand Down Expand Up @@ -93,12 +93,12 @@
</tr><tr>
<th>Shell</th>
<th>3</th>
<th>1097</th>
<th>145</th>
<th>1110</th>
<th>146</th>
<th>85</th>
<th>867</th>
<th>97</th>
<th>39410</th>
<th>879</th>
<th>99</th>
<th>39752</th>
</tr><tr>
<th>C#</th>
<th>2</th>
Expand Down Expand Up @@ -607,11 +607,11 @@
<tfoot><tr>
<th>Total</th>
<th>176</th>
<th>26727</th>
<th>3028</th>
<th>1758</th>
<th>21941</th>
<th>2403</th>
<th>1808690</th>
<th>26768</th>
<th>3032</th>
<th>1761</th>
<th>21975</th>
<th>2412</th>
<th>1809752</th>
</tr></tfoot>
</table></body></html>
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 18 additions & 0 deletions processor/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1a63334

Please sign in to comment.