Clarification on SonarQube Cloud File Analysis Criteria and LOC Consumption

Hi,

  1. I am currently using the SonarQube Cloud Team Plan. For our .NET project, I am using GitHub Actions with the analysis configuration provided by SonarQube. However, I noticed that not all files in the repository appear in SonarQube. For example, files such as package.json do not seem to be displayed as analyzed code. Could you please explain how the Sonar Scanner determines which files are analyzed and uploaded to SonarQube Cloud?

  2. Additionally, our subscription currently has a limit of 100K Lines of Code (LOC). If we have three projects that collectively consume approximately 56K LOC and we later delete one of those projects, will the corresponding LOC be released and made available for reuse? Or is LOC consumption calculated differently?

Thank you for your assistance.

Hi @izyanyasmin,

Could you please explain how the Sonar Scanner determines which files are analyzed and uploaded to SonarQube Cloud?

SonarScanner creates a list of all files in the current working directory (or directory set by sonar.projectBaseDir), then filters out any files that arn’t in the analysis scope. If you set sonar.sources=src, then only files in the src/ dir will be in the analysis scope – for a typical Node project, this would exclude the package.json from the analysis scope.

If we have three projects that collectively consume approximately 56K LOC and we later delete one of those projects, will the corresponding LOC be released and made available for reuse?

Yes. That’s correct.

Based on the GitHub Actions scan log and SonarCloud Code view, the analysis does not appear to be restricted to src. Root level files such as package.json, package-lock.json, and global.json were indexed, and SonarCloud Code section also displays content outside src (e.g. .github/workflows, nuget.config).

We also do not currently have any exclusion rules configured that would intentionally limit the scan to src.

Given this, I believe the scan starts from the repository root and includes files outside src. Could you help clarify how SonarCloud determines which indexed files are ultimately displayed in the Code view?

What language were they indexed as? If its text, then they were scanned for secrets, but no code analysis was performed.

Files scanned for secrets that don’t contain code or a secret aren’t displayed in the UI.

Analysis of files that don’t contain code

Files that don’t contain code (for example, build.gradle and sonar-project.properties) are scanned durning analysis and displayed in the SonarQube Server UI after an issue is detected in them. If no secrets are detected in those files, they are not displayed in the UI.

JSON analysis is available in SonarQube Cloud; however, it is behind a feature flag, which might not be enabled for your organization.

The analysis of JSON files is enabled for some organizations via a feature flag and will soon be enabled by default for all users. If you want to manually opt-in, you can set the sonar.featureflag.cloud-security-enable-generic-yaml-and-json-analyzer property to true.

By setting the above mentioned property to false, you can also opt-out of the analysis during this roll-out phase.

You can permanently disable the analysis by setting the sonar.json.activate property to false.

These properties do not affect analysis of language / framework specific YAML files.

In addition to this general JSON analysis, JSON files that are detected as belonging to the CloudFormation or Azure Resource Manager language-types are also analyzed by the dedicated analyzers.

Language-specific properties

To discover and update the JSON-specific properties, navigate in SonarQube Cloud to Your Project > Administration > General Settings > Languages > JSON. See Configuration overview for more information about setting properties.

Hi Austin,

I checked our project settings and JSON analysis is enabled.

From the scanner logs, package.json, global.json and several other configuration files are indexed during analysis, and are indexed with language json. However, these files do not appear in the SonarQube Cloud UI.

I also noticed that package.json is included in the default JSON exclusion list, so its behavior may be expected. However, global.json is not excluded and is also indexed as json, yet it does not appear in the UI.

On the other hand, pipeline-related files such as ci.yml and build.yml do appear in the UI.

My assumption is that this may be related to the nature of the files, where configuration files such as global.json are treated differently from pipeline/workflow files that contain executable build logic.

Is it expected that configuration files indexed as json does not appear in UI when no issues are detected, even when JSON analysis is enabled?