mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
@@ -54,6 +54,11 @@
|
||||
[Marcelo Fabri](https://github.com/marcelofabri)
|
||||
[#3186](https://github.com/realm/SwiftLint/issues/3186)
|
||||
|
||||
* Fix false positives in `closure_spacing` rule reported in
|
||||
non-closures expressions.
|
||||
[Marcelo Fabri](https://github.com/marcelofabri)
|
||||
[#3270](https://github.com/realm/SwiftLint/issues/3270)
|
||||
|
||||
## 0.39.2: Stay Home
|
||||
|
||||
This is the last release to support building with Swift 5.0.x.
|
||||
|
||||
@@ -30,7 +30,17 @@ public struct ClosureSpacingRule: CorrectableRule, ConfigurationProviderRule, Op
|
||||
Example("[].map ({ $0.description })"),
|
||||
Example("[].filter { $0.contains(location) }"),
|
||||
Example("extension UITableViewCell: ReusableView { }"),
|
||||
Example("extension UITableViewCell: ReusableView {}")
|
||||
Example("extension UITableViewCell: ReusableView {}"),
|
||||
Example("""
|
||||
protocol SomeProtocol {
|
||||
var field: Int {get}
|
||||
}
|
||||
"""),
|
||||
Example("""
|
||||
func something(field: Int) {
|
||||
guard field != 0 else {return}
|
||||
}
|
||||
""")
|
||||
],
|
||||
triggeringExamples: [
|
||||
Example("[].filter(↓{$0.contains(location)})"),
|
||||
@@ -131,6 +141,15 @@ public struct ClosureSpacingRule: CorrectableRule, ConfigurationProviderRule, Op
|
||||
let cleaned = content.trimmingCharacters(in: .whitespaces)
|
||||
return content != " " + cleaned + " "
|
||||
}
|
||||
.filter { range in
|
||||
guard SwiftVersion.current > .fourDotTwo else {
|
||||
return true
|
||||
}
|
||||
|
||||
let byteOffset = file.stringView.byteOffset(fromLocation: range.location)
|
||||
let structures = file.structureDictionary.structures(forByteOffset: byteOffset)
|
||||
return structures.last?.kind.flatMap(SwiftExpressionKind.init) == .closure
|
||||
}
|
||||
.sorted {
|
||||
$0.location < $1.location
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user