Skip to content

Commit

Permalink
Command line print formatting improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
nicorichard committed Jul 27, 2024
1 parent e6053e9 commit f90d278
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ extension Rules {
value.stringUnits.compactMap {
if !states.contains($0.state) {
if states.count == 1 {
return String(localized: "found state `\($0.state)`, expected one of \(states.joined(separator: ", "))", bundle: .module)
return String(localized: "found state `\($0.state)`, expected `\(states[0])`", bundle: .module)
} else {
return String(localized: "found state `\($0.state)`, expected \(states[0])", bundle: .module)
return String(localized: "found state `\($0.state)`, expected one of: \(states.map { "`\($0)`" }.joined(separator: ", "))", bundle: .module)
}
}
return nil
Expand Down
40 changes: 25 additions & 15 deletions Sources/XCStringsLint/services/Reporter/CommandLineReporter.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import StringCatalogValidator
import ArgumentParser
import Foundation

struct CommandLineReporter: Reporter {
private let print: Printer
Expand All @@ -15,28 +16,37 @@ struct CommandLineReporter: Reporter {

func report(results: [Validator.Validation]) throws {
for result in results {
let message = "xcstringslint failed for key `\(result.key)`: " + result.validations.map { validation in
"\(validation.message) (\(validation.name))"
}.joined(separator: "; ")

if result.validations.map(\.severity).contains(.error) {
print(message)
} else {
print(message)
print("`\(result.key)`:")
for validation in result.validations {
print(" \(validation.severity.symbol) \(validation.name): \(validation.message)")
}
}

let validations = results.flatMap { result in
result.validations
}
let validations = results.flatMap(\.validations)
let errorCount = validations.filter { $0.severity == .error }.count

let errors = validations.filter { $0.severity == .error }
let message = String(
AttributedString(
localized: "Found ^[\(validations.count) total issue](inflect: true) in ^[\(results.count) key](inflect: true)"
).characters
)

if !errors.isEmpty {
print("Found \(results.count) total xcstringlint issues in \(results.count) keys, \(errors.count) serious")
if errorCount > 0 {
print(message + ", \(errorCount) serious")
throw ExitCode.failure
} else if !results.isEmpty {
print("Found \(results.count) total xcstringlint issues in \(results.count) keys")
print(message)
}
}
}

extension Severity {
fileprivate var symbol: String {
switch self {
case .error:
return ""
case .warning:
return "⚠️"
}
}
}

0 comments on commit f90d278

Please sign in to comment.