|
| 1 | +/// Reports violations in the custom Subito format. |
| 2 | +struct SubitoReporter: Reporter { |
| 3 | + // MARK: - Reporter Conformance |
| 4 | + |
| 5 | + static let identifier = "subito" |
| 6 | + static let isRealtime = false |
| 7 | + static let description = "Reports violations in the custom Subito format." |
| 8 | + |
| 9 | + static func generateReport(_ violations: [StyleViolation]) -> String { |
| 10 | + violations |
| 11 | + .group { $0.location.file ?? "Other" } |
| 12 | + .sorted { $0.key < $1.key } |
| 13 | + .map(report) |
| 14 | + .joined(separator: "\n\n") |
| 15 | + } |
| 16 | + |
| 17 | + /// Generates a report for a single violation. |
| 18 | + /// |
| 19 | + /// - parameter violation: The violation to report. |
| 20 | + /// |
| 21 | + /// - returns: The report for a single violation. |
| 22 | + private static func report(for file: String, with violations: [StyleViolation]) -> String { |
| 23 | + // {emoji} {error,warning} |
| 24 | + // {full_path_to_file}{:line}{:character} |
| 25 | + // {content} - {content} |
| 26 | + violations |
| 27 | + .sorted { $0.severity == $1.severity ? $0.location > $1.location : $0.severity > $1.severity } |
| 28 | + .map { violation in |
| 29 | + let emoji, severityColor: String, locationColor = "\u{001B}[0;36m", resetColor = "\u{001B}[0;0m" |
| 30 | + switch violation.severity { |
| 31 | + case .error: |
| 32 | + emoji = "⛔️" |
| 33 | + severityColor = "\u{001B}[0;31m" |
| 34 | + case .warning: |
| 35 | + emoji = "⚠️" |
| 36 | + severityColor = "\u{001B}[0;33m" |
| 37 | + } |
| 38 | + return """ |
| 39 | + \(emoji) \(severityColor)\(violation.severity.rawValue)\(resetColor) |
| 40 | + \(locationColor)\(violation.location)\(resetColor) |
| 41 | + \(violation.ruleName) Violation - \(violation.reason) \(violation.ruleIdentifier) |
| 42 | + """ |
| 43 | + } |
| 44 | + .joined(separator: "\n\n") |
| 45 | + } |
| 46 | +} |
0 commit comments