Files
SwiftLint/Source/SwiftLintFramework/Rules/RuleConfigurations/SeverityLevelsConfiguration.swift
T
JP Simard b83e0991b9 Remove all file headers
The MIT license doesn't require that all files be prepended with this
licensing or copyright information. Realm confirmed that they're ok with this
change. This will enable some companies to contribute to SwiftLint and the
date & authorship information will remain accessible via git source control.
2018-05-04 13:42:02 -07:00

49 lines
1.7 KiB
Swift

import Foundation
public struct SeverityLevelsConfiguration: RuleConfiguration, Equatable {
public var consoleDescription: String {
let errorString: String
if let errorValue = error {
errorString = ", error: \(errorValue)"
} else {
errorString = ""
}
return "warning: \(warning)" + errorString
}
public var shortConsoleDescription: String {
if let errorValue = error {
return "w/e: \(warning)/\(errorValue)"
}
return "w: \(warning)"
}
var warning: Int
var error: Int?
var params: [RuleParameter<Int>] {
if let error = error {
return [RuleParameter(severity: .error, value: error),
RuleParameter(severity: .warning, value: warning)]
}
return [RuleParameter(severity: .warning, value: warning)]
}
public mutating func apply(configuration: Any) throws {
if let configurationArray = [Int].array(of: configuration), !configurationArray.isEmpty {
warning = configurationArray[0]
error = (configurationArray.count > 1) ? configurationArray[1] : nil
} else if let configDict = configuration as? [String: Int?],
!configDict.isEmpty, Set(configDict.keys).isSubset(of: ["warning", "error"]) {
warning = (configDict["warning"] as? Int) ?? warning
error = configDict["error"] as? Int
} else {
throw ConfigurationError.unknownConfiguration
}
}
}
public func == (lhs: SeverityLevelsConfiguration, rhs: SeverityLevelsConfiguration) -> Bool {
return lhs.warning == rhs.warning && lhs.error == rhs.error
}