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.66k stars 264 forks source link

Counting files with multiple extensions #531

Open gms8994 opened 3 weeks ago

gms8994 commented 3 weeks ago

Describe the bug I'm trying to use --count-as to convert file.test.js to Javascript Tests, but maybe scc is only looking at the actual extension (.js) on the files when performing this conversion.

To Reproduce

> brew update && brew upgrade scc && scc --version
scc version 3.4.0

> touch blah.test.js && scc --format csv --count-as test.js:"Javascript Tests" blah.test.js
Language,Lines,Code,Comments,Blanks,Complexity,Bytes,Files,ULOC
JavaScript,0,0,0,0,0,0,1,0

This also performs the same when using the docker image

> docker run --rm -it -v "$PWD:/pwd" ghcr.io/lhoupert/scc:master scc --format csv --count-as "test.js":"Javascript Tests" /pwd/blah.test.js
Language,Lines,Code,Comments,Blanks,Complexity,Bytes
JavaScript,0,0,0,0,0,0

Expected behavior The file and lines inside blah.test.js and any other files named like .test.js would be counted as Javascript Tests.

Desktop (please complete the following information):

boyter commented 3 weeks ago

The use of "multi" extensions is an odd one to deal with. Note that the count as you have there wouldn't work anyway because it tries to match based on the language and then the extension if possible. A custom mapping like this "Javascript Tests" would do nothing because nothing would match it

$ scc --languages | rg -i javascript
JavaScript (js,mjs)

However such a mapping could be useful and fits into the ideas I am working on in https://github.com/boyter/scc/issues/462 where you can supply a custom language type which would resolve this.

It would require more work to deal with the .test.js example you have here however but it might be worth it. I am linking the two together to keep track of it.