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.
46 lines
1.9 KiB
Swift
46 lines
1.9 KiB
Swift
private enum ConfigurationKey: String {
|
|
case severity = "severity"
|
|
case includePublicAndOpen = "include_public_and_open"
|
|
case relatedUSRsToSkip = "related_usrs_to_skip"
|
|
}
|
|
|
|
struct UnusedDeclarationConfiguration: SeverityBasedRuleConfiguration, Equatable {
|
|
typealias Parent = UnusedDeclarationRule
|
|
|
|
private(set) var severityConfiguration = SeverityConfiguration<Parent>.error
|
|
private(set) var includePublicAndOpen = false
|
|
private(set) var relatedUSRsToSkip = Set(["s:7SwiftUI15PreviewProviderP"])
|
|
|
|
var consoleDescription: String {
|
|
return "\(ConfigurationKey.severity.rawValue): \(severityConfiguration.severity.rawValue), " +
|
|
"\(ConfigurationKey.includePublicAndOpen.rawValue): \(includePublicAndOpen), " +
|
|
"\(ConfigurationKey.relatedUSRsToSkip.rawValue): \(relatedUSRsToSkip.sorted())"
|
|
}
|
|
|
|
mutating func apply(configuration: Any) throws {
|
|
guard let configDict = configuration as? [String: Any], configDict.isNotEmpty else {
|
|
throw Issue.unknownConfiguration(ruleID: Parent.identifier)
|
|
}
|
|
|
|
for (string, value) in configDict {
|
|
guard let key = ConfigurationKey(rawValue: string) else {
|
|
throw Issue.unknownConfiguration(ruleID: Parent.identifier)
|
|
}
|
|
switch (key, value) {
|
|
case (.severity, let stringValue as String):
|
|
try severityConfiguration.apply(configuration: stringValue)
|
|
case (.includePublicAndOpen, let boolValue as Bool):
|
|
includePublicAndOpen = boolValue
|
|
case (.relatedUSRsToSkip, let value):
|
|
if let usrs = [String].array(of: value) {
|
|
relatedUSRsToSkip.formUnion(usrs)
|
|
} else {
|
|
throw Issue.unknownConfiguration(ruleID: Parent.identifier)
|
|
}
|
|
default:
|
|
throw Issue.unknownConfiguration(ruleID: Parent.identifier)
|
|
}
|
|
}
|
|
}
|
|
}
|