mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
0335f155ab
Fixes #183.
36 lines
1.1 KiB
Swift
36 lines
1.1 KiB
Swift
//
|
|
// JSONReporter.swift
|
|
// SwiftLint
|
|
//
|
|
// Created by JP Simard on 9/19/15.
|
|
// Copyright © 2015 Realm. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import SourceKittenFramework
|
|
|
|
public struct JSONReporter: Reporter {
|
|
public static let identifier = "json"
|
|
public static let isRealtime = false
|
|
|
|
public var description: String {
|
|
return "Reports violations as a JSON array."
|
|
}
|
|
|
|
public static func generateReport(violations: [StyleViolation]) -> String {
|
|
return toJSON(violations.map(dictionaryForViolation))
|
|
}
|
|
|
|
private static func dictionaryForViolation(violation: StyleViolation) -> NSDictionary {
|
|
return [
|
|
"file": violation.location.file ?? NSNull(),
|
|
"line": violation.location.line ?? NSNull(),
|
|
"character": violation.location.character ?? NSNull(),
|
|
"severity": violation.severity.rawValue,
|
|
"type": violation.ruleDescription.name,
|
|
"rule_id": violation.ruleDescription.identifier,
|
|
"reason": violation.reason ?? NSNull()
|
|
]
|
|
}
|
|
}
|