mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
a6c4fd98bc
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.
30 lines
1023 B
Swift
30 lines
1023 B
Swift
import Foundation
|
|
import SourceKittenFramework
|
|
|
|
/// Reports violations as a JSON array.
|
|
struct JSONReporter: Reporter {
|
|
// MARK: - Reporter Conformance
|
|
|
|
static let identifier = "json"
|
|
static let isRealtime = false
|
|
static let description = "Reports violations as a JSON array."
|
|
|
|
static func generateReport(_ violations: [StyleViolation]) -> String {
|
|
toJSON(violations.map(dictionary(for:)), options: [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes])
|
|
}
|
|
|
|
// MARK: - Private
|
|
|
|
private static func dictionary(for violation: StyleViolation) -> [String: Any] {
|
|
[
|
|
"file": violation.location.file ?? NSNull() as Any,
|
|
"line": violation.location.line ?? NSNull() as Any,
|
|
"character": violation.location.character ?? NSNull() as Any,
|
|
"severity": violation.severity.rawValue.capitalized,
|
|
"type": violation.ruleName,
|
|
"rule_id": violation.ruleIdentifier,
|
|
"reason": violation.reason,
|
|
]
|
|
}
|
|
}
|