Difference between two"Lines of code" vs "New Lines" and new code that is not recognised as new code

  • Sonar version - 10.6 (but it is not relevant to question)
  • how is SonarQube deployed: Docker (but it is not relevant to question)
  • what are you trying to achieve - clarify some mechanics on how metrics are calculated

Hi :slight_smile:
Theoretical question

Lets say I have two analyses in sonar project (only those two and nothing more).
First analysis shows 198’000 lines of code (not just lines but “lines of code”).
Second analysis shows 200’000 lines of code.
Difference is 2000 lines.
But second analysis tells there is 220 new lines.
How it can be that difference between lines of code does not equals to new lines?

What in general is list of rules and mechanisms that prevents new code being recognized as new code?

Hi,

Are you sure both of these were Lines of Code?

Because we do make a distinction between Lines (i.e. return characters) and Lines of Code, which per the docs are

The number of physical lines that contain at least one character which is neither a whitespace nor a tabulation nor part of a comment.

And BTW, we don’t have a ‘New LOC’ metric (no matter how much I wish we did.) Only New lines (return characters.)

Did the analysis scope change between the two analyses? If you still have the logs of the first and second analyses, it would be useful to compare them.

 
Ann

Hi :slight_smile:
Not sure what exactly compare there.
I was looking for one specific file that tried to compare but did not found it in log for mvn sonar:sonar call at all in any of two analysis logs.
But file itself was analyzed - it shows test coverage when I open it in sonar.

Lets get specific case.

There was line in that file like:

call.ofSomething(true);

that was changed to

if (someCondition){
call.ofSomething(true);
}

And it does not show up under new lines. Why?

If itself is new line… IS there some list of rules what is considered new line and what is not?

Hi,

This is going to be about the SCM metadata available to analysis.

See what your analysis log says about “SCM” data.

 
HTH,
Ann

This is going to be about the SCM metadata available to analysis.
See what your analysis log says about “SCM” data.

Could you please tell under which menu point and what for I should look ?

Hi,

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
HTH,
Ann

Oh sorry I misread and thought that I should look into sonar itself.
Of course I have logs.

But it is rather big, maybe you have in mind something specific that I should copy out of logs?

Lines that included scm was very few:

[INFO] 3 files ignored because of scm ignore settings

[INFO] SCM Publisher SCM provider for this project is: git
[INFO] SCM Publisher 163 source files to be analyzed
[INFO] SCM Publisher 163/163 source files have been analyzed (done) | time=4015ms

Perhaps there is some list of rules that clarifies what is considered new line and what is not?
I could not find such list.

Hi,

Normally I’d ask you to post your analysis log, but since you’re on an EOL version I really need to ask you to do the upgrade first.

It’s all based on SCM metadata and your New Code definition.

 
Ann