mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
Ideally, SwiftLintCore would some day only contain components that are needed to define rules. Consequently, it would be the only bundle required to import for (external) rule development.
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.relativeFile ?? "",
|
|
"textRange": [
|
|
"startLine": violation.location.line ?? 1
|
|
] as Any,
|
|
] as Any,
|
|
"type": "CODE_SMELL",
|
|
"severity": violation.severity == .error ? "MAJOR" : "MINOR",
|
|
]
|
|
}
|
|
}
|