Files
SwiftLint/Source/SwiftLintFramework/Reporters/Reporter.swift
T
Danny Mösch a6c4fd98bc Move files from SwiftLintCore to SwiftLintFramework
Ideally, SwiftLintCore would some day only contain components
that are needed to define rules. Consequently, it would be the
only bundle required to import for (external) rule development.
2024-12-23 12:51:43 +01:00

44 lines
1.5 KiB
Swift

/// An interface for reporting violations as strings.
public protocol Reporter: CustomStringConvertible {
/// The unique identifier for this reporter.
static var identifier: String { get }
/// Whether or not this reporter can output incrementally as violations are found or if all violations must be
/// collected before generating the report.
static var isRealtime: Bool { get }
/// A more detailed description of the reporter's output.
static var description: String { get }
/// For CustomStringConvertible conformance.
var description: String { get }
/// Return a string with the report for the specified violations.
///
/// - parameter violations: The violations to report.
///
/// - returns: The report.
static func generateReport(_ violations: [StyleViolation]) -> String
}
extension Reporter {
/// For CustomStringConvertible conformance.
var description: String { Self.description }
}
/// Returns the reporter with the specified identifier. Traps if the specified identifier doesn't correspond to any
/// known reporters.
///
/// - parameter identifier: The identifier corresponding to the reporter.
///
/// - returns: The reporter type.
public func reporterFrom(identifier: String?) -> any Reporter.Type {
guard let identifier else {
return XcodeReporter.self
}
guard let reporter = reportersList.first(where: { $0.identifier == identifier }) else {
queuedFatalError("No reporter with identifier '\(identifier)' available.")
}
return reporter
}