Closure Parameter Position

Closure parameters should be on the same line as opening brace

  • Identifier: closure_parameter_position
  • Enabled by default: Yes
  • Supports autocorrection: No
  • Kind: style
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning

Non Triggering Examples

[1, 2].map { $0 + 1 }
[1, 2].map({ $0 + 1 })
[1, 2].map { number in
 number + 1 
}
[1, 2].map { number -> Int in
 number + 1 
}
[1, 2].map { (number: Int) -> Int in
 number + 1 
}
[1, 2].map { [weak self] number in
 number + 1 
}
[1, 2].something(closure: { number in
 number + 1 
})
let isEmpty = [1, 2].isEmpty()
rlmConfiguration.migrationBlock.map { rlmMigration in
    return { migration, schemaVersion in
        rlmMigration(migration.rlmMigration, schemaVersion)
    }
}
let mediaView: UIView = { [weak self] index in
   return UIView()
}(index)

Triggering Examples

[1, 2].map {
    number in
    number + 1
}
[1, 2].map {
    number -> Int in
    number + 1
}
[1, 2].map {
    (number: Int) -> Int in
    number + 1
}
[1, 2].map {
    [weak self] number in
    number + 1
}
[1, 2].map { [weak self]
    number in
    number + 1
}
[1, 2].map({
    number in
    number + 1
})
[1, 2].something(closure: {
    number in
    number + 1
})
[1, 2].reduce(0) {
    sum, number in
    number + sum
})
f.completionHandler = {
    thing in
    doStuff()
}
foo {
    [weak self] in
    self?.bar()
}