mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
31 lines
1.1 KiB
Swift
31 lines
1.1 KiB
Swift
public struct TrailingCommaConfiguration: RuleConfiguration, Equatable {
|
|
private(set) var severityConfiguration = SeverityConfiguration(.warning)
|
|
private(set) var mandatoryComma: Bool
|
|
|
|
public var consoleDescription: String {
|
|
return severityConfiguration.consoleDescription + ", mandatory_comma: \(mandatoryComma)"
|
|
}
|
|
|
|
public init(mandatoryComma: Bool = false) {
|
|
self.mandatoryComma = mandatoryComma
|
|
}
|
|
|
|
public mutating func apply(configuration: Any) throws {
|
|
guard let configuration = configuration as? [String: Any] else {
|
|
throw ConfigurationError.unknownConfiguration
|
|
}
|
|
|
|
mandatoryComma = (configuration["mandatory_comma"] as? Bool == true)
|
|
|
|
if let severityString = configuration["severity"] as? String {
|
|
try severityConfiguration.apply(configuration: severityString)
|
|
}
|
|
}
|
|
}
|
|
|
|
public func == (lhs: TrailingCommaConfiguration,
|
|
rhs: TrailingCommaConfiguration) -> Bool {
|
|
return lhs.mandatoryComma == rhs.mandatoryComma &&
|
|
lhs.severityConfiguration == rhs.severityConfiguration
|
|
}
|