mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
move ASTRule function implementations into a protocol extension
This commit is contained in:
@@ -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] {
|
||||
|
||||
Reference in New Issue
Block a user