Files
SwiftLint/Source/SwiftLintFramework/Reporters/GitHubActionsLoggingReporter.swift
T
Zev Eisenberg fcf848608e Add Inline test failure messages (#3040)
* Add Example wrapper in order to display test failures inline when running in Xcode.
* Stop using Swift 5.1-only features so we can compile on Xcode 10.2.
* Wrap strings in Example.
* Add Changelog entry.
* Wrap all examples in Example struct.
* Better and more complete capturing of line numbers.
* Fix broken test.
* Better test traceability.
* Address or disable linting warnings.
* Add documentation comments.
* Disable linter for a few cases.
* Limit mutability and add copy-and-mutate utility functions.
* Limit scope of mutability.
2020-02-02 10:35:37 +02:00

32 lines
1.3 KiB
Swift

/// Reports violations in the format GitHub-hosted virtual machine for Actions can recognize as messages.
public struct GitHubActionsLoggingReporter: Reporter {
// MARK: - Reporter Conformance
public static let identifier = "github-actions-logging"
public static let isRealtime = true
public var description: String {
return "Reports violations in the format GitHub-hosted virtual machine for Actions can recognize as messages."
}
public static func generateReport(_ violations: [StyleViolation]) -> String {
return 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}
return [
"::\(violation.severity.rawValue) ",
"file=\(violation.location.relativeFile ?? ""),",
"line=\(violation.location.line ?? 1),",
"col=\(violation.location.character ?? 1)::",
violation.reason,
" (\(violation.ruleIdentifier))"
].joined()
}
}