mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
fcf848608e
* Add Example wrapper in order to display test failures inline when running in Xcode. * Stop using Swift 5.1-only features so we can compile on Xcode 10.2. * Wrap strings in Example. * Add Changelog entry. * Wrap all examples in Example struct. * Better and more complete capturing of line numbers. * Fix broken test. * Better test traceability. * Address or disable linting warnings. * Add documentation comments. * Disable linter for a few cases. * Limit mutability and add copy-and-mutate utility functions. * Limit scope of mutability.
50 lines
1.9 KiB
Swift
50 lines
1.9 KiB
Swift
/// Reports violations as XML conforming to the Checkstyle specification, as defined here:
|
|
/// https://www.jetbrains.com/help/teamcity/xml-report-processing.html
|
|
public struct CheckstyleReporter: Reporter {
|
|
// MARK: - Reporter Conformance
|
|
|
|
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
|
|
.group(by: { ($0.location.file ?? "<nopath>").escapedForXML() })
|
|
.sorted(by: { $0.key < $1.key })
|
|
.map(generateForViolationFile).joined(),
|
|
"\n</checkstyle>"
|
|
].joined()
|
|
}
|
|
|
|
// MARK: - Private
|
|
|
|
private static func generateForViolationFile(_ file: String, violations: [StyleViolation]) -> String {
|
|
return [
|
|
"\n\t<file name=\"", file, "\">\n",
|
|
violations.map(generateForSingleViolation).joined(),
|
|
"\t</file>"
|
|
].joined()
|
|
}
|
|
|
|
private static func generateForSingleViolation(_ violation: StyleViolation) -> String {
|
|
let line: Int = violation.location.line ?? 0
|
|
let col: Int = violation.location.character ?? 0
|
|
let severity: String = violation.severity.rawValue
|
|
let reason: String = violation.reason.escapedForXML()
|
|
let identifier: String = violation.ruleIdentifier
|
|
let source: String = "swiftlint.rules.\(identifier)".escapedForXML()
|
|
return [
|
|
"\t\t<error line=\"\(line)\" ",
|
|
"column=\"\(col)\" ",
|
|
"severity=\"", severity, "\" ",
|
|
"message=\"", reason, "\" ",
|
|
"source=\"\(source)\"/>\n"
|
|
].joined()
|
|
}
|
|
}
|