mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
34 lines
1.0 KiB
Swift
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
|
|
}
|
|
}
|
|
}
|