move ASTRule function implementations into a protocol extension

This commit is contained in:
JP Simard
2015-11-04 15:39:29 -08:00
parent b3624c4707
commit 8e12dbd81d
6 changed files with 20 additions and 104 deletions
+20 -4
View File
@@ -10,9 +10,25 @@ import SourceKittenFramework
import SwiftXPC
public protocol ASTRule: Rule {
func validateFile(file: File, dictionary: XPCDictionary) -> [StyleViolation]
func validateFile(file: File,
kind: SwiftDeclarationKind,
dictionary: XPCDictionary) -> [StyleViolation]
kind: SwiftDeclarationKind, dictionary: XPCDictionary) -> [StyleViolation]
}
extension ASTRule {
public func validateFile(file: File) -> [StyleViolation] {
return validateFile(file, dictionary: file.structure.dictionary)
}
public func validateFile(file: File, dictionary: XPCDictionary) -> [StyleViolation] {
let substructure = dictionary["key.substructure"] as? XPCArray ?? []
return substructure.flatMap { subItem -> [StyleViolation] in
guard let subDict = subItem as? XPCDictionary,
let kindString = subDict["key.kind"] as? String,
let kind = SwiftDeclarationKind(rawValue: kindString) else {
return []
}
return self.validateFile(file, dictionary: subDict) +
self.validateFile(file, kind: kind, dictionary: subDict)
}
}
}
@@ -29,26 +29,6 @@ public struct FunctionBodyLengthRule: ASTRule, ParameterizedRule {
description: "Enforce maximum function length"
)
public func validateFile(file: File) -> [StyleViolation] {
return validateFile(file, dictionary: file.structure.dictionary)
}
public func validateFile(file: File, dictionary: XPCDictionary) -> [StyleViolation] {
let substructure = dictionary["key.substructure"] as? XPCArray ?? []
return substructure.flatMap { subItem -> [StyleViolation] in
var violations = [StyleViolation]()
if let subDict = subItem as? XPCDictionary,
let kindString = subDict["key.kind"] as? String,
let kind = SwiftDeclarationKind(rawValue: kindString) {
violations.appendContentsOf(
self.validateFile(file, dictionary: subDict) +
self.validateFile(file, kind: kind, dictionary: subDict)
)
}
return violations
}
}
public func validateFile(file: File,
kind: SwiftDeclarationKind,
dictionary: XPCDictionary) -> [StyleViolation] {
@@ -30,26 +30,6 @@ public struct NestingRule: ASTRule {
]
)
public func validateFile(file: File) -> [StyleViolation] {
return validateFile(file, dictionary: file.structure.dictionary)
}
public func validateFile(file: File, dictionary: XPCDictionary) -> [StyleViolation] {
let substructure = dictionary["key.substructure"] as? XPCArray ?? []
return substructure.flatMap { subItem -> [StyleViolation] in
var violations = [StyleViolation]()
if let subDict = subItem as? XPCDictionary,
let kindString = subDict["key.kind"] as? String,
let kind = SwiftDeclarationKind(rawValue: kindString) {
violations.appendContentsOf(
self.validateFile(file, dictionary: subDict) +
self.validateFile(file, kind: kind, dictionary: subDict)
)
}
return violations
}
}
public func validateFile(file: File, kind: SwiftDeclarationKind,
dictionary: XPCDictionary) -> [StyleViolation] {
return validateFile(file, kind: kind, dictionary: dictionary, level: 0)
@@ -29,26 +29,6 @@ public struct TypeBodyLengthRule: ASTRule, ParameterizedRule {
description: "Enforce maximum type body length"
)
public func validateFile(file: File) -> [StyleViolation] {
return validateFile(file, dictionary: file.structure.dictionary)
}
public func validateFile(file: File, dictionary: XPCDictionary) -> [StyleViolation] {
let substructure = dictionary["key.substructure"] as? XPCArray ?? []
return substructure.flatMap { subItem -> [StyleViolation] in
var violations = [StyleViolation]()
if let subDict = subItem as? XPCDictionary,
let kindString = subDict["key.kind"] as? String,
let kind = SwiftDeclarationKind(rawValue: kindString) {
violations.appendContentsOf(
self.validateFile(file, dictionary: subDict) +
self.validateFile(file, kind: kind, dictionary: subDict)
)
}
return violations
}
}
public func validateFile(file: File,
kind: SwiftDeclarationKind,
dictionary: XPCDictionary) -> [StyleViolation] {
@@ -29,26 +29,6 @@ public struct TypeNameRule: ASTRule {
]
)
public func validateFile(file: File) -> [StyleViolation] {
return validateFile(file, dictionary: file.structure.dictionary)
}
public func validateFile(file: File, dictionary: XPCDictionary) -> [StyleViolation] {
let substructure = dictionary["key.substructure"] as? XPCArray ?? []
return substructure.flatMap { subItem -> [StyleViolation] in
var violations = [StyleViolation]()
if let subDict = subItem as? XPCDictionary,
let kindString = subDict["key.kind"] as? String,
let kind = SwiftDeclarationKind(rawValue: kindString) {
violations.appendContentsOf(
self.validateFile(file, dictionary: subDict) +
self.validateFile(file, kind: kind, dictionary: subDict)
)
}
return violations
}
}
public func validateFile(file: File,
kind: SwiftDeclarationKind,
dictionary: XPCDictionary) -> [StyleViolation] {
@@ -30,26 +30,6 @@ public struct VariableNameRule: ASTRule {
]
)
public func validateFile(file: File) -> [StyleViolation] {
return validateFile(file, dictionary: file.structure.dictionary)
}
public func validateFile(file: File, dictionary: XPCDictionary) -> [StyleViolation] {
let substructure = dictionary["key.substructure"] as? XPCArray ?? []
return substructure.flatMap { subItem -> [StyleViolation] in
var violations = [StyleViolation]()
if let subDict = subItem as? XPCDictionary,
let kindString = subDict["key.kind"] as? String,
let kind = SwiftDeclarationKind(rawValue: kindString) {
violations.appendContentsOf(
self.validateFile(file, dictionary: subDict) +
self.validateFile(file, kind: kind, dictionary: subDict)
)
}
return violations
}
}
public func validateFile(file: File,
kind: SwiftDeclarationKind,
dictionary: XPCDictionary) -> [StyleViolation] {