Trailing Closure

Trailing closure syntax should be used whenever possible

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

Non Triggering Examples

foo.map { $0 + 1 }
foo.bar()
foo.reduce(0) { $0 + 1 }
if let foo = bar.map({ $0 + 1 }) { }
foo.something(param1: { $0 }, param2: { $0 + 1 })
offsets.sorted { $0.offset < $1.offset }
foo.something({ return 1 }())
foo.something({ return $0 }(1))
foo.something(0, { return 1 }())
for x in list.filter({ $0.isValid }) {}
if list.allSatisfy({ $0.isValid }) {}
foo(param1: 1, param2: { _ in true }, param3: 0)
foo(param1: 1, param2: { _ in true }) { $0 + 1 }
foo(param1: { _ in false }, param2: { _ in true })
foo(param1: { _ in false }, param2: { _ in true }, param3: { _ in false })
if f({ true }), g({ true }) {
    print("Hello")
}
for i in h({ [1,2,3] }) {
    print(i)
}

Triggering Examples

foo.map({ $0 + 1 })
foo.reduce(0, combine: { $0 + 1 })
offsets.sorted(by: { $0.offset < $1.offset })
foo.something(0, { $0 + 1 })
foo.something(param1: { _ in true }, param2: 0, param3: { _ in false })