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.8 KiB
Swift
52 lines
1.8 KiB
Swift
import Foundation
|
|
|
|
private enum ConfigurationKey: String {
|
|
case firstArgumentLocation = "first_argument_location"
|
|
}
|
|
|
|
public struct MultilineArgumentsConfiguration: RuleConfiguration, Equatable {
|
|
public enum FirstArgumentLocation: String {
|
|
case anyLine = "any_line"
|
|
case sameLine = "same_line"
|
|
case nextLine = "next_line"
|
|
|
|
init(value: Any) throws {
|
|
guard
|
|
let string = (value as? String)?.lowercased(),
|
|
let value = FirstArgumentLocation(rawValue: string) else {
|
|
throw ConfigurationError.unknownConfiguration
|
|
}
|
|
|
|
self = value
|
|
}
|
|
}
|
|
|
|
private(set) var severityConfiguration = SeverityConfiguration(.warning)
|
|
private(set) var firstArgumentLocation = FirstArgumentLocation.anyLine
|
|
|
|
public var consoleDescription: String {
|
|
return severityConfiguration.consoleDescription +
|
|
", \(ConfigurationKey.firstArgumentLocation.rawValue): \(firstArgumentLocation.rawValue)"
|
|
}
|
|
|
|
public mutating func apply(configuration: Any) throws {
|
|
guard let configuration = configuration as? [String: Any] else {
|
|
throw ConfigurationError.unknownConfiguration
|
|
}
|
|
|
|
if let modeString = configuration[ConfigurationKey.firstArgumentLocation.rawValue] {
|
|
try firstArgumentLocation = FirstArgumentLocation(value: modeString)
|
|
}
|
|
|
|
if let severityString = configuration["severity"] as? String {
|
|
try severityConfiguration.apply(configuration: severityString)
|
|
}
|
|
}
|
|
|
|
public static func == (lhs: MultilineArgumentsConfiguration,
|
|
rhs: MultilineArgumentsConfiguration) -> Bool {
|
|
return lhs.severityConfiguration == rhs.severityConfiguration &&
|
|
lhs.firstArgumentLocation == rhs.firstArgumentLocation
|
|
}
|
|
}
|