[Swift] Error when importing swiftlint report

Hi @Alexandre_Gigleux

I’m using SonarQube to analyse my Swift code and almost all is working fine so far.
I’ve only one issue importing the SwiftLint report in my SonarQube analysis.
This is my configuration:
In xCode Run Script
${PODS_ROOT}/SwiftLint/swiftlint --reporter sonarqube > ${PROJECT_DIR}/report/swiftlint.json
The file gets correctly generated in the folder.

In .swiftlint.yml:
reporter: sonarqube (but I’ve also tried with json)

In the sonar-properties.properties
sonar.swift.swiftLint.reportPaths=report/swiftlint.json

But when I run the analysis it throws the error below:

10:05:50.720 INFO: Importing /builds/mobile/dssios/report/swiftlint.json
10:05:50.729 INFO: Sensor Import of SwiftLint issues [swift] (done) | time=10ms
10:05:50.729 INFO: Sensor JaCoCo XML Report Importer [jacoco]
10:05:50.729 ERROR: No issues information will be saved as the report file can’t be read.
com.A.A.B: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
at com.A.A.K.A(Unknown Source)
at com.A.A.K.A(Unknown Source)
at com.sonar.swift.plugin.external.SwiftLintSensor.importReport(Unknown Source)
at com.sonar.swift.plugin.external.SwiftLintSensor.lambda$execute$1(Unknown Source)
at java.base/java.util.ArrayList.forEach(Unknown Source)
at com.sonar.swift.plugin.external.SwiftLintSensor.execute(Unknown Source)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:386)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:382)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:351)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.Proxy0.execute(Unknown Source) at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189) at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138) at org.sonarsource.scanner.cli.Main.execute(Main.java:112) at org.sonarsource.scanner.cli.Main.execute(Main.java:75) at org.sonarsource.scanner.cli.Main.main(Main.java:61) Caused by: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path
at com.A.A.D.D.G(Unknown Source)
at com.A.A.B.A.I.A(Unknown Source)
… 36 common frames omitted

Can you spot anything I’m doing wrong?
Thanks for your help,
Alessandro

Looking at my question I realised that my run-phase script was overriding the .swiftlint.yml setting. Therefore I changed it to be:
${PODS_ROOT}/SwiftLint/swiftlint --reporter json > ${PROJECT_DIR}/report/swiftlint.json

This seems to be a step forward because now SonarQube likes the format and does something.

But it throws other warnings:
10:17:47.593 WARN: No input file found for '/Users/[myUserName]/Development/iOS/[projectFolder][ProjectName]/Constants.swift'. No SwiftLint issues will be imported on this file.
(I’ve hidden some sensible names)
The report actually contains the absolute path to the files, hence SonarQube can’t find them.
How do I change the report to contain only relative paths?

Thanks,
Alessandro

You can check that with SwiftLint community. Or create a script which cuts out the absolute path prefix.

Same here. Did you find any solution?

Hi Vladimir,

Actually not, I’ve been busy with other things and I’ve left this problem aside.
Eventually I’ll get in contact with the SwiftLint guys, unless you’ll get there first. :slight_smile:

Alessandro

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