Skip to content

Commit

Permalink
Add Subito custom reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Faber92 committed Sep 4, 2024
1 parent 70f1110 commit d45fbde
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions Source/SwiftLintCore/Models/ReportersList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public let reportersList: [any Reporter.Type] = [
RelativePathReporter.self,
SARIFReporter.self,
SonarQubeReporter.self,
SubitoReporter.self,
SummaryReporter.self,
XcodeReporter.self,
]
46 changes: 46 additions & 0 deletions Source/SwiftLintCore/Reporters/SubitoReporter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/// Reports violations in the custom Subito format.
struct SubitoReporter: Reporter {
// MARK: - Reporter Conformance

static let identifier = "subito"
static let isRealtime = false
static let description = "Reports violations in the custom Subito format."

static func generateReport(_ violations: [StyleViolation]) -> String {
violations
.group { $0.location.file ?? "Other" }
.sorted { $0.key < $1.key }
.map(report)
.joined(separator: "\n\n")
}

/// Generates a report for a single violation.
///
/// - parameter violation: The violation to report.
///
/// - returns: The report for a single violation.
private static func report(for file: String, with violations: [StyleViolation]) -> String {
// {emoji} {error,warning}
// {full_path_to_file}{:line}{:character}
// {content} - {content}
violations
.sorted { $0.severity == $1.severity ? $0.location > $1.location : $0.severity > $1.severity }
.map { violation in
let emoji, severityColor: String, locationColor = "\u{001B}[0;36m", resetColor = "\u{001B}[0;0m"
switch violation.severity {
case .error:
emoji = "⛔️"
severityColor = "\u{001B}[0;31m"
case .warning:
emoji = "⚠️"
severityColor = "\u{001B}[0;33m"
}
return """
\(emoji) \(severityColor)\(violation.severity.rawValue)\(resetColor)
\(locationColor)\(violation.location)\(resetColor)
\(violation.ruleName) Violation - \(violation.reason) \(violation.ruleIdentifier)
"""
}
.joined(separator: "\n\n")
}
}

0 comments on commit d45fbde

Please sign in to comment.