Skip to content

Commit

Permalink
Fix crash on multiline_function_chains rule
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelofabri authored and sjavora committed Mar 9, 2019
1 parent 6c2e06d commit 8705610
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@

* Fix false positive on `file_name` rule when using nested types.
[Marcelo Fabri](https://github.com/marcelofabri)
[#2325](https://github.com/realm/SwiftLint/issues/2325)
[#2325](https://github.com/realm/SwiftLint/issues/2325)

* Fix crash on `multiline_function_chains` rule when using some special
characters inside the function calls.
[Marcelo Fabri](https://github.com/marcelofabri)
[#2360](https://github.com/realm/SwiftLint/issues/2360)

## 0.27.0: Heavy Duty

Expand Down
6 changes: 6 additions & 0 deletions Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -10270,6 +10270,12 @@ let evenSquaresSum = a.b(1, 2, 3)↓.c { blah in
.d()
```
```swift
a.b {
// ““
}↓.e()
```
</details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public struct MultilineFunctionChainsRule: ASTRule, OptInRule, ConfigurationProv
print(blah)
}
.d()
""",
"""
a.b {
// ““
}↓.e()
"""
]
)
Expand Down Expand Up @@ -197,7 +202,7 @@ public struct MultilineFunctionChainsRule: ASTRule, OptInRule, ConfigurationProv
}

let nameEndOffset = nameOffset + nameLength
let nameLengthDifference = parentName.bridge().length - nameLength
let nameLengthDifference = parentName.utf8.count - nameLength
let offsetDifference = bodyOffset - nameEndOffset

return NSRange(location: nameEndOffset + offsetDifference + bodyLength,
Expand All @@ -209,7 +214,7 @@ public struct MultilineFunctionChainsRule: ASTRule, OptInRule, ConfigurationProv
fileprivate extension Dictionary where Key: ExpressibleByStringLiteral {
var subcalls: [[String: SourceKitRepresentable]] {
return substructure.compactMap { dictionary -> [String: SourceKitRepresentable]? in
guard case .call? = dictionary.kind.flatMap(SwiftExpressionKind.init(rawValue:)) else {
guard dictionary.kind.flatMap(SwiftExpressionKind.init(rawValue:)) == .call else {
return nil
}
return dictionary
Expand Down

0 comments on commit 8705610

Please # to comment.