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.8k stars 267 forks source link

Extra line added in ULOC #552

Closed spenserblack closed 4 weeks ago

spenserblack commented 4 weeks ago

Describe the bug

I ran scc -u and got 1 more unique line than total lines... which I don't believe should ever be possible :sweat_smile:

───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
YAML                         1         2        0         0        2          0
(ULOC)                                 3
───────────────────────────────────────────────────────────────────────────────
Total                        1         2        0         0        2          0
───────────────────────────────────────────────────────────────────────────────
Unique Lines of Code (ULOC)            3
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop (organic) $39
Estimated Schedule Effort (organic) 0.29 months
Estimated People Required (organic) 0.01
───────────────────────────────────────────────────────────────────────────────
Processed 18 bytes, 0.000 megabytes (SI)
───────────────────────────────────────────────────────────────────────────────

Based on some very simple testing, it looks like the final newline is counted towards the ULOC count.

This is surprising behavior because

  1. It looks pretty strange when you have more unique lines than total lines.
  2. The final newline is pretty common, and a default of a few editors, so users might not even be aware of it.

To Reproduce

I've got a minimal file used to generate the report above here:

- line 1
- line 2

Note that the final newline is important.

Expected behavior

2 lines, 2 total lines. I'm not really sure if all empty lines should be excluded from the ULOC count, but probably the final newline at least.

Desktop (please complete the following information):

boyter commented 4 weeks ago

Yep pretty clearly a bug. As you say the additional newline. Its one of those things I explicitly removed from the main counts, but forgot about when it came to the ULOC calculation. Ill fix it soon.

boyter commented 4 weeks ago

Pushed a fix which resolves it.

$ go run . -u examples/issue552
───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
Plain Text                   1         2        0         0        2          0
(ULOC)                                 2
───────────────────────────────────────────────────────────────────────────────
Total                        1         2        0         0        2          0
───────────────────────────────────────────────────────────────────────────────
Unique Lines of Code (ULOC)            2
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop (organic) $39
Estimated Schedule Effort (organic) 0.29 months
Estimated People Required (organic) 0.01
───────────────────────────────────────────────────────────────────────────────
Processed 18 bytes, 0.000 megabytes (SI)
───────────────────────────────────────────────────────────────────────────────

Will ensure this will make it into the next release. Thanks for reporting with a test case that makes it so easy to resolve.