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.
54 lines
2.0 KiB
Swift
54 lines
2.0 KiB
Swift
import Foundation
|
|
|
|
public struct NestingConfiguration: RuleConfiguration, Equatable {
|
|
public var consoleDescription: String {
|
|
return "(type_level) \(typeLevel.shortConsoleDescription), " +
|
|
"(statement_level) \(statementLevel.shortConsoleDescription)"
|
|
}
|
|
|
|
var typeLevel: SeverityLevelsConfiguration
|
|
var statementLevel: SeverityLevelsConfiguration
|
|
|
|
public init(typeLevelWarning: Int,
|
|
typeLevelError: Int?,
|
|
statementLevelWarning: Int,
|
|
statementLevelError: Int?) {
|
|
typeLevel = SeverityLevelsConfiguration(warning: typeLevelWarning, error: typeLevelError)
|
|
statementLevel = SeverityLevelsConfiguration(warning: statementLevelWarning, error: statementLevelError)
|
|
}
|
|
|
|
public mutating func apply(configuration: Any) throws {
|
|
guard let configurationDict = configuration as? [String: Any] else {
|
|
throw ConfigurationError.unknownConfiguration
|
|
}
|
|
|
|
if let typeLevelConfiguration = configurationDict["type_level"] {
|
|
try typeLevel.apply(configuration: typeLevelConfiguration)
|
|
}
|
|
if let statementLevelConfiguration = configurationDict["statement_level"] {
|
|
try statementLevel.apply(configuration: statementLevelConfiguration)
|
|
}
|
|
}
|
|
|
|
func severity(with config: SeverityLevelsConfiguration, for level: Int) -> ViolationSeverity? {
|
|
if let error = config.error, level > error {
|
|
return .error
|
|
} else if level > config.warning {
|
|
return .warning
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func threshold(with config: SeverityLevelsConfiguration, for severity: ViolationSeverity) -> Int {
|
|
switch severity {
|
|
case .error: return config.error ?? config.warning
|
|
case .warning: return config.warning
|
|
}
|
|
}
|
|
}
|
|
|
|
public func == (lhs: NestingConfiguration, rhs: NestingConfiguration) -> Bool {
|
|
return lhs.typeLevel == rhs.typeLevel
|
|
&& lhs.statementLevel == rhs.statementLevel
|
|
}
|