mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
b83e0991b9
The MIT license doesn't require that all files be prepended with this licensing or copyright information. Realm confirmed that they're ok with this change. This will enable some companies to contribute to SwiftLint and the date & authorship information will remain accessible via git source control.
30 lines
1.1 KiB
Swift
30 lines
1.1 KiB
Swift
import Foundation
|
|
import SourceKittenFramework
|
|
|
|
extension Structure {
|
|
|
|
/// Returns array of tuples containing "key.kind" and "byteRange" from Structure
|
|
/// that contains the byte offset. Returns all kinds if no parameter specified.
|
|
///
|
|
/// - Parameter byteOffset: Int?
|
|
internal func kinds(forByteOffset byteOffset: Int? = nil) -> [(kind: String, byteRange: NSRange)] {
|
|
var results = [(kind: String, byteRange: NSRange)]()
|
|
|
|
func parse(_ dictionary: [String: SourceKitRepresentable]) {
|
|
guard let offset = dictionary.offset,
|
|
let byteRange = dictionary.length.map({ NSRange(location: offset, length: $0) }) else {
|
|
return
|
|
}
|
|
if let byteOffset = byteOffset, !NSLocationInRange(byteOffset, byteRange) {
|
|
return
|
|
}
|
|
if let kind = dictionary.kind {
|
|
results.append((kind: kind, byteRange: byteRange))
|
|
}
|
|
dictionary.substructure.forEach(parse)
|
|
}
|
|
parse(dictionary)
|
|
return results
|
|
}
|
|
}
|