Collection Element Alignment

All elements in a collection literal should be vertically aligned

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

Non Triggering Examples

doThings(arg: [
    "foo": 1,
    "bar": 2,
    "fizz": 2,
    "buzz": 2
])
let abc = [
    "alpha": "a",
    "beta": "b",
    "gamma": "g",
    "delta": "d",
    "epsilon": "e"
]
let meals = [
                "breakfast": "oatmeal",
                "lunch": "sandwich",
                "dinner": "burger"
]
NSAttributedString(string: "…", attributes: [.font: UIFont.systemFont(ofSize: 12, weight: .regular),
                                             .foregroundColor: UIColor(white: 0, alpha: 0.2)])
let coordinates = [
    CLLocationCoordinate2D(latitude: 0, longitude: 33),
    CLLocationCoordinate2D(latitude: 0, longitude: 66),
    CLLocationCoordinate2D(latitude: 0, longitude: 99)
]
var evenNumbers: Set<Int> = [
    2,
    4,
    6
]
let abc = [1, 2, 3, 4]
let abc = [
    1, 2, 3, 4
]
let abc = [
    "foo": "bar", "fizz": "buzz"
]

Triggering Examples

doThings(arg: [
    "foo": 1,
    "bar": 2,
   "fizz": 2,
   "buzz": 2
])
let abc = [
    "alpha": "a",
     "beta": "b",
    "gamma": "g",
    "delta": "d",
  "epsilon": "e"
]
let meals = [
                "breakfast": "oatmeal",
                "lunch": "sandwich",
    "dinner": "burger"
]
let coordinates = [
    CLLocationCoordinate2D(latitude: 0, longitude: 33),
        CLLocationCoordinate2D(latitude: 0, longitude: 66),
    CLLocationCoordinate2D(latitude: 0, longitude: 99)
]
var evenNumbers: Set<Int> = [
    2,
  4,
    6
]