mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
7c2c4ac270
``` SwiftLintFrameworkTests.IntegrationTests testSwiftLintLints, failed - Documented declarations should be valid. ``` That has been fixed on locally by https://github.com/jpsim/SourceKitten/pull/175
37 lines
1.0 KiB
Swift
37 lines
1.0 KiB
Swift
//
|
|
// SyntaxMap+SwiftLint.swift
|
|
// SwiftLint
|
|
//
|
|
// Created by Norio Nomura on 2/19/16.
|
|
// Copyright © 2016 Realm. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import SourceKittenFramework
|
|
|
|
extension SyntaxMap {
|
|
/// Returns array of SyntaxTokens intersecting with byte range
|
|
///
|
|
/// - Parameter byteRange: byte based NSRange
|
|
internal func tokensIn(byteRange: NSRange) -> [SyntaxToken] {
|
|
|
|
func intersect(token: SyntaxToken) -> Bool {
|
|
return NSRange(location: token.offset, length: token.length)
|
|
.intersectsRange(byteRange)
|
|
}
|
|
|
|
func notIntersect(token: SyntaxToken) -> Bool {
|
|
return !intersect(token)
|
|
}
|
|
|
|
guard let startIndex = tokens.indexOf(intersect) else {
|
|
return []
|
|
}
|
|
let tokensBeginningIntersect = tokens.lazy.suffixFrom(startIndex)
|
|
if let endIndex = tokensBeginningIntersect.indexOf(notIntersect) {
|
|
return Array(tokensBeginningIntersect.prefixUpTo(endIndex))
|
|
}
|
|
return Array(tokensBeginningIntersect)
|
|
}
|
|
}
|