Files
SwiftLint/Source/SwiftLintFramework/Protocols/ASTRule.swift
T
2017-07-21 21:08:52 +02:00

34 lines
1.0 KiB
Swift

//
// ASTRule.swift
// SwiftLint
//
// Created by JP Simard on 5/16/15.
// Copyright © 2015 Realm. All rights reserved.
//
import SourceKittenFramework
public protocol ASTRule: Rule {
associatedtype KindType: RawRepresentable
func validate(file: File, kind: KindType, dictionary: [String: SourceKitRepresentable]) -> [StyleViolation]
}
public extension ASTRule where KindType.RawValue == String {
func validate(file: File) -> [StyleViolation] {
return validate(file: file, dictionary: file.structure.dictionary)
}
func validate(file: File, dictionary: [String: SourceKitRepresentable]) -> [StyleViolation] {
return dictionary.substructure.flatMap { subDict -> [StyleViolation] in
var violations = validate(file: file, dictionary: subDict)
if let kindString = subDict.kind,
let kind = KindType(rawValue: kindString) {
violations += validate(file: file, kind: kind, dictionary: subDict)
}
return violations
}
}
}