Files
SwiftLint/Source/SwiftLintFramework/Reporters/GitHubActionsLoggingReporter.swift
T
Danny Mösch 6c1ae86eb3 Use URL for file paths throughout the code base
# Conflicts:
#	Source/SwiftLintFramework/Extensions/FileManager+SwiftLint.swift
#	Tests/IntegrationTests/ConfigPathResolutionTests.swift
2026-01-24 22:13:56 +01:00

30 lines
1.3 KiB
Swift

/// Reports violations in the format GitHub-hosted virtual machine for Actions can recognize as messages.
struct GitHubActionsLoggingReporter: Reporter {
// MARK: - Reporter Conformance
static let identifier = "github-actions-logging"
static let isRealtime = true
static let description = "Reports violations in the format GitHub-hosted virtual " +
"machine for Actions can recognize as messages."
static func generateReport(_ violations: [StyleViolation]) -> String {
violations.map(generateForSingleViolation).joined(separator: "\n")
}
// MARK: - Private
private static func generateForSingleViolation(_ violation: StyleViolation) -> String {
// swiftlint:disable:next line_length
// https://help.github.com/en/github/automating-your-workflow-with-github-actions/development-tools-for-github-actions#logging-commands
// ::(warning|error) file={relative_path_to_file},line={:line},col={:character}::{content}
[
"::\(violation.severity.rawValue) ",
"file=\(violation.location.file?.relativeFilepath ?? ""),",
"line=\(violation.location.line ?? 1),",
"col=\(violation.location.character ?? 1)::",
violation.reason,
" (\(violation.ruleIdentifier))",
].joined()
}
}