Customize C# LOC counter

Is there any way to customize the way lines of code are counted and reported? I am analyzing C# code and see that lines with curly brackets { } are being counted. We’ve run estimates based on a different tools LOC (using UCC) and want to switch to SonarQube. However, the differences in counts is big and we believe if these weren’t counted then we’d be aligned pretty well.


There’s no way to customize that. Would you mind detailing what changes you think should be made?


Yes, I don’t think lines with opening and closing curly brackets should be counted.
There may be a reason for that (like coverage counters) but we did a quick comparison to UCC results and found this to be the biggest difference. It bloats your code counts quite a bit too, so if you use LOC for an estimates (yes this is a horrible practice but common) you can’t compare results.

Maybe a few basic options on counting logic.


Thanks for getting back to me. To be honest, this isn’t likely to change, and certainly not in the near term. AND I’m passing this on internally.


Hello Danny,

We can debate and at the same time our definition of Lines of Code is clear in our documentation:

Lines of code ( ncloc )
Number of physical lines that contain at least one character which is neither a whitespace nor a tabulation nor part of a comment.

So it is expected that curly braces are considered as part of Lines of Code because they are not whitespace, not a tabulation, nor part of a comment.
Without the curly braces, the C# code won’t compile so they are part of the required lines to make the code do what it is supposed to do.

FYI, here how we compute Executable Lines. This “Executable Lines” metric (EL) is used in the computation of the Coverage and Line Coverage metrics.

Why do you absolutely need to be compliant with how UCC define LOC? What is your final use case?