Trailing Closure

Trailing closure syntax should be used whenever possible

  • Identifier: trailing_closure
  • Enabled by default: No
  • Supports autocorrection: No
  • Kind: style
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration: 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 }())

Triggering Examples

foo.map({ $0 + 1 })

foo.reduce(0, combine: { $0 + 1 })

offsets.sorted(by: { $0.offset < $1.offset })

foo.something(0, { $0 + 1 })