Migrate to use SourceKitten's new ByteCount/ByteRange types (#3037)

New APIs were introduced in SourceKitten to allow for a more typesafe distinction between integers meaning NSString-based distances and byte-based distances.

* https://github.com/jpsim/SourceKitten/pull/639
* https://github.com/jpsim/SourceKitten/pull/642

This PR migrates SwiftLint's use of those APIs.
This commit is contained in:
JP Simard
2020-01-16 15:18:37 -08:00
committed by GitHub
parent 4a56bf56c5
commit fe5baca7cd
123 changed files with 829 additions and 878 deletions
@@ -1,4 +1,3 @@
import Foundation
import SourceKittenFramework
/// Represents a Swift file's syntax information.
@@ -22,7 +21,7 @@ public struct SwiftLintSyntaxMap {
/// - parameter byteRange: Byte-based NSRange.
///
/// - returns: The array of syntax tokens intersecting with byte range.
internal func tokens(inByteRange byteRange: NSRange) -> [SwiftLintSyntaxToken] {
internal func tokens(inByteRange byteRange: ByteRange) -> [SwiftLintSyntaxToken] {
func intersect(_ token: SwiftLintSyntaxToken) -> Bool {
return token.range.intersects(byteRange)
}
@@ -46,10 +45,10 @@ public struct SwiftLintSyntaxMap {
/// Returns the syntax kinds in the specified byte range.
///
/// - parameter byteRange: Byte-based NSRange.
/// - parameter byteRange: Byte range.
///
/// - returns: The syntax kinds in the specified byte range.
internal func kinds(inByteRange byteRange: NSRange) -> [SyntaxKind] {
internal func kinds(inByteRange byteRange: ByteRange) -> [SyntaxKind] {
return tokens(inByteRange: byteRange).compactMap { $0.kind }
}
}