Skip to content

Commit de51d63

Browse files
committed
Add Subito custom reporter
1 parent 13e38df commit de51d63

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

Source/SwiftLintFramework/Models/ReportersList.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public let reportersList: [any Reporter.Type] = [
1515
RelativePathReporter.self,
1616
SARIFReporter.self,
1717
SonarQubeReporter.self,
18+
SubitoReporter.self,
1819
SummaryReporter.self,
1920
XcodeReporter.self,
2021
]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)