Array Init

Prefer using Array(seq) over seq.map { $0 } to convert a sequence into an Array

  • Identifier: array_init
  • Enabled by default: No
  • Supports autocorrection: No
  • Kind: lint
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration: warning

Non Triggering Examples

Array(foo)

foo.map { $0.0 }

foo.map { $1 }

foo.map { $0() }

foo.map { ((), $0) }

foo.map { $0! }

foo.map { $0! /* force unwrap */ }

foo.something { RouteMapper.map($0) }

foo.map { !$0 }

foo.map { /* a comment */ !$0 }

Triggering Examples

foo.map({ $0 })

foo.map { $0 }

foo.map { return $0 }

    foo.map { elem in
        elem
    }
    foo.map { elem in
        return elem
    }
    foo.map { (elem: String) in
        elem
    }
    foo.map { elem -> String in
        elem
    }
foo.map { $0 /* a comment */ }

foo.map { /* a comment */ $0 }