Files
SwiftLint/Source/SwiftLintFramework/Rules/RuleConfigurations/StatementPositionConfiguration.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.6 KiB
Swift

import Foundation
public enum StatementModeConfiguration: String {
case `default` = "default"
case uncuddledElse = "uncuddled_else"
init(value: Any) throws {
if let string = (value as? String)?.lowercased(),
let value = StatementModeConfiguration(rawValue: string) {
self = value
} else {
throw ConfigurationError.unknownConfiguration
}
}
}
public struct StatementConfiguration: RuleConfiguration, Equatable {
public var consoleDescription: String {
return "(statement_mode) \(statementMode.rawValue), " +
"(severity) \(severity.consoleDescription)"
}
var statementMode: StatementModeConfiguration
var severity: SeverityConfiguration
public init(statementMode: StatementModeConfiguration,
severity: SeverityConfiguration) {
self.statementMode = statementMode
self.severity = severity
}
public mutating func apply(configuration: Any) throws {
guard let configurationDict = configuration as? [String: Any] else {
throw ConfigurationError.unknownConfiguration
}
if let statementModeConfiguration = configurationDict["statement_mode"] {
try statementMode = StatementModeConfiguration(value: statementModeConfiguration)
}
if let severityConfiguration = configurationDict["severity"] {
try severity.apply(configuration: severityConfiguration)
}
}
}
public func == (lhs: StatementConfiguration, rhs: StatementConfiguration) -> Bool {
return lhs.statementMode == rhs.statementMode && lhs.severity == rhs.severity
}