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.
57 lines
1.7 KiB
Swift
57 lines
1.7 KiB
Swift
struct ProhibitedSuperConfiguration: SeverityBasedRuleConfiguration, Equatable {
|
|
typealias Parent = ProhibitedSuperRule
|
|
|
|
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
|
|
var excluded = [String]()
|
|
var included = ["*"]
|
|
|
|
private(set) var resolvedMethodNames = [
|
|
// NSFileProviderExtension
|
|
"providePlaceholder(at:completionHandler:)",
|
|
// NSTextInput
|
|
"doCommand(by:)",
|
|
// NSView
|
|
"updateLayer()",
|
|
// UIViewController
|
|
"loadView()"
|
|
]
|
|
|
|
init() {}
|
|
|
|
var consoleDescription: String {
|
|
return "severity: \(severityConfiguration.consoleDescription)" +
|
|
", excluded: [\(excluded)]" +
|
|
", included: [\(included)]"
|
|
}
|
|
|
|
mutating func apply(configuration: Any) throws {
|
|
guard let configuration = configuration as? [String: Any] else {
|
|
throw Issue.unknownConfiguration(ruleID: Parent.identifier)
|
|
}
|
|
|
|
if let severityString = configuration["severity"] as? String {
|
|
try severityConfiguration.apply(configuration: severityString)
|
|
}
|
|
|
|
if let excluded = [String].array(of: configuration["excluded"]) {
|
|
self.excluded = excluded
|
|
}
|
|
|
|
if let included = [String].array(of: configuration["included"]) {
|
|
self.included = included
|
|
}
|
|
|
|
resolvedMethodNames = calculateResolvedMethodNames()
|
|
}
|
|
|
|
private func calculateResolvedMethodNames() -> [String] {
|
|
var names = [String]()
|
|
if included.contains("*") && !excluded.contains("*") {
|
|
names += resolvedMethodNames
|
|
}
|
|
names += included.filter { $0 != "*" }
|
|
names = names.filter { !excluded.contains($0) }
|
|
return names
|
|
}
|
|
}
|