-
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.
Merge pull request #552 from realm/nn-rewrite-force-unwrapping-rule
Rewrite `ForceUnwrappingRule`
- Loading branch information
Showing
5 changed files
with
167 additions
and
5 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
42 changes: 42 additions & 0 deletions
42
Source/SwiftLintFramework/Extensions/Structure+SwiftLint.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,42 @@ | ||
// | ||
// Structure+SwiftLint.swift | ||
// SwiftLint | ||
// | ||
// Created by Norio Nomura on 2/18/16. | ||
// Copyright © 2016 Realm. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import SourceKittenFramework | ||
|
||
extension Structure { | ||
|
||
/// Returns array of tuples containing "key.kind" and "byteRange" from Structure | ||
/// that contains the byte offset. | ||
/// | ||
/// - Parameter byteOffset: Int | ||
// swiftlint:disable:next valid_docs | ||
internal func kindsFor(byteOffset: Int) -> [(kind: String, byteRange: NSRange)] { | ||
var results = [(kind: String, byteRange: NSRange)]() | ||
|
||
func parse(dictionary: [String : SourceKitRepresentable]) { | ||
guard let | ||
offset = (dictionary["key.offset"] as? Int64).map({ Int($0) }), | ||
byteRange = (dictionary["key.length"] as? Int64).map({ Int($0) }) | ||
.map({NSRange(location: offset, length: $0)}) | ||
where NSLocationInRange(byteOffset, byteRange) else { | ||
return | ||
} | ||
if let kind = dictionary["key.kind"] as? String { | ||
results.append((kind: kind, byteRange: byteRange)) | ||
} | ||
if let subStructure = dictionary["key.substructure"] as? [SourceKitRepresentable] { | ||
for case let dictionary as [String : SourceKitRepresentable] in subStructure { | ||
parse(dictionary) | ||
} | ||
} | ||
} | ||
parse(dictionary) | ||
return results | ||
} | ||
} |
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
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