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