mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
8a30cb2e3d
make Extensions, Models & Protocols groups under SourceKittenFramework
35 lines
1.1 KiB
Swift
35 lines
1.1 KiB
Swift
//
|
|
// ASTRule.swift
|
|
// SwiftLint
|
|
//
|
|
// Created by JP Simard on 2015-05-16.
|
|
// Copyright (c) 2015 Realm. All rights reserved.
|
|
//
|
|
|
|
import SourceKittenFramework
|
|
import SwiftXPC
|
|
|
|
public protocol ASTRule: Rule {
|
|
func validateFile(file: File,
|
|
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)
|
|
}
|
|
}
|
|
}
|