Skip to content

Commit 1a63334

Browse files
committed
resolve #259
1 parent f0fa7a5 commit 1a63334

File tree

6 files changed

+64
-17
lines changed

6 files changed

+64
-17
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ Command line usage of `scc` is designed to be as simple as possible.
190190
Full details can be found in `scc --help` or `scc -h`. Note that the below reflects the state of master not a release.
191191

192192
```
193+
$ scc -h
193194
Sloc, Cloc and Code. Count lines of code in a directory with complexity estimation.
194195
Version 3.0.0
195196
Ben Boyter <[email protected]> + Contributors
@@ -204,8 +205,11 @@ Flags:
204205
--ci enable CI output settings where stdout is ASCII
205206
--cocomo-project-type string change COCOMO model type [organic, semi-detached, embedded, "custom,1,1,1,1"] (default "organic")
206207
--count-as string count extension as language [e.g. jsp:htm,chead:"C Header" maps extension jsp to html and chead to C Header]
208+
--currency-symbol string set currency symbol (default "$")
207209
--debug enable debug output
210+
--eaf float the effort adjustment factor derived from the cost drivers (1.0 if rated nominal) (default 1)
208211
--exclude-dir strings directories to exclude (default [.git,.hg,.svn])
212+
-x, --exclude-ext strings ignore file extensions (overrides include-ext) [comma separated list: e.g. go,java,js]
209213
--file-gc-count int number of files to parse before turning the GC on (default 10000)
210214
-f, --format string set output format [tabular, wide, json, csv, csv-stream, cloc-yaml, html, html-table, sql, sql-insert, openmetrics] (default "tabular")
211215
--format-multi string have multiple format output overriding --format [e.g. tabular:stdout,csv:file.csv,json:file.json]
@@ -232,9 +236,11 @@ Flags:
232236
--no-size remove size calculation output
233237
-M, --not-match stringArray ignore files and directories matching regular expression
234238
-o, --output string output filename (default stdout)
239+
--overhead float set the overhead multiplier for corporate overhead (facilities, equipment, accounting, etc.) (default 2.4)
235240
--remap-all string inspect every file and remap by checking for a string and remapping the language [e.g. "-*- C++ -*-":"C Header"]
236241
--remap-unknown string inspect files of unknown type and remap by checking for a string and remapping the language [e.g. "-*- C++ -*-":"C Header"]
237242
--size-unit string set size unit [si, binary, mixed, xkcd-kb, xkcd-kelly, xkcd-imaginary, xkcd-intel, xkcd-drive, xkcd-bakers] (default "si")
243+
--sloccount-format print a more SLOCCount like COCOMO calculation
238244
-s, --sort string column to sort by [files, name, lines, blanks, code, comments, complexity] (default "files")
239245
--sql-project string use supplied name as the project identifier for the current run. Only valid with the --format sql or sql-insert option
240246
-t, --trace enable trace output (not recommended when processing multiple files)

SCC-OUTPUT-REPORT.html

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
<tbody><tr>
1313
<th>Go</th>
1414
<th>36</th>
15-
<th>8899</th>
16-
<th>1431</th>
17-
<th>422</th>
18-
<th>7046</th>
19-
<th>1419</th>
20-
<th>352051</th>
15+
<th>8927</th>
16+
<th>1434</th>
17+
<th>425</th>
18+
<th>7068</th>
19+
<th>1426</th>
20+
<th>352771</th>
2121
</tr><tr>
2222
<th>Java</th>
2323
<th>24</th>
@@ -93,12 +93,12 @@
9393
</tr><tr>
9494
<th>Shell</th>
9595
<th>3</th>
96-
<th>1097</th>
97-
<th>145</th>
96+
<th>1110</th>
97+
<th>146</th>
9898
<th>85</th>
99-
<th>867</th>
100-
<th>97</th>
101-
<th>39410</th>
99+
<th>879</th>
100+
<th>99</th>
101+
<th>39752</th>
102102
</tr><tr>
103103
<th>C#</th>
104104
<th>2</th>
@@ -607,11 +607,11 @@
607607
<tfoot><tr>
608608
<th>Total</th>
609609
<th>176</th>
610-
<th>26727</th>
611-
<th>3028</th>
612-
<th>1758</th>
613-
<th>21941</th>
614-
<th>2403</th>
615-
<th>1808690</th>
610+
<th>26768</th>
611+
<th>3032</th>
612+
<th>1761</th>
613+
<th>21975</th>
614+
<th>2412</th>
615+
<th>1809752</th>
616616
</tr></tfoot>
617617
</table></body></html>

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ func main() {
9696
[]string{},
9797
"limit to file extensions [comma separated list: e.g. go,java,js]",
9898
)
99+
flags.StringSliceVarP(
100+
&processor.ExcludeListExtensions,
101+
"exclude-ext",
102+
"x",
103+
[]string{},
104+
"ignore file extensions (overrides include-ext) [comma separated list: e.g. go,java,js]",
105+
)
99106
flags.BoolVarP(
100107
&processor.Languages,
101108
"languages",

processor/file.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ func newFileJob(path, name string, fileInfo os.FileInfo) *FileJob {
246246
language, extension := DetectLanguage(name)
247247

248248
if len(language) != 0 {
249+
// check if extensions in the allow list, which should limit to just those extensions
249250
if len(AllowListExtensions) != 0 {
250251
ok := false
251252
for _, x := range AllowListExtensions {
@@ -262,6 +263,23 @@ func newFileJob(path, name string, fileInfo os.FileInfo) *FileJob {
262263
}
263264
}
264265

266+
// check if we should exclude this type
267+
if len(ExcludeListExtensions) != 0 {
268+
ok := true
269+
for _, x := range ExcludeListExtensions {
270+
if x == extension {
271+
ok = false
272+
}
273+
}
274+
275+
if !ok {
276+
if Verbose {
277+
printWarn(fmt.Sprintf("skipping file as in exclude list: %s", name))
278+
}
279+
return nil
280+
}
281+
}
282+
265283
for _, l := range language {
266284
LoadLanguageFeature(l)
267285
}

processor/processor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ var FileSummaryJobQueueSize = runtime.NumCPU()
146146
// AllowListExtensions is a list of extensions which are allowed to be processed
147147
var AllowListExtensions = []string{}
148148

149+
// ExcludeListExtensions is a list of extensions which should be ignored
150+
var ExcludeListExtensions = []string{}
151+
149152
// AverageWage is the average wage in dollars used for the COCOMO cost estimate
150153
var AverageWage int64 = 56286
151154

test-all.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,19 @@ else
848848
echo -e "${GREEN}PASSED examples exclude-dir check"
849849
fi
850850

851+
a=$(./scc --exclude-ext go)
852+
b=$(./scc)
853+
if [ "$a" == "$b" ]; then
854+
echo "$a"
855+
echo "$b"
856+
echo -e "${RED}======================================================="
857+
echo -e "FAILED exclude-ext check"
858+
echo -e "=================================================${NC}"
859+
exit
860+
else
861+
echo -e "${GREEN}PASSED exclude-ext check"
862+
fi
863+
851864
# Try out specific languages
852865
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 '
853866
do

0 commit comments

Comments
 (0)