mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
9979c4fd27
To enforce that `self` identifiers are consistently re-bound to a common identifier name. Configure `bind_identifier` to the name you want to use. Defaults to `self`. Addresses https://github.com/realm/SwiftLint/issues/2495
27 lines
1011 B
Swift
27 lines
1011 B
Swift
private enum ConfigurationKey: String {
|
|
case severity = "severity"
|
|
case bindIdentifier = "bind_identifier"
|
|
}
|
|
|
|
public struct SelfBindingConfiguration: RuleConfiguration, Equatable {
|
|
private(set) var severityConfiguration = SeverityConfiguration(.warning)
|
|
private(set) var bindIdentifier = "self"
|
|
|
|
public var consoleDescription: String {
|
|
return [severityConfiguration.consoleDescription,
|
|
"\(ConfigurationKey.bindIdentifier): \(bindIdentifier)"].joined(separator: ", ")
|
|
}
|
|
|
|
public mutating func apply(configuration: Any) throws {
|
|
guard let configuration = configuration as? [String: Any] else {
|
|
throw ConfigurationError.unknownConfiguration
|
|
}
|
|
|
|
if let severityString = configuration[ConfigurationKey.severity.rawValue] as? String {
|
|
try severityConfiguration.apply(configuration: severityString)
|
|
}
|
|
|
|
bindIdentifier = configuration[ConfigurationKey.bindIdentifier.rawValue] as? String ?? "self"
|
|
}
|
|
}
|