Unable to parse .swift file when #warning is present in code

Some of our .swift files are failing to scan because the file contains a #warning() message. The error we get is that a string cannot be parsed, but it is not the string with the warning, but instead some line after the #warning line. A simple way to repro is to create a default project and add a #warning line anywhere in the code and see if it can be scanned.

Template below
I’m not sure what to fill the template out with, but here’s the best I can do without further guidance.

  • Scanner version: 4.10.0
Task         : Run Code Analysis
Description  : Run scanner and upload the results to the SonarQube server.
Version      : 4.10.0
Author       : sonarsource
Help         : Version: 4.10.0. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)

  • Error observed
##[error]ERROR: String is not parsed (file Foo/FileWithWarning.swift, line 10)
  • Steps to reproduce
  1. Include #warning(“string doesn’t matter”) in a swift file.
  • Potential workaround: Comment out warnings as TODOs so that sonarqube picks them up, but this will lose the value of #warning in XCode
  • Scanner command used: tfs task - SonarSource.sonarqube.{GUID}.SonarQubeAnalyze@4
  • In case of SonarCloud:
    • ALM used Azure DevOps
    • CI system used Azure DevOps

Hi @wwt-Richard,

what version of swift plugin do you have installed? This was fixed in swift plugin version 4.2 https://jira.sonarsource.com/browse/SONARSWIFT-420.

A post was split to a new topic: Swift parsing error

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