Hello Swift Forums!
This is a pitch for introducing support in the Swift compiler for serializing Swift diagnostics to the Static Analysis Results Interchange Format (SARIF) v2.1.0 , a standardized JSON-based format with a rich information model for representing static analysis results.
This will facilitate integration of Swift diagnostic output with a variety of language tools and enable comprehensive diagnostic tracking via result management systems for automated code quality workflows.
I would love to hear your feedback on this proposal.
# SARIF Support for Swift Diagnostics
* Proposal: [SE-0nnn](0nnn-sarif-support-for-swift-diagnostics.md)
* Authors: [Aviral Goel](https://github.com/aviralg)
* Review Manager: TBD
* Status: **Awaiting implementation**
* Implementation: [swiftlang/swift#NNNNN](https://github.com/swiftlang/swift/pull/NNNNN)
* Experimental Feature Flag: `--sarif-log`
## Introduction
We propose introducing support in the Swift compiler for serializing Swift diagnostics to the [Static Analysis Results Interchange Format (SARIF) v2.1.0](https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.pdf), a standardized JSON-based format with a rich information model for representing static analysis results. This will facilitate integration of Swift diagnostic output with a variety of language tools and enable comprehensive diagnostic tracking via result management systems for automated code quality workflows.
This proposal is organized as follows. We begin with the **Motivation** for adding SARIF support, followed by a discussion of **Benefits** for the Open-Source Swift Community. We then describe how **Swift Diagnostics are Represented in SARIF**, providing concrete examples of the format and detailed mappings of diagnostic fields. The **Implementation Plan** outlines the architecture across three components: the Swift compiler, a new `sarif` library, and a new `swift-sarif` library. We conclude with **Future Implementation Work** that extends beyond the initial proposal and **Alternatives Considered.**
## Motivation
The Swift compiler currently emits diagnostics in [LLVM’s bitstream format](https://llvm.org/docs/BitCodeFormat.html#bitstream-format), which is not widely supported by diagnostic consumer tools such as CI systems, and the binary representation creates friction in designing these tools. SARIF is a JSON-based format for representing results from static analyzers designed specifically for consumption by tracking and reporting tools. It supports a wide variety of diagnostic metadata beyond what is currently implemented in Swift’s diagnostic bitstream representation. SARIF enjoys widespread industry adoption; major compilers, code analysis tools, development platforms, and IDEs such as MSVC, Clang, GCC, GitHub, and Visual Studio Code support SARIF. Implementing this proposal will bring the Swift compiler diagnostic reporting at par with these compilers and enable the Swift community to leverage the diagnostic analysis and visualization support of existing tools.
## Benefits
This file has been truncated. show original
11 Likes
@ecosystem-steering-group This pitch requires creation of sarif and swift-sarif repositories as explained in the Implementation Plan section. I need your sponsorship for creating these repositories.