mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
a773c3ec21
* Improve docstrings for `StringView+SwiftSyntax.swift` * Move changelog entry to correct section & reword * Change parameter type from `Int` to `ByteCount` * Move AbsolutePosition / ByteCount conversion to internal API * Only warn once if syntax tree cannot be parsed * Move Syntactic Sugar examples to a dedicated file * Change SyntacticSugarRuleVisitor from SyntaxAnyVisitor to SyntaxVisitor * Add `SugaredType` enum to help with the implement `SyntacticSugarRule`
28 lines
1.1 KiB
Swift
28 lines
1.1 KiB
Swift
import Foundation
|
|
import SourceKittenFramework
|
|
import SwiftSyntax
|
|
|
|
extension StringView {
|
|
/// Converts two absolute positions from SwiftSyntax to a valid `NSRange` if possible.
|
|
///
|
|
/// - parameter start: Starting position.
|
|
/// - parameter end: End position.
|
|
///
|
|
/// - returns: `NSRange` or nil in case of empty string.
|
|
func NSRange(start: AbsolutePosition, end: AbsolutePosition) -> NSRange? {
|
|
precondition(end >= start, "End position should be bigger than the start position")
|
|
return NSRange(start: start, length: ByteCount(end.utf8Offset - start.utf8Offset))
|
|
}
|
|
|
|
/// Converts absolute position with length from SwiftSyntax to a valid `NSRange` if possible.
|
|
///
|
|
/// - parameter start: Starting position.
|
|
/// - parameter length: Length in bytes.
|
|
///
|
|
/// - returns: `NSRange` or nil in case of empty string.
|
|
private func NSRange(start: AbsolutePosition, length: ByteCount) -> NSRange? {
|
|
let byteRange = ByteRange(location: ByteCount(start), length: length)
|
|
return byteRangeToNSRange(byteRange)
|
|
}
|
|
}
|