mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
792032480e
Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org> Co-authored-by: Roman Lavrov <roman.lavrov@thebrowser.company>
34 lines
1.1 KiB
Swift
34 lines
1.1 KiB
Swift
import SourceKittenFramework
|
|
|
|
/// Reports violations in SonarQube import format.
|
|
struct SonarQubeReporter: Reporter {
|
|
// MARK: - Reporter Conformance
|
|
|
|
static let identifier = "sonarqube"
|
|
static let isRealtime = false
|
|
static let description = "Reports violations in SonarQube import format."
|
|
|
|
static func generateReport(_ violations: [StyleViolation]) -> String {
|
|
toJSON(["issues": violations.map(dictionary(for:))])
|
|
}
|
|
|
|
// MARK: - Private
|
|
|
|
// refer to https://docs.sonarqube.org/display/SONAR/Generic+Issue+Data
|
|
private static func dictionary(for violation: StyleViolation) -> [String: Any] {
|
|
[
|
|
"engineId": "SwiftLint",
|
|
"ruleId": violation.ruleIdentifier,
|
|
"primaryLocation": [
|
|
"message": violation.reason,
|
|
"filePath": violation.location.file?.relativeDisplayPath ?? "",
|
|
"textRange": [
|
|
"startLine": violation.location.line ?? 1
|
|
] as Any,
|
|
] as Any,
|
|
"type": "CODE_SMELL",
|
|
"severity": violation.severity == .error ? "MAJOR" : "MINOR",
|
|
]
|
|
}
|
|
}
|