Lines of Code
In SonarQube, the number of Lines of Code (LOC) you plan on analyzing plays an important role in your choice of subscription plan. Your LOC consumption is relevant only for Commercial Editions (Developer, Enterprise, and Data Center). Commercial Support is included with some plans; see the Sonar Plans and Pricing page for more details.
Lines of code (
ncloc) refers to the number of physical lines that contain at least one character which is neither a whitespace, nor a tabulation, nor part of a comment.
Go to Administration > Configuration > License Manager to check how many lines of code you are currently using. Select Edit notification threshold to define when an email should be sent with information in regards to the impending lines of code limit. You cannot exceed your LOC threshold. If you're near your limit, you may need to purchase additional lines of code.
You can check your LOC per project, per branch, in three different locations:
- Select Project Information to reveal the LOC on your main branch (for that project). Note that this may not exactly be your max LOC, for example, another branch or PR might have more lines of code.
- Navigate to the Your Project > Measures > Size page via the UI for a list of folders & files with a count of each folders’ and files’ LOC.
- Navigate to Your Project > Code page for a list of folders & files with a count of each folders’ and files’ LOC.
Lines of code found in an application do not count against your subscription’s LOC. This is because Applications aggregate code from projects, and we already count the LOC once for the "parent" project.
Once you are near your limit, you will receive a notification with advice to upgrade your current subscription plan to a higher LOC limit, or to reduce the number of LOC in your projects. On the License Manager page, select the Edit notification threshold button to define when notifications will be sent.
If you reach your limit, you will receive an error message and the SonarQube instance will stop accepting new analyses which will make the LOC exceed the limit defined by the license.
If you reach your limit, you will receive an error message and the SonarQube instance will reject any analysis whose total lines of code exceed the limit defined by your license. In no way does this affect access to basic functionalities such as saving configuration changes and allowing project browsing. In all cases, you can still analyze your code if the new analysis doesn't surpass the LOC limit defined by your license.
Lines of code are calculated by summing the LOC of each project analyzed. The LOCs that are counted are those found on the largest branch of the project. If you have set up branch analysis, then the LOC will be counted from the most recent analysis of the project with the largest branch or PR. This means that if your main branch for whatever reason does not contain any LOC, then the largest branch (or PR) will be counted instead.
- If a project has 500 lines of code on its main branch and 400 on a secondary branch, then the number of LOCs counted for the project is 500.
- If a project has 500 lines of code on its main branch and a PR is issued with 540 lines of code, then the number of LOCs counted for the project is 540.
- If a project has 0 lines of code on its main branch (provisioned but never analyzed) and 200 on a secondary branch, then the number of LOCs counted is 200.
Typically, the simple formula for calculating your lines of code is by adding:
- Project 1 LOC + Project 2 LOC + Project 3 LOC = Total LOC
SonarQube’s Data Center Edition doesn’t behave any differently. Whatever the number of nodes in the cluster, the LOC from each project are summed up.
Now that it’s clear that LOC is calculated from your largest branch, it’s important to note that your lines of test code do not count toward your License Usage.
There are a number of exceptions to take into account when calculating your LOC:
- Lines of test code do not count as LOC.
- Files excluded from analysis are not counted. See the page on setting your Analysis scope for more details about file exclusions.
- Code in unsupported languages does not count as LOC. However, if you run a 3rd party plugin that introduces support (for that language), the newly analyzed code will be counted towards your LOC.
- Comments or blank lines do not count as LOC.
- You can’t use up your license by reanalyzing the same code (with the same number of lines).
For more details on subscription plans and what’s included with your plan, see our Plans & Pricing page.
© 2008-2023, SonarSource S.A, Switzerland. Except where otherwise noted, content in this space is licensed under a Creative Commons Attribution-NonCommercial 3.0 United States License. SONARQUBE is a trademark of SonarSource SA. All other trademarks and copyrights are the property of their respective owners.