Apply small refactorings

This commit is contained in:
JP Simard
2020-11-09 12:06:44 -05:00
parent 0788cd237c
commit aa02a8aec0
2 changed files with 9 additions and 21 deletions
@@ -11,16 +11,16 @@ public struct NestingRule: ConfigurationProviderRule {
public static let description = RuleDescription(
identifier: "nesting",
name: "Nesting",
description: "Types should be nested at most 1 level deep, " +
"and functions should be nested at most 2 levels deep.",
description:
"Types should be nested at most 1 level deep, and functions should be nested at most 2 levels deep.",
kind: .metrics,
nonTriggeringExamples: NestingRuleExamples.nonTriggeringExamples,
triggeringExamples: NestingRuleExamples.triggeringExamples
)
private let omittedStructureKinds: [SwiftStructureKind] =
[.declaration(.enumcase), .declaration(.enumelement)]
+ SwiftDeclarationKind.variableKinds.map { .declaration($0) }
private let omittedStructureKinds = SwiftDeclarationKind.variableKinds
.union([.enumcase, .enumelement])
.map(SwiftStructureKind.declaration)
private struct ValidationArgs {
var typeLevel: Int = -1
@@ -146,17 +146,4 @@ private enum SwiftStructureKind: Equatable {
return nil
}
}
static func == (lhs: SwiftStructureKind, rhs: SwiftStructureKind) -> Bool {
switch (lhs, rhs) {
case let (.declaration(lhsKind), .declaration(rhsKind)):
return lhsKind == rhsKind
case let (.expression(lhsKind), .expression(rhsKind)):
return lhsKind == rhsKind
case let (.statement(lhsKind), .statement(rhsKind)):
return lhsKind == rhsKind
default:
return false
}
}
}
@@ -34,9 +34,10 @@ public struct NestingConfiguration: RuleConfiguration, Equatable {
if let functionLevelConfiguration = configurationDict["function_level"] {
try functionLevel.apply(configuration: functionLevelConfiguration)
}
// swiftlint:disable:next line_length
checkNestingInClosuresAndStatements = configurationDict["check_nesting_in_closures_and_statements"] as? Bool ?? true
alwaysAllowOneTypeInFunctions = configurationDict["always_allow_one_type_in_functions"] as? Bool ?? false
checkNestingInClosuresAndStatements =
configurationDict["check_nesting_in_closures_and_statements"] as? Bool ?? true
alwaysAllowOneTypeInFunctions =
configurationDict["always_allow_one_type_in_functions"] as? Bool ?? false
}
func severity(with config: SeverityLevelsConfiguration, for level: Int) -> ViolationSeverity? {