forked from realm/SwiftLint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultilineArgumentsConfiguration.swift
59 lines (48 loc) · 1.98 KB
/
MultilineArgumentsConfiguration.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// MultilineArgumentsConfiguration.swift
// SwiftLint
//
// Created by Marcel Jackwerth on 9/29/17.
// Copyright © 2017 Realm. All rights reserved.
//
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
}
}