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.
52 lines
1.7 KiB
Swift
52 lines
1.7 KiB
Swift
import Foundation
|
|
|
|
// swiftlint:disable:next type_name
|
|
public enum ImplicitlyUnwrappedOptionalModeConfiguration: String {
|
|
case all = "all"
|
|
case allExceptIBOutlets = "all_except_iboutlets"
|
|
|
|
init(value: Any) throws {
|
|
if let string = (value as? String)?.lowercased(),
|
|
let value = ImplicitlyUnwrappedOptionalModeConfiguration(rawValue: string) {
|
|
self = value
|
|
} else {
|
|
throw ConfigurationError.unknownConfiguration
|
|
}
|
|
}
|
|
}
|
|
|
|
public struct ImplicitlyUnwrappedOptionalConfiguration: RuleConfiguration, Equatable {
|
|
private(set) var severity: SeverityConfiguration
|
|
private(set) var mode: ImplicitlyUnwrappedOptionalModeConfiguration
|
|
|
|
init(mode: ImplicitlyUnwrappedOptionalModeConfiguration, severity: SeverityConfiguration) {
|
|
self.mode = mode
|
|
self.severity = severity
|
|
}
|
|
|
|
public var consoleDescription: String {
|
|
return severity.consoleDescription +
|
|
", mode: \(mode)"
|
|
}
|
|
|
|
public mutating func apply(configuration: Any) throws {
|
|
guard let configuration = configuration as? [String: Any] else {
|
|
throw ConfigurationError.unknownConfiguration
|
|
}
|
|
|
|
if let modeString = configuration["mode"] {
|
|
try mode = ImplicitlyUnwrappedOptionalModeConfiguration(value: modeString)
|
|
}
|
|
|
|
if let severityString = configuration["severity"] as? String {
|
|
try severity.apply(configuration: severityString)
|
|
}
|
|
}
|
|
|
|
public static func == (lhs: ImplicitlyUnwrappedOptionalConfiguration,
|
|
rhs: ImplicitlyUnwrappedOptionalConfiguration) -> Bool {
|
|
return lhs.severity == rhs.severity &&
|
|
lhs.mode == rhs.mode
|
|
}
|
|
}
|