From f8f617695a10268dde4c243b260257b68e525da2 Mon Sep 17 00:00:00 2001 From: Faber92 Date: Wed, 14 Aug 2024 15:36:37 +0200 Subject: [PATCH] Add Subito custom reporter --- .../SwiftLintCore/Models/ReportersList.swift | 1 + .../Reporters/SubitoReporter.swift | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 Source/SwiftLintCore/Reporters/SubitoReporter.swift diff --git a/Source/SwiftLintCore/Models/ReportersList.swift b/Source/SwiftLintCore/Models/ReportersList.swift index 1c7d8c2ebed..9e2196f96f0 100644 --- a/Source/SwiftLintCore/Models/ReportersList.swift +++ b/Source/SwiftLintCore/Models/ReportersList.swift @@ -16,6 +16,7 @@ public let reportersList: [any Reporter.Type] = [ RelativePathReporter.self, SARIFReporter.self, SonarQubeReporter.self, + SubitoReporter.self, SummaryReporter.self, XcodeReporter.self ] diff --git a/Source/SwiftLintCore/Reporters/SubitoReporter.swift b/Source/SwiftLintCore/Reporters/SubitoReporter.swift new file mode 100644 index 00000000000..e594e910e44 --- /dev/null +++ b/Source/SwiftLintCore/Reporters/SubitoReporter.swift @@ -0,0 +1,28 @@ +/// Reports violations in the custom Subito format. +struct SubitoReporter: Reporter { + // MARK: - Reporter Conformance + + static let identifier = "subito" + static let isRealtime = true + static let description = "Reports violations in the custom Subito format." + + static func generateReport(_ violations: [StyleViolation]) -> String { + violations.map(generateForSingleViolation).joined(separator: "\n") + } + + /// Generates a report for a single violation. + /// + /// - parameter violation: The violation to report. + /// + /// - returns: The report for a single violation. + static func generateForSingleViolation(_ violation: StyleViolation) -> String { + // {error,warning} + // {full_path_to_file}{:line}{:character} + // {content} - {content} + """ + \(violation.severity.rawValue) + \(violation.location) + \(violation.ruleName) Violation - \(violation.reason) \(violation.ruleIdentifier) + """ + } +}