Files
Danny Mösch 6c1ae86eb3 Use URL for file paths throughout the code base
# Conflicts:
#	Source/SwiftLintFramework/Extensions/FileManager+SwiftLint.swift
#	Tests/IntegrationTests/ConfigPathResolutionTests.swift
2026-01-24 22:13:56 +01:00

30 lines
1.0 KiB
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?.path ?? 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,
]
}
}