-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite SyntacticSugarRule with SwiftSyntax
- Loading branch information
1 parent
702b36a
commit ba4e1bf
Showing
5 changed files
with
395 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Source/SwiftLintFramework/Extensions/StringView+SwiftSyntax.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Foundation | ||
import SourceKittenFramework | ||
import SwiftSyntax | ||
|
||
extension StringView { | ||
/// Converts two absolute positions from SwiftSyntax to valid NSRange if possible | ||
/// - Parameters: | ||
/// - start: starting poisiition | ||
/// - end: end position | ||
/// - Returns: NSRange or nil in case of empty string | ||
func NSRange(start: AbsolutePosition, end: AbsolutePosition) -> NSRange? { | ||
precondition(end.utf8Offset >= start.utf8Offset, "End position should be beigger than start position") | ||
return NSRange(start: start, length: end.utf8Offset - start.utf8Offset) | ||
} | ||
|
||
/// Converts absolute position with length from SwiftSyntax to valid NSRange if possible | ||
/// - Parameters: | ||
/// - start: starting position | ||
/// - length: length in bytes | ||
/// - Returns: NSRange or nil in case of empty string | ||
private func NSRange(start: AbsolutePosition, length: Int) -> NSRange? { | ||
let byteRange = ByteRange(location: ByteCount(start.utf8Offset), length: ByteCount(length)) | ||
return byteRangeToNSRange(byteRange) | ||
} | ||
} |
Oops, something went wrong.