mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
0335f155ab
Fixes #183.
45 lines
1.2 KiB
Swift
45 lines
1.2 KiB
Swift
//
|
|
// CSVReporter.swift
|
|
// SwiftLint
|
|
//
|
|
// Created by JP Simard on 9/19/15.
|
|
// Copyright © 2015 Realm. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public struct CSVReporter: Reporter {
|
|
public static let identifier = "csv"
|
|
public static let isRealtime = false
|
|
|
|
public var description: String {
|
|
return "Reports violations as a newline-separated string of comma-separated values (CSV)."
|
|
}
|
|
|
|
public static func generateReport(violations: [StyleViolation]) -> String {
|
|
let keys = [
|
|
"file",
|
|
"line",
|
|
"character",
|
|
"severity",
|
|
"type",
|
|
"reason",
|
|
"rule_id"
|
|
]
|
|
return (keys + violations.flatMap(arrayForViolation)).joinWithSeparator(",")
|
|
}
|
|
|
|
private static func arrayForViolation(violation: StyleViolation) -> [String] {
|
|
let values: [AnyObject?] = [
|
|
violation.location.file,
|
|
violation.location.line,
|
|
violation.location.character,
|
|
violation.severity.rawValue,
|
|
violation.ruleDescription.name,
|
|
violation.reason,
|
|
violation.ruleDescription.identifier
|
|
]
|
|
return values.map({ $0?.description ?? "" })
|
|
}
|
|
}
|