boyter / scc

Sloc, Cloc and Code: scc is a very fast accurate code counter with complexity calculations and COCOMO estimates written in pure Go
MIT License
6.51k stars 255 forks source link

Feature Request: Flag for combining header and implementation files. #503

Closed bramtechs closed 1 week ago

bramtechs commented 1 week ago

Hello, if not already possible, it would be nice to have a flag that counts 'C++ Header' together with 'C++'.

$ scc core
───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
C++                         41      8676     1438       514     6724        791
C++ Header                  40      3107      603       342     2162         45

The traditional sloccount command does not make this separation and I personally prefer it that way.

$ sloccount core
SLOC    Directory   SLOC-by-Language (Sorted)
14681   core            cpp=14681

Totals grouped by language (dominant language first):
cpp:          14681 (100.00%)
boyter commented 1 week ago

This is possible now,

scc -i cpp,hpp --count-as hpp:C++ 

Where I include only C++ and its headers, but count the headers as C++.

The catch with this approach is that it uses the C++ rules for counting, so if there was a difference in how they handle quotes or such it will not be accurate, however in this case I don't think it should make a difference.

The result of the above is

$ scc -i cpp,hpp --count-as hpp:C++ 
───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
C++                          8       523       85        31      407         39
───────────────────────────────────────────────────────────────────────────────
Total                        8       523       85        31      407         39
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop (organic) $10,511
Estimated Schedule Effort (organic) 2.44 months
Estimated People Required (organic) 0.38
───────────────────────────────────────────────────────────────────────────────
Processed 13540 bytes, 0.014 megabytes (SI)
───────────────────────────────────────────────────────────────────────────────
boyter commented 1 week ago

I think I should add some form of dotfile support so people can have these sort of overrides in a single place.

bramtechs commented 1 week ago

Thank you, I've adapted my command to the following, which seems to work.

scc -i cpp,hpp,cxx,hxx,cc,hh,kt --currency-symbol € --sort lines --count-as hpp:C++,hxx:C++,hh:C++ | tee sloc.txt
───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
C++                        103     14210     2452      1118    10640       1005
Kotlin                       1       229       37         8      184         20
───────────────────────────────────────────────────────────────────────────────
Total                      104     14439     2489      1126    10824       1025
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop (organic) €329,383
Estimated Schedule Effort (organic) 9.02 months
Estimated People Required (organic) 3.24
───────────────────────────────────────────────────────────────────────────────
Processed 414641 bytes, 0.415 megabytes (SI)
───────────────────────────────────────────────────────────────────────────────