mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
05ac3c9d75
This will unblock using Swift Concurrency features and updating to the latest versions of Swift Argument Parser. This won't drop support for linting projects with an older toolchain / Xcode selected, as long as SwiftLint was _built_ with 5.6+ and is _running_ on macOS 12+. So the main breaking change for end users here is requiring macOS 12 to run. However, the upside to using Swift Concurrency features is worth the breaking change in my opinion. Also being able to stay on recent Swift Argument Parser releases.
56 lines
1.8 KiB
Swift
56 lines
1.8 KiB
Swift
#if canImport(CryptoSwift)
|
|
import CryptoSwift
|
|
#endif
|
|
import Foundation
|
|
import SourceKittenFramework
|
|
|
|
/// Reports violations as a JSON array in Code Climate format.
|
|
public struct CodeClimateReporter: Reporter {
|
|
// MARK: - Reporter Conformance
|
|
|
|
public static let identifier = "codeclimate"
|
|
public static let isRealtime = false
|
|
|
|
public var description: String {
|
|
return "Reports violations as a JSON array in Code Climate format."
|
|
}
|
|
|
|
public static func generateReport(_ violations: [StyleViolation]) -> String {
|
|
return toJSON(violations.map(dictionary(for:)))
|
|
.replacingOccurrences(of: "\\/", with: "/")
|
|
}
|
|
|
|
// MARK: - Private
|
|
|
|
private static func dictionary(for violation: StyleViolation) -> [String: Any] {
|
|
return [
|
|
"check_name": violation.ruleName,
|
|
"description": violation.reason,
|
|
"engine_name": "SwiftLint",
|
|
"fingerprint": generateFingerprint(violation),
|
|
"location": [
|
|
"path": violation.location.relativeFile ?? NSNull() as Any,
|
|
"lines": [
|
|
"begin": violation.location.line ?? NSNull() as Any,
|
|
"end": violation.location.line ?? NSNull() as Any
|
|
]
|
|
],
|
|
"severity": violation.severity == .error ? "MAJOR" : "MINOR",
|
|
"type": "issue"
|
|
]
|
|
}
|
|
|
|
internal static func generateFingerprint(_ violation: StyleViolation) -> String {
|
|
let fingerprintLocation = Location(
|
|
file: violation.location.relativeFile,
|
|
line: violation.location.line,
|
|
character: violation.location.character
|
|
)
|
|
|
|
return [
|
|
"\(fingerprintLocation)",
|
|
"\(violation.ruleIdentifier)"
|
|
].joined().sha256()
|
|
}
|
|
}
|