mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
With the binding of configurations to their associated rule types "unknown configuration" errors can be made more specific mentioning also the rule's identifier in the printed message.
38 lines
1.4 KiB
Swift
38 lines
1.4 KiB
Swift
struct StatementPositionConfiguration: SeverityBasedRuleConfiguration, Equatable {
|
|
typealias Parent = StatementPositionRule
|
|
|
|
enum StatementModeConfiguration: String {
|
|
case `default` = "default"
|
|
case uncuddledElse = "uncuddled_else"
|
|
|
|
init(value: Any) throws {
|
|
if let string = (value as? String)?.lowercased(),
|
|
let value = Self(rawValue: string) {
|
|
self = value
|
|
} else {
|
|
throw Issue.unknownConfiguration(ruleID: Parent.identifier)
|
|
}
|
|
}
|
|
}
|
|
|
|
var consoleDescription: String {
|
|
return "(statement_mode) \(statementMode.rawValue), " +
|
|
"(severity) \(severityConfiguration.consoleDescription)"
|
|
}
|
|
|
|
private(set) var statementMode = StatementModeConfiguration.default
|
|
private(set) var severityConfiguration = SeverityConfiguration<Parent>.warning
|
|
|
|
mutating func apply(configuration: Any) throws {
|
|
guard let configurationDict = configuration as? [String: Any] else {
|
|
throw Issue.unknownConfiguration(ruleID: Parent.identifier)
|
|
}
|
|
if let statementModeConfiguration = configurationDict["statement_mode"] {
|
|
try statementMode = StatementModeConfiguration(value: statementModeConfiguration)
|
|
}
|
|
if let severity = configurationDict["severity"] {
|
|
try severityConfiguration.apply(configuration: severity)
|
|
}
|
|
}
|
|
}
|