My numbers don't add up

Community Edition Version 7.9.1 (build 27448)
sonar-scanner-msbuild-4.7.1.2311-net46
JetBrains dotCover Console Runner 2019.3.1. Build 777.0.20191219.94806

What I did:

Created a brand new project on SonarQube for my repo X. I have run an analysis on the last two release tags of my repo. I specified both a version and a project date as parameters of by begin SonarScanner.MSBuild.exe call.

# tag 1 
/v:"2.1" /d:sonar.projectDate=2019-12-12
# tag2:
/v:"2.2" /d:sonar.projectDate=2020-03-20

Both analyses are shown on SonarQube just fine.

What I’m trying to do:

I’m trying to understand the information provided by the tool.

  1. If I click on Measures, Size, it shows only 194 New Lines in yellow. But, if I then go to Activity (where I see my two versions listed) and select Custom and add Lines of code from the add metric dropdown; I can see a difference of almost 2k lines in the Lines of code graph. Why is it then showing only 194 New Lines in yellow on Measures?

  2. Back on Overview I can see New code since the previous version, started 4 months ago in yellow. Coverage shows only 75 New Lines to Cover - We definitely have way more new code than this.

I appreciate your help. I’m happy to provide any additional information needed.

Hi,

Welcome to the community!

How about some screenshots. It will (hopefully!) be a lot easier to understand/diagnose if we can see what you’re seeing.

 
Ann

1 Like

Images uploaded for sharing. The forum is not letting me upload more than 1 picture per post (I’m a newbie).




Ann’s edit to add the images:

Hi,

I’ve edited your post to include your images. Thanks for your persistence and ingenuity despite the newbie limitations imposed on you!

TBH, I was hoping to see something obvious in your screenshots that I could easily explain away. … I don’t. I’m going to call for backup. Hopefully, we’ll have a simple explanation soon.

 
Ann

Hi,
With the default New Code Period set to “last version”, you started a new code period with that analysis of v2.2 with the date 2020.03.20. So all lines of code with a modification date after that date will be considered to be “new code”. The modification date is usually collected from the SCM blame information.

The label about it started 4 months ago is probably incorrect (that’s the start of the previous version and doesn’t correspond to the new code period that just started) and I believe it has been corrected in recent releases.

To confirm this, click on the new lines, find the lines highlighted as “new” and click on the bar at the right to see the blame information for that line. It should always be after 2020-03-20.

To sum up, there is a net difference of 2k lines of code between both snapshots analyzed while there are 194 lines in the 2nd analysis that have a change date reported by the SCM after 2020-03-20.

Thank you for your explanation. It does clarify the numbers a bit. If I understood correctly, the yellow information (“new” stuff) is based on the delta between the date of the last code period, in my case 2020-03-12, and SCM (git in this case) commit date on blame. Correct?

Unfortunately, this check is not following your suggestion. The first three files I checked have yellow lines that have commit dates prior to 2020-03-12.

PS: I know I previously said 2020-03-20 with version 2.2; those were made up numbers to simplify the example. When I was asked to upload screen-shots I had no other option than just to upload real screenshots from my instance so, hence the variation on the dates and versions.

Hi,

Thank you for your explanation. It does clarify the numbers a bit. If I understood correctly, the yellow information (“new” stuff) is based on the delta between the date of the last code period, in my case 2020-03-12, and SCM (git in this case) commit date on blame. Correct?
That’s correct.

Unfortunately, this check is not following your suggestion. The first three files I checked have yellow lines that have commit dates prior to 2020-03-12.

Ok, I think that has changed in the latest versions. I just did a test with v7.9.
The “new code period”, has shown in the screenshots, has probably started on Dec 18th with v4.69.5. So the label “Started 4 months ago” is correct. As soon as you do another analysis with v4.70.0.4 it will change to March 12th.

Does that make sense, looking at the commit dates you see for white and yellow lines?

So coming back to your initial concerns, I understand that you expected more “new lines” and that you see an inconsistency with the difference in lines of code between both analysis.
One possible explanation is that the code that was analyzed with each analysis doesn’t correspond to the dates provided with “sonar.projectDate”.

What would make sense to add as project date? the date of the last commit of the version (when the version ended)? Or maybe the date of the first commit of the version (aka, when the version started)?

I’m trying to feed my new project with the analysis of the last 3 versions we have released (4.69.5 - 4.70.0.4 and 4.71.0), to have “memory” then I plan to run daily analysis on the codebase (now 4.72.0 is in development).

What would make sense to add as project date? the date of the last commit of the version (when the version ended)? Or maybe the date of the first commit of the version (aka, when the version started)?

The date of the last commit would be fine. You could than compare what SQ shows with what you get with git diff.