flosse / sloc

simple tool to count SLOC (source lines of code)
MIT License
943 stars 84 forks source link

Consistency check? physical = source + comment + empty? #90

Closed manatarms closed 6 years ago

manatarms commented 7 years ago

I wanted to make sure I wasn't losing my mind. I wanted to confirm if the total physical lines of code should = source + comment + empty? I am getting results where it does not. Does that mean something is wrong, or am I assuming something here? Thanks!

zwrawr commented 6 years ago

Based on my repo, it looks like mixed lines get counted as comments and source code (which makes sense). But even when i account for that it doesn't match up exactly.
physical ~= source + comment - mixed + empty is two lines off for my repo.

flosse commented 6 years ago

Would you mind to write a testcase?

flosse commented 6 years ago

FYI: #99

zwrawr commented 6 years ago

Figured it out from looking at source.

The equation in the source is source = total - comment - empty + blockEmpty + mixed Which is source = physical - comment - empty + empty_lines_in_block_comments + mixed

Empty lines in block comments contribute to the number of block comment lines and the number of empty lines (similar to how mixed works) so we need to add the number back on to stop them being counted twice.

The output looked wrong because the formatter doesn't output the number of empty lines in block comments, but sloc was working fine.