Let Emoji reporter print rule identifier (#4708)

This commit is contained in:
Danny Mösch 2023-02-06 22:28:07 +01:00 committed by GitHub
parent d3ebfc5567
commit 5af4291b53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 21 deletions

View File

@ -27,6 +27,10 @@
[Ethan Wong](https://github.com/GetToSet)
[#4664](https://github.com/realm/SwiftLint/pull/4664)
* Add rule identifier to output of Emoji reporter.
[SimplyDanny](https://github.com/SimplyDanny)
[#4707](https://github.com/realm/SwiftLint/issues/4707)
* Interpret strings in `excluded` option of `identifier_name`,
`type_name` and `generic_type_name` rules as regex.
[Moly](https://github.com/kyounh12)

View File

@ -1,4 +1,4 @@
/// Reports violations in the format that's both fun and easy to read.
/// Reports violations in a format that's both fun and easy to read.
public struct EmojiReporter: Reporter {
// MARK: - Reporter Conformance
@ -10,7 +10,7 @@ public struct EmojiReporter: Reporter {
}
public static func generateReport(_ violations: [StyleViolation]) -> String {
return violations
violations
.group { $0.location.file ?? "Other" }
.sorted { $0.key < $1.key }
.map(report)
@ -20,21 +20,20 @@ public struct EmojiReporter: Reporter {
// MARK: - Private
private static func report(for file: String, with violations: [StyleViolation]) -> String {
let lines = [file] + violations.sorted { lhs, rhs in
guard lhs.severity == rhs.severity else {
return lhs.severity > rhs.severity
let issueList = violations
.sorted { $0.severity == $1.severity ? $0.location > $1.location : $0.severity > $1.severity }
.map { violation in
let emoji = violation.severity == .error ? "⛔️" : "⚠️"
var lineString = ""
if let line = violation.location.line {
lineString = "Line \(line): "
}
return "\(emoji) \(lineString)\(violation.reason) (\(violation.ruleIdentifier))"
}
return lhs.location > rhs.location
}.map { violation in
let emoji = (violation.severity == .error) ? "⛔️" : "⚠️"
let lineString: String
if let line = violation.location.line {
lineString = "Line \(line): "
} else {
lineString = ""
}
return "\(emoji) \(lineString)\(violation.reason)"
}
return lines.joined(separator: "\n")
.joined(separator: "\n")
return """
\(file)
\(issueList)
"""
}
}

View File

@ -1,6 +1,6 @@
Other
⛔️ Colons should be next to the identifier when specifying a type and next to the key in dictionary literals
⛔️ Colons should be next to the identifier when specifying a type and next to the key in dictionary literals (colon)
filename
⛔️ Line 1: Violation Reason
⛔️ Line 1: Shorthand syntactic sugar should be used, i.e. [Int] instead of Array<Int>
⚠️ Line 1: Violation Reason
⛔️ Line 1: Violation Reason (line_length)
⛔️ Line 1: Shorthand syntactic sugar should be used, i.e. [Int] instead of Array<Int> (syntactic_sugar)
⚠️ Line 1: Violation Reason (line_length)