Files
SwiftLint/Source/SwiftLintFramework/Models/SwiftLintSyntaxToken.swift
T
JP Simard fe5baca7cd 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.
2020-01-16 15:18:37 -08:00

40 lines
1.1 KiB
Swift

import SourceKittenFramework
/// A SwiftLint-aware Swift syntax token.
public struct SwiftLintSyntaxToken {
/// The raw `SyntaxToken` obtained by SourceKitten.
public let value: SyntaxToken
/// The syntax kind associated with is token.
public let kind: SyntaxKind?
/// Creates a `SwiftLintSyntaxToken` from the raw `SyntaxToken` obtained by SourceKitten.
///
/// - parameter value: The raw `SyntaxToken` obtained by SourceKitten.
public init(value: SyntaxToken) {
self.value = value
kind = SyntaxKind(rawValue: value.type)
}
/// The byte range in a source file for this token.
public var range: ByteRange {
return value.range
}
/// The starting byte offset in a source file for this token.
public var offset: ByteCount {
return value.offset
}
/// The length in bytes for this token.
public var length: ByteCount {
return value.length
}
}
extension Array where Element == SwiftLintSyntaxToken {
var kinds: [SyntaxKind] {
return compactMap { $0.kind }
}
}