Sonarcloud PR Analysis always having 0 line of code

I am trying to integrate my public repo in Bitbucket Cloud with Sonarcloud through Bitrise. So my current workflow is when PR is created in Bitbucket Cloud, it will trigger Bitrise to execute a Workflow where on that workflow there is Sonar Scanner step that will connect with my Sonarcloud account (Free plan).
But I always get 0 result for all indicators.
You can find my repo here : Bitbucket
And my Sonarcloud project here : https://sonarcloud.io/project/overview?id=tcaplayground

Anyone know how to fix this issues? Thank you.

Hi @khairilushan,

Can you look into the scanner logs, they should be visible on Bitrise (Your Bitrise logs are not public).
These could contain import pointers to why there is not any new code reported on your PRs.

Hi @TomVanBraband , Thanks for your reply. Here is the log on Bitrise for the sonarscanner step on my workflow

+------------------------------------------------------------------------------+

| (4) sonarqube-scanner@1                                                      |
+------------------------------------------------------------------------------+
| id: sonarqube-scanner                                                        |
| version: 1.0.9                                                               |
| collection: https://github.com/bitrise-io/bitrise-steplib.git                |
| toolkit: bash                                                                |
| time: 2021-12-19T15:53:55Z                                                   |
+------------------------------------------------------------------------------+
|                                                                              |
INFO[15:53:55]  * [OK] Step dependency (unzip) installed, available. 
INFO[15:53:55]  * [OK] Step dependency (wget) installed, available. 
INFO[15:53:55]  * [OK] Step dependency (curl) installed, available. 
/var/folders/62/0p2cg52j6r16xjxfqch4vgt40000gn/T/tmp.MpgLJy28 ~/git
--2021-12-19 15:53:57--  https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472.zip
Resolving binaries.sonarsource.com (binaries.sonarsource.com)... 91.134.125.245
Connecting to binaries.sonarsource.com (binaries.sonarsource.com)|91.134.125.245|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 589299 (575K) [application/zip]
Saving to: ‘sonar-scanner-cli-4.6.2.2472.zip’
     0K .......... .......... .......... .......... ..........  8%  163K 3s
    50K .......... .......... .......... .......... .......... 17%  328K 2s
   100K .......... .......... .......... .......... .......... 26% 33.1M 1s
   150K .......... .......... .......... .......... .......... 34%  325K 1s
   200K .......... .......... .......... .......... .......... 43% 35.6M 1s
   250K .......... .......... .......... .......... .......... 52% 41.5M 1s
   300K .......... .......... .......... .......... .......... 60% 26.2M 0s
   350K .......... .......... .......... .......... .......... 69% 52.8M 0s
   400K .......... .......... .......... .......... .......... 78%  337K 0s
   450K .......... .......... .......... .......... .......... 86% 46.4M 0s
   500K .......... .......... .......... .......... .......... 95% 65.8M 0s
   550K .......... .......... .....                           100% 25.6M=0.8s
2021-12-19 15:53:59 (747 KB/s) - ‘sonar-scanner-cli-4.6.2.2472.zip’ saved [589299/589299]
Archive:  sonar-scanner-cli-4.6.2.2472.zip
   creating: sonar-scanner-4.6.2.2472/
   creating: sonar-scanner-4.6.2.2472/bin/
   creating: sonar-scanner-4.6.2.2472/conf/
   creating: sonar-scanner-4.6.2.2472/lib/
  inflating: sonar-scanner-4.6.2.2472/bin/sonar-scanner.bat  
  inflating: sonar-scanner-4.6.2.2472/bin/sonar-scanner-debug.bat  
  inflating: sonar-scanner-4.6.2.2472/bin/sonar-scanner-debug  
  inflating: sonar-scanner-4.6.2.2472/bin/sonar-scanner  
  inflating: sonar-scanner-4.6.2.2472/conf/sonar-scanner.properties  
  inflating: sonar-scanner-4.6.2.2472/lib/sonar-scanner-cli-4.6.2.2472.jar  
~/git
INFO: Scanner configuration file: /private/var/folders/62/0p2cg52j6r16xjxfqch4vgt40000gn/T/tmp.MpgLJy28/sonar-scanner-4.6.2.2472/conf/sonar-scanner.properties
INFO: Project root configuration file: /Users/vagrant/git/sonar-project.properties
INFO: SonarScanner 4.6.2.2472
INFO: Java 11.0.11 AdoptOpenJDK (64-bit)
INFO: Mac OS X 10.16 x86_64
INFO: User cache: /Users/vagrant/.sonar/cache
INFO: Scanner configuration file: /private/var/folders/62/0p2cg52j6r16xjxfqch4vgt40000gn/T/tmp.MpgLJy28/sonar-scanner-4.6.2.2472/conf/sonar-scanner.properties
INFO: Project root configuration file: /Users/vagrant/git/sonar-project.properties
INFO: Analyzing on SonarCloud
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=855ms
INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu
INFO: User cache: /Users/vagrant/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=221ms
INFO: Load/download plugins (done) | time=108156ms
INFO: Loaded core extensions: developer-scanner
INFO: Found an active CI vendor: 'Bitrise'
INFO: Load project settings for component key: 'khairil-icehouse_tcaplayground'
INFO: Load project settings for component key: 'khairil-icehouse_tcaplayground' (done) | time=162ms
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=2ms
INFO: Project key: khairil-icehouse_tcaplayground
INFO: Base dir: /Users/vagrant/git
INFO: Working dir: /Users/vagrant/git/.scannerwork
INFO: Load project branches
INFO: Load project branches (done) | time=160ms
INFO: Check ALM binding of project 'khairil-icehouse_tcaplayground'
INFO: Detected project binding: BOUND
INFO: Check ALM binding of project 'khairil-icehouse_tcaplayground' (done) | time=151ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=161ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=669ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=207ms
INFO: Load active rules
INFO: Load active rules (done) | time=5047ms
INFO: Organization key: khairil-ushan
INFO: Pull request 2 for merge into main from test/moya-async-extension
INFO: Load project repositories
INFO: Load project repositories (done) | time=161ms
INFO: SCM collecting changed files in the branch
INFO: SCM collecting changed files in the branch (done) | time=333ms
INFO: Indexing files...
INFO: Project configuration:
INFO:   Excluded sources: **/build-wrapper-dump.json
INFO: 23 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: 3 files ignored because of scm ignore settings
INFO: Quality profile for json: Sonar way
INFO: Quality profile for swift: Sonar way
INFO: ------------- Run sensors on module khairil-icehouse_tcaplayground
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=161ms
INFO: Sensor IaC CloudFormation Sensor [iac]
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor IaC CloudFormation Sensor [iac] (done) | time=69ms
INFO: Sensor C# Project Type Information [csharp]
INFO: Sensor C# Project Type Information [csharp] (done) | time=1ms
INFO: Sensor C# Analysis Log [csharp]
INFO: Sensor C# Analysis Log [csharp] (done) | time=22ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=0ms
INFO: Sensor HTML [web]
INFO: Sensor HTML is restricted to changed files only
INFO: Sensor HTML [web] (done) | time=5ms
INFO: Sensor VB.NET Project Type Information [vbnet]
INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=1ms
INFO: Sensor VB.NET Analysis Log [vbnet]
INFO: Sensor VB.NET Analysis Log [vbnet] (done) | time=26ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=1ms
INFO: Sensor Swift Code Quality and Security [swift]
INFO: 18 source files to be analyzed
ERROR: String is not parsed (file TCAPlayground/UI/RepositoryList/RepositoryListView+Store.swift, line 128)
118: 	}
119: }
120: 
121: extension RepositoryListEnvironment {
122: 
123: 	static let live = Self(
124: 		searchRepo: { keyword in
125: 			Effect<[Repository], Error>.task {
126: 				try await GithubRepoManager.live().load(keyword)
127: 			}
128: 			.mapError { $0 as! RepositoryError }
       ^
129: 			.eraseToEffect()
130: 		},
131: 		mainQueue: .main
132: 	)
133: }
134: 
135: extension RepositoryItemEnvironment {
136: 
137: 	static let live = Self(
138: 		log: { data in
ERROR: String is not parsed (file TCAPlayground/Data/GithubRepoManager.swift, line 12)
2: //  GithubRepoManager.swift
3: //  TCAPlayground
4: //
5: //  Created by Khairil Ushan on 11/12/21.
6: //
7: 
8: import Foundation
9: import ComposableArchitecture
10: 
11: struct GithubRepoManager {
12: 	var load: (String) async throws -> [Repository]
                             ^
13: }
14: 
15: extension GithubRepoManager {
16: 
17: 	static var jsonDecoder: JSONDecoder {
18: 		let decoder = JSONDecoder()
19: 		decoder.dateDecodingStrategy = .iso8601
20: 		return decoder
21: 	}
22: 
ERROR: String is not parsed (file TCAPlayground/Utils/Extension/MoyaProvider+Concurrency.swift, line 21)
11: enum NetworkError: Error {
12: 	case jsonSerialization(Error)
13: 	case underlying(Error, code: Int?, data: Data?, response: HTTPURLResponse?)
14: }
15: 
16: extension MoyaProvider {
17: 
18: 	func requestAsync<Response>(
19: 		_ target: Target,
20: 		jsonDecoder: JSONDecoder
21: 	) async throws -> Response where Response: Codable {
            ^
22: 
23: 		try await withCheckedThrowingContinuation { continuation in
24: 
25: 			self.request(target) { result in
26: 				switch result {
27: 				case let .success(response):
28: 					do {
29: 						let f = try response.filterSuccessfulStatusCodes()
30: 						let response = try jsonDecoder.decode(Response.self, from: f.data)
31: 						continuation.resume(returning: response)
ERROR: String is not parsed (file TCAPlayground/Data/GithubLoader.swift, line 12)
2: //  GithubLoader.swift
3: //  TCAPlayground
4: //
5: //  Created by Khairil Ushan on 11/12/21.
6: //
7: 
8: import Foundation
9: import Moya
10: 
11: struct GithubLoader {
12: 	var search: (String) async throws -> SearchRepositoryResponse
                               ^
13: }
14: 
15: extension GithubLoader {
16: 
17: 	static let live = Self(
18: 		search: { keyword in
19: 			let provider = MoyaProvider<GithubEndpoint>()
20: 			let decoder = JSONDecoder()
21: 			return try await provider.requestAsync(.searchRepositories(keyword: keyword), jsonDecoder: decoder)
22: 		}
ERROR: String is not parsed (file TCAPlaygroundTests/GithubRepoManagerTest.swift, line 13)
3: //  TCAPlaygroundTests
4: //
5: //  Created by Khairil Ushan on 17/12/21.
6: //
7: 
8: import XCTest
9: @testable import TCAPlayground
10: 
11: final class GithubRepoManagerTest: XCTestCase {
12: 
13: 	func testGetingResultFromNetwork() async throws {
                                             ^
14: 
15: 		let mockRepo = [ Repository(repoId: 1, name: "test", fullName: "test", desc: "test", htmlUrl: "test", owner: nil) ]
16: 		let manager = GithubRepoManager.live(
17: 			loader: .init(search: { _ in
18: 				SearchRepositoryResponse(
19: 					totalCount: 1,
20: 					incompleteResult: false,
21: 					items: mockRepo
22: 				)
23: 			}),
ERROR: String is not parsed (file TCAPlaygroundTests/MoyaProviderRequestAsyncTest.swift, line 14)
4: //
5: //  Created by Khairil Ushan on 18/12/21.
6: //
7: 
8: import Moya
9: import XCTest
10: @testable import TCAPlayground
11: 
12: final class MoyaProviderRequestAsyncTest: XCTestCase {
13: 
14: 	func testSuccessfullySerializeResponse() async throws {
                                                   ^
15: 
16: 		let json = """
17: 		{
18: 		"total_count": 1,
19: 		"incomplete_result": false,
20: 		"items": [
21: 		  {
22: 			"id": 1,
23: 			"name": "test"
24: 		  }
INFO: 18/18 source files have been analyzed
INFO: Sensor Swift Code Quality and Security [swift] (done) | time=1832ms
INFO: Sensor Import of SwiftLint issues [swift]
INFO: Importing /Users/vagrant/deploy/swiftlint_report.json
INFO: Sensor Import of SwiftLint issues [swift] (done) | time=56ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=6ms
INFO: Sensor CSS Rules [javascript]
INFO: Sensor CSS Rules is restricted to changed files only
INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
INFO: Sensor CSS Rules [javascript] (done) | time=1ms
INFO: Sensor ThymeLeaf template sensor [securityjavafrontend]
INFO: Sensor ThymeLeaf template sensor [securityjavafrontend] (done) | time=1ms
INFO: Sensor Serverless configuration file sensor [security]
INFO: 0 Serverless function entries were found in the project
INFO: 0 Serverless function handlers were kept as entrypoints
INFO: Sensor Serverless configuration file sensor [security] (done) | time=16ms
INFO: Sensor AWS SAM template file sensor [security]
INFO: Sensor AWS SAM template file sensor [security] (done) | time=1ms
INFO: Sensor JavaSecuritySensor [security]
INFO: Reading type hierarchy from: /Users/vagrant/git/.scannerwork/ucfg2/java
INFO: Read 0 type definitions
INFO: Reading UCFGs from: /Users/vagrant/git/.scannerwork/ucfg2/java
INFO: No UCFGs have been included for analysis.
INFO: Sensor JavaSecuritySensor [security] (done) | time=5ms
INFO: Sensor CSharpSecuritySensor [security]
INFO: Reading type hierarchy from: /Users/vagrant/git/ucfg_cs2
INFO: Read 0 type definitions
INFO: Reading UCFGs from: /Users/vagrant/git/ucfg_cs2
INFO: No UCFGs have been included for analysis.
INFO: Sensor CSharpSecuritySensor [security] (done) | time=0ms
INFO: Sensor PhpSecuritySensor [security]
INFO: Reading type hierarchy from: /Users/vagrant/git/.scannerwork/ucfg2/php
INFO: Read 0 type definitions
INFO: Reading UCFGs from: /Users/vagrant/git/.scannerwork/ucfg2/php
INFO: No UCFGs have been included for analysis.
INFO: Sensor PhpSecuritySensor [security] (done) | time=0ms
INFO: Sensor PythonSecuritySensor [security]
INFO: Reading type hierarchy from: /Users/vagrant/git/.scannerwork/ucfg2/python
INFO: Read 0 type definitions
INFO: Reading UCFGs from: /Users/vagrant/git/.scannerwork/ucfg2/python
INFO: No UCFGs have been included for analysis.
INFO: Sensor PythonSecuritySensor [security] (done) | time=0ms
INFO: Sensor JsSecuritySensor [security]
INFO: Reading type hierarchy from: /Users/vagrant/git/.scannerwork/ucfg2/js
INFO: Read 0 type definitions
INFO: Reading UCFGs from: /Users/vagrant/git/.scannerwork/ucfg2/js
INFO: No UCFGs have been included for analysis.
INFO: Sensor JsSecuritySensor [security] (done) | time=1ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=25ms
INFO: CPD Executor 2 files had no CPD blocks
INFO: CPD Executor Calculating CPD for 10 files
INFO: CPD Executor CPD calculation finished (done) | time=20ms
INFO: SCM writing changed lines
INFO: SCM writing changed lines (done) | time=7ms
INFO: Analysis report generated in 332ms, dir size=198 KB
INFO: Analysis report compressed in 65ms, zip size=49 KB
INFO: Analysis report uploaded in 364ms
INFO: ANALYSIS SUCCESSFUL, you can find the results at: https://sonarcloud.io/dashboard?id=khairil-icehouse_tcaplayground&pullRequest=2
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AX3TaHAICDDsBvsPuugT
INFO: Analysis total time: 15.958 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 2:16.783s
INFO: Final Memory: 32M/110M
INFO: ------------------------------------------------------------------------
|                                                                              |
+---+---------------------------------------------------------------+----------+
| ✓ | sonarqube-scanner@1                                           | 2.4 min  |
+---+---------------------------------------------------------------+----------+

And here is the content of the sonar properties on my workflow:

sonar.sources=.
sonar.login=$SONAR_TOKEN
sonar.projectKey=khairil-icehouse_tcaplayground
sonar.swift.swiftLint.reportPaths=$SWIFTLINT_REPORT_PATH
sonar.host.url=https://sonarcloud.io
sonar.organization=$SONAR_ORGANIZATION
sonar.pullrequest.branch=$BITRISE_GIT_BRANCH
sonar.pullrequest.base=$BITRISEIO_GIT_BRANCH_DEST
sonar.pullrequest.key=$BITRISE_PULL_REQUEST
sonar.pullrequest.provider=bitbucketcloud
sonar.pullrequest.bitbucketcloud.owner=$BITBUCKET_REPO_OWNER
sonar.pullrequest.bitbucketcloud.repository=$BITBUCKET_REPO

Hey @khairilushan

SonarCloud supports Swift up to v5.3 while it appears you are using some features specific to v5.5, specifically async/await structures.

Parsing errors means the results from those files aren’t uploaded to SonarCloud – and if files including those features (which result in parsing errros) is all your PR contains… you’ll get 0 results. :frowning:

We plan on eventually support the newer language versions. I’ll ping internally to see if we can get a public card on our roadmap.

Hey there.

Support for Swift v5.5 has been added to the Coming Soon tab of the SonarCloud roadmap here.

Hi @Colin , wow thanks for the updates. Glad to hear that it’s coming soon. Hopefully that really is the case for this issue.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.