# LoC not counted correctly in SonarQube

**URL:** <https://community.sonarsource.com/t/loc-not-counted-correctly-in-sonarqube/74696>\
**Category:** SonarQube Server / Community Build\
**Created:** [October 18, 2022, 11:23am UTC](https://community.sonarsource.com/t/loc-not-counted-correctly-in-sonarqube/74696 "2022-10-18T11:23:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcin\_J](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@Marcin\_J](https://community.sonarsource.com/u/Marcin_J)\
**Post date:** [October 18, 2022, 11:23am UTC](https://community.sonarsource.com/t/loc-not-counted-correctly-in-sonarqube/74696/1 "2022-10-18T11:23:51Z")

</div>

Last month we extended our license from 250k to 500k lines of code.

Surprisingly we received today a notification that we are reaching limit of LoC (around 450k used).

But when we count a Lines of Code in current Projects it is something around 300k LoC. It is possible that this is a bug? Is there any suitable way to get the count of LoC that we are paying for ?

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [October 19, 2022, 2:23pm UTC](https://community.sonarsource.com/t/loc-not-counted-correctly-in-sonarqube/74696/2 "2022-10-19T14:23:07Z")

</div>

Hey there.

SonarQube takes into consideration the largest branch of each project. Have you checked the individual branches of each project?

---

<div class="post-metadata">

**Author:** ![Marcin\_J](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@Marcin\_J](https://community.sonarsource.com/u/Marcin_J)\
**Post date:** [October 20, 2022, 12:00pm UTC](https://community.sonarsource.com/t/loc-not-counted-correctly-in-sonarqube/74696/4 "2022-10-20T12:00:16Z")

</div>

Hello Colin,

Thank you for your reply.

I went through our Projects and It seems that when I summarize largest branches in each project there is totally around 300k LoC.

Br,  
Marcin

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [October 21, 2022, 7:03am UTC](https://community.sonarsource.com/t/loc-not-counted-correctly-in-sonarqube/74696/5 "2022-10-21T07:03:12Z")

</div>

Thanks @Marcin_J

What version are you using? There is an API endpoint in the latest version, **GET api/projects/license\_usage** , that should help instance administrators understand the LoC and branch being counted for each project.

---

<div class="post-metadata">

**Author:** ![Marcin\_J](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@Marcin\_J](https://community.sonarsource.com/u/Marcin_J)\
**Post date:** [October 21, 2022, 11:40am UTC](https://community.sonarsource.com/t/loc-not-counted-correctly-in-sonarqube/74696/6 "2022-10-21T11:40:19Z")

</div>

Hi Colin,  
Unfortunately we’ve version: \* Developer Edition

- Version 9.3 (build 51899)

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [November 3, 2022, 3:35pm UTC](https://community.sonarsource.com/t/loc-not-counted-correctly-in-sonarqube/74696/7 "2022-11-03T15:35:23Z")

</div>

In that case, I recommend upgrading to a supported version (_v9.7_)

---

<div class="post-metadata">

**Author:** ![Marcin\_J](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@Marcin\_J](https://community.sonarsource.com/u/Marcin_J)\
**Post date:** [November 4, 2022, 8:10am UTC](https://community.sonarsource.com/t/loc-not-counted-correctly-in-sonarqube/74696/8 "2022-11-04T08:10:54Z")

</div>

Hello Colin, I found other way to count LoC. I setup python script [squtilities/locbyproject.py at master · alexandre-frigout-sonarsource/squtilities · GitHub](https://github.com/alexandre-frigout-sonarsource/squtilities/blob/master/locbyproject.py)

Indeed count of LoC is much different than visible in Portal – “Total number of lines of code in your SonarQube instance: 447790”

I can see now that if Main Branch is not analyzed the LoC count is not visible:

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/7/0/70435fef10033d9aeeb91d258ac36e451fc59188.png)  
But is counted as well in License. Would be nice to have on the list counted branch visible (because this was analyzed in SonarQube).

![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/0/5/05e5c492ba1de68282795936700b4212910f9029.png)

It is implemented in newest version of SonarQube ?

Thank you for your help

Br  
Marcin

---

<div class="post-metadata">

**Author:** ![Chris](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/chris/32/71589_2.png) [@Chris](https://community.sonarsource.com/u/Chris)\
**Post date:** [November 4, 2022, 4:30pm UTC](https://community.sonarsource.com/t/loc-not-counted-correctly-in-sonarqube/74696/12 "2022-11-04T16:30:08Z")

</div>

Hi @Marcin_J,

You won’t find a change regarding that point in the latest version. The information displayed in the projects list relates only to the main branch in order to avoid bringing confusion.  
Also, please tell me if you have another perspective on the topic, but I think that in many cases the number of lines of code on the main branch is a good approximation. I’d be happy to understand why your main branch is not displayed, apart from the fact the project is quite new.

Chris
