Files
SwiftLint/Source/SwiftLintFramework/Reporters/CheckstyleReporter.swift
T
JP Simard 39e1001629 make lots of Swift 3 related changes
many of which are to help with otherwise very long compile times
2016-12-01 00:34:29 -08:00

43 lines
1.3 KiB
Swift

//
// CheckstyleReporter.swift
// SwiftLint
//
// Created by JP Simard on 12/25/15.
// Copyright © 2015 Realm. All rights reserved.
//
import Foundation
public struct CheckstyleReporter: Reporter {
public static let identifier = "checkstyle"
public static let isRealtime = false
public var description: String {
return "Reports violations as Checkstyle XML."
}
public static func generateReport(_ violations: [StyleViolation]) -> String {
return [
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<checkstyle version=\"4.3\">",
violations.map(generateForSingleViolation).joined(),
"\n</checkstyle>"
].joined()
}
private static func generateForSingleViolation(_ violation: StyleViolation) -> String {
let file: String = violation.location.file ?? "<nopath>"
let line: Int = violation.location.line ?? 0
let col: Int = violation.location.character ?? 0
let severity: String = violation.severity.rawValue.lowercased()
let reason: String = violation.reason
return [
"\n\t<file name=\"", file, "\">\n",
"\t\t<error line=\"\(line)\" ",
"column=\"\(col)\" ",
"severity=\"", severity, "\" ",
"message=\"", reason, "\"/>\n",
"\t</file>"
].joined()
}
}