-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #945 from realm/feature/emoji_reporter
Emoji reporter
- Loading branch information
Showing
8 changed files
with
87 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// EmojiReporter.swift | ||
// SwiftLint | ||
// | ||
// Created by Michał Kałużny on 01/12/2016. | ||
// Copyright © 2016 Realm. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct EmojiReporter: Reporter { | ||
public static let identifier = "emoji" | ||
public static let isRealtime = false | ||
|
||
public var description: String { | ||
return "Reports violations in the format that's both fun and easy to read." | ||
} | ||
|
||
public static func generateReport(_ violations: [StyleViolation]) -> String { | ||
return violations.group { violation in | ||
violation.location.file ?? "Other" | ||
}.map(reportFor).joined(separator: "\n") | ||
} | ||
|
||
private static func reportFor(file: String, with violations: [StyleViolation]) -> String { | ||
let lines = [file] + violations.sorted(by: { lhs, rhs in | ||
guard lhs.severity == rhs.severity else { | ||
return lhs.severity > rhs.severity | ||
} | ||
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters