mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
b83e0991b9
The MIT license doesn't require that all files be prepended with this licensing or copyright information. Realm confirmed that they're ok with this change. This will enable some companies to contribute to SwiftLint and the date & authorship information will remain accessible via git source control.
94 lines
3.0 KiB
Swift
94 lines
3.0 KiB
Swift
import Foundation
|
|
|
|
public struct OverridenSuperCallConfiguration: RuleConfiguration, Equatable {
|
|
private let defaultIncluded = [
|
|
//NSObject
|
|
"awakeFromNib()",
|
|
"prepareForInterfaceBuilder()",
|
|
//UICollectionViewLayout
|
|
"invalidateLayout()",
|
|
"invalidateLayout(with:)",
|
|
"invalidateLayoutWithContext(_:)",
|
|
//UIView
|
|
"prepareForReuse()",
|
|
"updateConstraints()",
|
|
//UIViewController
|
|
"addChildViewController(_:)",
|
|
"decodeRestorableState(with:)",
|
|
"decodeRestorableStateWithCoder(_:)",
|
|
"didReceiveMemoryWarning()",
|
|
"encodeRestorableState(with:)",
|
|
"encodeRestorableStateWithCoder(_:)",
|
|
"removeFromParentViewController()",
|
|
"setEditing(_:animated:)",
|
|
"transition(from:to:duration:options:animations:completion:)",
|
|
"transitionCoordinator()",
|
|
"transitionFromViewController(_:toViewController:duration:options:animations:completion:)",
|
|
"viewDidAppear(_:)",
|
|
"viewDidDisappear(_:)",
|
|
"viewDidLoad()",
|
|
"viewWillAppear(_:)",
|
|
"viewWillDisappear(_:)",
|
|
//XCTestCase
|
|
"setUp()",
|
|
"tearDown()"
|
|
]
|
|
|
|
var severityConfiguration = SeverityConfiguration(.warning)
|
|
var excluded: [String] = []
|
|
var included: [String] = ["*"]
|
|
|
|
public private(set) var resolvedMethodNames: [String]
|
|
|
|
init() {
|
|
resolvedMethodNames = defaultIncluded
|
|
}
|
|
|
|
public var consoleDescription: String {
|
|
return severityConfiguration.consoleDescription +
|
|
", excluded: [\(excluded)]" +
|
|
", included: [\(included)]"
|
|
}
|
|
|
|
public mutating func apply(configuration: Any) throws {
|
|
guard let configuration = configuration as? [String: Any] else {
|
|
throw ConfigurationError.unknownConfiguration
|
|
}
|
|
|
|
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()
|
|
}
|
|
|
|
public var severity: ViolationSeverity {
|
|
return severityConfiguration.severity
|
|
}
|
|
|
|
private func calculateResolvedMethodNames() -> [String] {
|
|
var names: [String] = []
|
|
if included.contains("*") && !excluded.contains("*") {
|
|
names += defaultIncluded
|
|
}
|
|
names += included.filter({ $0 != "*" })
|
|
names = names.filter { !excluded.contains($0) }
|
|
return names
|
|
}
|
|
}
|
|
|
|
public func == (lhs: OverridenSuperCallConfiguration,
|
|
rhs: OverridenSuperCallConfiguration) -> Bool {
|
|
return lhs.excluded == rhs.excluded &&
|
|
lhs.included == rhs.included &&
|
|
lhs.severityConfiguration == rhs.severityConfiguration
|
|
}
|