Skip to content

Commit

Permalink
Simplify error messages, xcode reporting, include xcode reporter when…
Browse files Browse the repository at this point in the history
… running the plugin from xcode
  • Loading branch information
nicorichard committed Jul 27, 2024
1 parent cdbb198 commit f703e5a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct StringCatalogLinterPlugin: BuildToolPlugin {

let arguments: [CustomStringConvertible] = [
"--config", config,
"--reporter", "xcode"
"--reporter", "xcode",
] + catalogs.map(\.path)

return [
Expand Down Expand Up @@ -115,7 +115,8 @@ extension StringCatalogLinterPlugin: XcodeBuildToolPlugin {
}

let arguments: [CustomStringConvertible] = [
"--config", config
"--config", config,
"--reporter", "xcode",
] + catalogs.map(\.path)

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ struct CommandLineReporter: Reporter {

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

let message = String(
AttributedString(
localized: "Found ^[\(validations.count) total issue](inflect: true) in ^[\(results.count) key](inflect: true)"
Expand Down
35 changes: 17 additions & 18 deletions Sources/XCStringsLint/services/Reporter/XcodeReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,31 @@ struct XcodeReporter: 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(level: .error, message)
} else {
print(level: .warning, message)
for validation in result.validations {
let message = "`\(result.key)`: \(validation.message) (\(validation.name))"
switch validation.severity {
case .error:
print(level: .error, message)
case .warning:
print(level: .warning, message)
}
}
}

let validations = results.flatMap { result in
result.validations
}

let errors = validations.filter { $0.severity == .error }

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

extension [Validator.Validation] {
fileprivate var errorCount: Int {
flatMap(\.validations)
.filter { $0.severity == .error }
.count
}
}

extension XcodeReporter {
private func print(level: XcodeTag.Level, _ message: String) {
print(tag(level: level, message))
Expand Down

0 comments on commit f703e5a

Please sign in to comment.