mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
b83e0991b9
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.
49 lines
1.6 KiB
Swift
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
|
|
}
|