Skip to content

Commit

Permalink
Changed guard to be based on the largest replacement index. Added ent…
Browse files Browse the repository at this point in the history
…ry to the changelog.
  • Loading branch information
CraigSiemens committed Apr 24, 2016
1 parent c3a5e33 commit 7930c09
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
[Norio Nomura](https://github.com/norio-nomura)
[#617](https://github.com/realm/SwiftLint/issues/617)

* Add autocorrect for `ReturnArrowWhitespaceRule`.
[Craig Siemens](https://github.com/CraigSiemens)

##### Bug Fixes

* Failed to launch swiftlint when Xcode.app was placed at non standard path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ public struct ReturnArrowWhitespaceRule: CorrectableRule, ConfigurationProviderR
return regularExpression.firstMatchInString(contents, options: [], range: range)
}

let replacementsByIndex = [2: " -> ", 4: " -> ", 6: " ", 7: " "]

for result in results {
guard result.numberOfRanges == 8 else { break }
guard result.numberOfRanges > replacementsByIndex.keys.maxElement() else { break }

let replacementsByIndex = [2: " -> ", 4: " -> ", 6: " ", 7: " "]
for (index, string) in replacementsByIndex {
if let range = contents.nsrangeToIndexRange(result.rangeAtIndex(index)) {
contents.replaceRange(range, with: string)
Expand Down

0 comments on commit 7930c09

Please sign in to comment.