// // HTMLReporter.swift // SwiftLint // // Created by Johnykutty on 10/27/16. // Copyright © 2016 Realm. All rights reserved. // import Foundation public struct HTMLReporter: Reporter { public static let identifier = "html" public static let isRealtime = false public var description: String { return "Reports violations as HTML" } // swiftlint:disable function_body_length public static func generateReport(violations: [StyleViolation]) -> String { // swiftlint:enable function_body_length var rows = "" for (index, violation) in violations.enumerate() { rows += generateSingleRow(for: violation, at: index + 1) } let bundle = NSBundle(identifier: "io.realm.SwiftLintFramework")! let version = bundle.objectForInfoDictionaryKey("CFBundleShortVersionString") let v = (version as? String ?? "0.0.0") let files = violations.map { violation in violation.location.file ?? "" } let uniqueFiles = Set(files) let warnings = violations.filter { violation in violation.severity == .Warning } let errors = violations.filter { violation in violation.severity == .Error } let formatter = NSDateFormatter() formatter.dateStyle = .ShortStyle let dateString = formatter.stringFromDate(NSDate()) return "\n" + "\n" + "\t
\n" + "\t\t| \n" + "\t\t\t\t\t\tSerial No.\n" + "\t\t\t\t\t | \n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\tFile\n" + "\t\t\t\t\t | \n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\tLocation\n" + "\t\t\t\t\t | \n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\tSeverity\n" + "\t\t\t\t\t | \n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\tMessage\n" + "\t\t\t\t\t | \n" + "\t\t\t\t
|---|
| Total files with violations | \n" + "\t\t\t\t\t\(uniqueFiles.count) | \n" + "\t\t\t\t
| Total warnings | \n" + "\t\t\t\t\t\(warnings.count) | \n" + "\t\t\t\t
| Total errors | \n" + "\t\t\t\t\t\(errors.count) | \n" + "\t\t\t\t
Created with \n" + "\t\t\tSwiftlint\n" + "\t\t " + v + " on: " + dateString + "
\n" + "\t\n" + "" } private static func generateSingleRow(for violation: StyleViolation, at index: Int) -> String { let severity = violation.severity.rawValue let location = violation.location let line = location.line ?? 0 let character = location.character ?? 0 return "\t\t\t\t