Files
SwiftLint/Source/SwiftLintFramework/Extensions/Dictionary+SwiftLint.swift
T
2016-12-15 19:57:49 -02:00

38 lines
1.2 KiB
Swift

//
// DynamicInlineRule.swift
// SwiftLint
//
// Created by Daniel Duan on 12/08/16.
// Copyright © 2015 Realm. All rights reserved.
//
import Foundation
import SourceKittenFramework
extension Dictionary where Key: ExpressibleByStringLiteral {
var enclosedSwiftAttributes: [String] {
let array = self["key.attributes"] as? [SourceKitRepresentable] ?? []
return array.flatMap { ($0 as? [String: String])?["key.attribute"] }
}
var enclosedVarParameters: [[String: SourceKitRepresentable]] {
let substructure = self["key.substructure"] as? [SourceKitRepresentable] ?? []
return substructure.flatMap { subItem -> [[String: SourceKitRepresentable]] in
guard let subDict = subItem as? [String: SourceKitRepresentable],
let kindString = subDict["key.kind"] as? String else {
return []
}
if SwiftDeclarationKind(rawValue: kindString) == .varParameter {
return [subDict]
}
if SwiftExpressionKind(rawValue: kindString) == .argument {
return subDict.enclosedVarParameters
}
return []
}
}
}