In this section:

Introduction

Parasoft supports Swift by integrating with SwiftLint, an open source static analysis tool for Swift source code. SwiftLint reports issues related to Swift programming style and conventions. Refer to the SwiftLint documentation for a more detailed description: https://github.com/realm/SwiftLint

The Parasoft SwiftLint extension processes the result file output from your open source static analysis tool, generates reports showing violations and severities for the code authors, and sends the data to Parasoft DTP. DTP presents the data in widgets, reports, and other interfaces that enable you to prioritize violations, place them into remediation workflows, and monitor progress toward improving the code quality. 

Requirements

  • SwiftLint version 0.45.0 is currently supported.
  • Supported operating systems: macOS, Linux.
  • The JAVA_HOME environment variable must be set and pointing to your Java installation folder.
  • SwiftLint should be installed, successfully running analysis, and producing XML reports in Checkstyle format. Refer to the Checkstyle documentation for details about the format: http://checkstyle.sourceforge.net/project-reports.html.

    Specify the following reporter property in your .swiftlint.yml settings file to enforce the Checkstyle output format:

    reporter: "checkstyle"

    Refer to the SwiftLint documentation (https://github.com/realm/SwiftLint) for details about SwiftLint settings.

    Example command to run SwiftLint execution and generate results to report.xml file:

    >> swiftlint > report.xml

Known Limitation

Some rules in SwiftLint have two possible severities. Depending on the case, the violation may either have an "error" or "warning" severity. For such rules, these violations will have one specific "error" severity after processing with Parasoft SwiftLint extension.

Usage

  1. If you have not already done so, execute SwiftLint and verify that the results are output to a file in Checkstyle format.
  2. Open a command prompt and navigate to the Multi-Language Pack installation directory.
  3. Execute the multilanguage-pack.bat or multilanguage-pack.sh script with the required parameters all on one line, e.g.:
multilanguage-pack.sh -tool SwiftLint -results.file "c:\sample\swiftlint-results.xml" -source.dir "C:\sample\sampleProjectFolder"

Internal technical log files from the Multi-Language Pack execution are generated in the <INSTALL>/.mlp subdirectory.

Required Parameters

The following parameters are required.

tool

This parameter specifies the Parasoft extension to execute. Use -tool SwiftLint to run the SwiftLint extension.

results.file

Path to the SwiftLint analysis results file. 

source.dir

Specifies the path to the folder containing the original Swift code that has been analyzed by SwiftLint. This is used to collect source control metadata (e.g., authorship, last updated, etc.) for DTP reporting and processing.

Jump-start Example

This simple example is designed to help you quickly run the SwiftLint Parasoft Extension. It uses a very simple sample of Swift source code and SwiftLint results. You can follow this example if you do not yet have Swift and SwiftLint.

About the Example

Refer to the following script:

example\swiftlint\swiftlint-analyzer.sh.

The script runs multilanguage-pack.sh with the following settings:

-tool SwiftLint

-results.file example/swiftlint/checkstyle.xml

-source.dir example/swiftlint/src

Before running the script, set the DTP properties in the settings file as described in the Configuration chapter.

Running the Example

Run the script example\swiftlint\swiftlint-analyzer.sh.

After execution, a Parasoft report.xml file and a report.html file will be generated. The results will also be sent to DTP.

  • No labels